Search in sources :

Example 36 with User

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

the class NotificationsFragment method onCreateView.

/**
 *  Initializes the fragment, and sets up listeners which checks if any notification
 *  on the listview has been clicked on.
 *
 * @param inflater              The current view
 * @param container
 * @param savedInstanceState    The state the fragment was in before switching to a new activity/fragment
 * @return                      Current view
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    final ConstraintLayout constraintLayout = (ConstraintLayout) inflater.inflate(R.layout.fragment_notifications, container, false);
    notificationList = new ArrayList<>();
    notificationListView = constraintLayout.findViewById(R.id.NotificationListView);
    notificationsController = new NotificationsController(this, getActivity(), currentUser.getInstance());
    adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, notificationList);
    notificationListView.setAdapter(adapter);
    notificationListView.setClickable(true);
    // get all notifications for the user currently available
    notificationsController.getNotificationsRequest();
    notificationListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            taskId = notificationList.get(i).getTaskID();
            if (notificationsController.checkTaskExistRequest(taskId))
                viewTask(taskId);
            else {
                AlertDialog.Builder deleteNotifcationAlert = new AlertDialog.Builder(getContext());
                deleteNotifcationAlert.setTitle("Task no longer exists!");
                deleteNotifcationAlert.setMessage("Do you want to remove this notification?");
                deleteNotifcationAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        notificationsController.removeNotificationRequest(taskId, i);
                        dialogInterface.dismiss();
                    }
                });
                deleteNotifcationAlert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });
                deleteNotifcationAlert.show();
            }
        }
    });
    notificationListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
            currentNotification = notificationList.get(position);
            notificationId = currentNotification.getId();
            AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
            alert.setTitle("Remove Notification?");
            alert.setMessage("Are you sure you want to delete this notification?");
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // remove notification
                    notificationsController.removeNotificationRequest(notificationId, position);
                    dialogInterface.dismiss();
                }
            });
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            alert.show();
            return true;
        }
    });
    clear = constraintLayout.findViewById(R.id.clearButton);
    clear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
            alert.setTitle("Remove Notification?");
            alert.setMessage("Are you sure you want to delete all notifications?");
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // remove notification
                    notificationsController.removeAllNotificationRequest();
                    dialogInterface.dismiss();
                }
            });
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            alert.show();
        }
    });
    return constraintLayout;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) NotificationsController(com.cmput301w18t05.taskzilla.controller.NotificationsController) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ConstraintLayout(android.support.constraint.ConstraintLayout) AdapterView(android.widget.AdapterView)

Example 37 with User

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

the class GetTasksByRequesterUsernameRequest method executeOffline.

/**
 * search through the app cache for tasks with this username
 */
@Override
public void executeOffline() {
    if (executedOfflineOnce) {
        result = new ArrayList<>();
        return;
    }
    executedOfflineOnce = true;
    System.out.println("Searching for tasks by requester username with username: " + user);
    executedOffline = true;
    AppCache appCache = AppCache.getInstance();
    ArrayList<Task> cachedTasks = appCache.getCachedTasks();
    this.result = new ArrayList<>();
    for (Task t : cachedTasks) {
        System.out.println("Looking at task: " + t);
        System.out.println("Looking at task with taskrequester uname: " + t.getTaskRequester().getUsername());
        if (t.getTaskRequester().getUsername().equals(user)) {
            System.out.println("Adding this to result");
            result.add(t);
        }
    }
}
Also used : Task(com.cmput301w18t05.taskzilla.Task) AppCache(com.cmput301w18t05.taskzilla.AppCache)

Example 38 with User

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

the class ProfileController method getNumberOfTasksDone.

/**
 * getNumberOfTasksDone
 * get the number of tasks that the user
 * has provided and completed for another user
 *
 * @param username
 * @return number of tasks done by the user
 */
public String getNumberOfTasksDone(String username) {
    requestTasksProvider = new GetTasksByProviderUsernameRequest(username);
    RequestManager.getInstance().invokeRequest(ctx, requestTasksProvider);
    taskList = new ArrayList<Task>();
    this.taskList.addAll(requestTasksProvider.getResult());
    tasksDone = 0;
    for (Task task : taskList) {
        if (task.getStatus().equals("Completed")) {
            tasksDone++;
        }
    }
    while (taskList.size() > 0 && taskList != null) {
        taskList.clear();
        RequestManager.getInstance().invokeRequest(ctx, requestTasksProvider);
        this.taskList.addAll(requestTasksProvider.getResult());
        for (Task task : taskList) {
            if (task.getStatus().equals("Completed")) {
                tasksDone++;
            }
        }
    }
    return Integer.toString(tasksDone);
}
Also used : Task(com.cmput301w18t05.taskzilla.Task) GetTasksByProviderUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetTasksByProviderUsernameRequest)

Example 39 with User

use of com.cmput301w18t05.taskzilla.User 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)

Example 40 with User

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

the class SignUpActivity method getUser.

/**
 * retrieve the user from elastic search through request manager
 * @param username
 * @return the user retrieved from elastic search
 */
public User getUser(String username) {
    GetUserByUsernameRequest getUserByUsernameRequest = new GetUserByUsernameRequest(username);
    RequestManager.getInstance().invokeRequest(getUserByUsernameRequest);
    return getUserByUsernameRequest.getResult();
}
Also used : GetUserByUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetUserByUsernameRequest)

Aggregations

View (android.view.View)13 Task (com.cmput301w18t05.taskzilla.Task)11 AddUserRequest (com.cmput301w18t05.taskzilla.request.command.AddUserRequest)8 AlertDialog (android.support.v7.app.AlertDialog)6 ListView (android.widget.ListView)6 TextView (android.widget.TextView)6 Photo (com.cmput301w18t05.taskzilla.Photo)6 EditText (android.widget.EditText)5 AddTaskRequest (com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 ColorDrawable (android.graphics.drawable.ColorDrawable)4 ActionBar (android.support.v7.app.ActionBar)4 RecyclerView (android.support.v7.widget.RecyclerView)4 AdapterView (android.widget.AdapterView)4 ImageButton (android.widget.ImageButton)4 User (com.cmput301w18t05.taskzilla.User)4 DialogInterface (android.content.DialogInterface)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 ArrayAdapter (android.widget.ArrayAdapter)3