Search in sources :

Example 1 with RecyclerViewAdapter

use of com.cmput301w18t05.taskzilla.RecyclerViewAdapter in project Taskzilla by CMPUT301W18T05.

the class EditTaskActivity method onCreate.

/**
 * Activity uses the activity_edit_task.xml layout
 * Initialize a task with edited fields
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    task = new Task();
    ctx = getApplicationContext();
    super.onCreate(savedInstanceState);
    setTitle("Edit Task");
    setContentView(R.layout.activity_edit_task);
    Double taskLat = Double.parseDouble(getIntent().getStringExtra("Lat"));
    Double taskLon = Double.parseDouble(getIntent().getStringExtra("Lon"));
    taskLocation = new LatLng(taskLat, taskLon);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.dragdropMap2);
    mapFragment.getMapAsync(this);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    currentLocationButton = findViewById(R.id.currentLocationButton);
    autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {

        /**
         * When the user searchs a location
         * set the hint and the taskLocation
         * @param place
         */
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            autocompleteFragment.setHint(place.getName());
            taskLocation = place.getLatLng();
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
            taskLocation = null;
            Log.i("err", "An error occurred: " + status);
        }
    });
    autocompleteFragment.setHint(getIntent().getStringExtra("Lat") + ", " + getIntent().getStringExtra("Lon"));
    autocompleteFragment.setText(getIntent().getStringExtra("Lat") + ", " + getIntent().getStringExtra("Lon"));
    getLocation();
    autocompleteFragment.setBoundsBias(new LatLngBounds(new LatLng(lat - 0.25, lon - 0.25), new LatLng(lat + 0.25, lon + 0.25)));
    currentLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            setCurrentLocation();
        }
    });
    AppColors appColors = AppColors.getInstance();
    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
    actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
    EditText TaskNameText = findViewById(R.id.TaskName);
    EditText DescriptionText = findViewById(R.id.Description);
    String taskName = getIntent().getStringExtra("task Name");
    String taskDescription = getIntent().getStringExtra("Description");
    // Dummy
    task.setName(taskName);
    // Dummy
    task.setDescription(taskDescription);
    TaskNameText.setText(task.getName());
    DescriptionText.setText(task.getDescription());
    photos = new ArrayList<>();
    ArrayList<String> photosString = getIntent().getStringArrayListExtra("photos");
    for (int i = 0; i < photosString.size(); i++) {
        Log.i("test", photosString.get(i));
        photos.add(new Photo(photosString.get(i)));
    }
    recyclerPhotosView = findViewById(R.id.listOfPhotos);
    layoutManager = new LinearLayoutManager(ctx, LinearLayoutManager.HORIZONTAL, false);
    recyclerPhotosView.setLayoutManager(layoutManager);
    recyclerPhotosViewAdapter = new RecyclerViewAdapter(ctx, photos, new CustomOnItemClick() {

        @Override
        public void onColumnClicked(final int position) {
            // taken from https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android
            // 2018-03-16
            AlertDialog.Builder alert = new AlertDialog.Builder(EditTaskActivity.this);
            alert.setTitle("Delete Photo");
            alert.setMessage("Are you sure you want to delete this photo?");
            // DELETE CODE
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    photos.remove(position);
                    dialogInterface.dismiss();
                    recyclerPhotosViewAdapter.notifyDataSetChanged();
                }
            });
            // DELETE CANCEL CODE
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            alert.show();
        }
    });
    recyclerPhotosView.setAdapter(recyclerPhotosViewAdapter);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Task(com.cmput301w18t05.taskzilla.Task) DialogInterface(android.content.DialogInterface) Photo(com.cmput301w18t05.taskzilla.Photo) RecyclerViewAdapter(com.cmput301w18t05.taskzilla.RecyclerViewAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CustomOnItemClick(com.cmput301w18t05.taskzilla.CustomOnItemClick) AppColors(com.cmput301w18t05.taskzilla.AppColors) SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) LatLng(com.google.android.gms.maps.model.LatLng) ActionBar(android.support.v7.app.ActionBar) Status(com.google.android.gms.common.api.Status) EditText(android.widget.EditText) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) PlaceSelectionListener(com.google.android.gms.location.places.ui.PlaceSelectionListener) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ColorDrawable(android.graphics.drawable.ColorDrawable) Place(com.google.android.gms.location.places.Place)

Example 2 with RecyclerViewAdapter

use of com.cmput301w18t05.taskzilla.RecyclerViewAdapter in project Taskzilla by CMPUT301W18T05.

the class ViewTaskActivity method onCreate.

/**
 *onCreate
 * Retrieve the task using the task id that was sent using
 * intent into the activity updating the information on the
 * activity_ViewTaskActivity while checking if the task has
 * a provider, what the status is and if the user viewing
 * is the owner of the task
 *
 * @param savedInstanceState
 * @author Micheal-Nguyen, myapplestory
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_task);
    appColors = AppColors.getInstance();
    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
    actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.dragdropMap);
    mapFragment.getMapAsync(this);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    findViews();
    // starts the activity at the very top
    scrollView.setFocusableInTouchMode(true);
    scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    // gets the task id
    this.viewTaskController = new ViewTaskController(this.findViewById(android.R.id.content), this);
    taskID = getIntent().getStringExtra("TaskId");
    setValues();
    setRequesterField();
    setProviderField();
    photos = task.getPhotos();
    NoLocation = findViewById(R.id.NoLocationText);
    NoLocation.setVisibility(View.INVISIBLE);
    if (task.getLocation() == null) {
        NoLocation.setVisibility(View.VISIBLE);
    // mapFragment.s
    }
    linearLayout = findViewById(R.id.Photos);
    recyclerPhotosView = findViewById(R.id.listOfPhotos);
    layoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
    recyclerPhotosView.setLayoutManager(layoutManager);
    recyclerPhotosViewAdapter = new RecyclerViewAdapter(getApplicationContext(), photos, new CustomOnItemClick() {

        @Override
        public void onColumnClicked(int position) {
            Intent intent = new Intent(getApplicationContext(), ZoomImageActivity.class);
            intent.putExtra("Photo", photos.get(position).toString());
            startActivity(intent);
        }
    });
    recyclerPhotosView.setAdapter(recyclerPhotosViewAdapter);
    setVisibility();
    setUpBidsList();
}
Also used : SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) ColorDrawable(android.graphics.drawable.ColorDrawable) Intent(android.content.Intent) RecyclerViewAdapter(com.cmput301w18t05.taskzilla.RecyclerViewAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CustomOnItemClick(com.cmput301w18t05.taskzilla.CustomOnItemClick) ActionBar(android.support.v7.app.ActionBar) ViewTaskController(com.cmput301w18t05.taskzilla.controller.ViewTaskController)

Example 3 with RecyclerViewAdapter

use of com.cmput301w18t05.taskzilla.RecyclerViewAdapter in project Taskzilla by CMPUT301W18T05.

the class NewTaskActivity method onCreate.

/**
 * Activity uses the activity_new_task.xml layout
 * New tasks are created through NewTaskController
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    setTitle("Add a Task");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_task);
    AppColors appColors = AppColors.getInstance();
    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
    actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.dragdropMap);
    mapFragment.getMapAsync(this);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    newTaskController = new NewTaskController(this, getApplicationContext());
    currentLocationButton = findViewById(R.id.currentLocationButton);
    Button cancel = findViewById(R.id.CancelButton);
    Button addTask = findViewById(R.id.addTaskButton);
    final EditText taskName = findViewById(R.id.TaskName);
    final EditText taskDescription = findViewById(R.id.Description);
    addPhotoButton = findViewById(R.id.AddPhotoButton);
    autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {

        /**
         * When user select a location
         * Set hint and set place
         * @param place
         */
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            autocompleteFragment.setHint(place.getName());
            taskLocation = place.getLatLng();
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
            taskLocation = null;
            Log.i("err", "An error occurred: " + status);
        }
    });
    photos = new ArrayList<>();
    recyclerPhotosView = findViewById(R.id.listOfPhotos);
    layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    recyclerPhotosView.setLayoutManager(layoutManager);
    recyclerPhotosViewAdapter = new RecyclerViewAdapter(this, photos, new CustomOnItemClick() {

        @Override
        public void onColumnClicked(final int position) {
            // taken from https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android
            // 2018-03-16
            AlertDialog.Builder alert = new AlertDialog.Builder(NewTaskActivity.this);
            alert.setTitle("Delete Photo");
            alert.setMessage("Are you sure you want to delete this photo?");
            // DELETE CODE
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    photos.remove(position);
                    dialogInterface.dismiss();
                    recyclerPhotosViewAdapter.notifyDataSetChanged();
                }
            });
            // DELETE CANCEL CODE
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            alert.show();
        }
    });
    recyclerPhotosView.setAdapter(recyclerPhotosViewAdapter);
    autocompleteFragment.setHint("Task Location");
    getLocation();
    autocompleteFragment.setBoundsBias(new LatLngBounds(new LatLng(lat - 0.25, lon - 0.25), new LatLng(lat + 0.25, lon + 0.25)));
    /* cancel button */
    cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            newTaskController.cancelTask();
        }
    });
    currentLocationButton.setOnClickListener(new View.OnClickListener() {

        /**
         * Set loaction to the users current location
         * @param view
         */
        @Override
        public void onClick(View view) {
            setCurrentLocation();
        }
    });
    /* add task button */
    addTask.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            newTaskController.addTask(taskName.getText().toString(), cUser, taskDescription.getText().toString(), taskLocation, photos);
        }
    });
    addPhotoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AddPhotoButtonClicked();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) RecyclerViewAdapter(com.cmput301w18t05.taskzilla.RecyclerViewAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CustomOnItemClick(com.cmput301w18t05.taskzilla.CustomOnItemClick) NewTaskController(com.cmput301w18t05.taskzilla.controller.NewTaskController) AppColors(com.cmput301w18t05.taskzilla.AppColors) SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LatLng(com.google.android.gms.maps.model.LatLng) ActionBar(android.support.v7.app.ActionBar) EditText(android.widget.EditText) Status(com.google.android.gms.common.api.Status) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) PlaceSelectionListener(com.google.android.gms.location.places.ui.PlaceSelectionListener) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ColorDrawable(android.graphics.drawable.ColorDrawable) Place(com.google.android.gms.location.places.Place)

Aggregations

ColorDrawable (android.graphics.drawable.ColorDrawable)3 ActionBar (android.support.v7.app.ActionBar)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 CustomOnItemClick (com.cmput301w18t05.taskzilla.CustomOnItemClick)3 RecyclerViewAdapter (com.cmput301w18t05.taskzilla.RecyclerViewAdapter)3 SupportMapFragment (com.google.android.gms.maps.SupportMapFragment)3 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 EditText (android.widget.EditText)2 AppColors (com.cmput301w18t05.taskzilla.AppColors)2 Status (com.google.android.gms.common.api.Status)2 Place (com.google.android.gms.location.places.Place)2 PlaceSelectionListener (com.google.android.gms.location.places.ui.PlaceSelectionListener)2 LatLng (com.google.android.gms.maps.model.LatLng)2 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)2 Intent (android.content.Intent)1 Button (android.widget.Button)1 ImageButton (android.widget.ImageButton)1