Search in sources :

Example 51 with Task

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

the class TasksRequesterFragment method viewTask.

/**
 * upon pressing a task on the listview, switches to ViewTaskActivity
 * @param id id of the task to be view is passed in as a String
 * @author Colin
 */
public void viewTask(String id) {
    /*
        try except statement, when task clicked. Attempts to get from elastic search in order to test
        if the task still exists or not.
         */
    try {
        GetTaskRequest request = new GetTaskRequest(id);
        RequestManager.getInstance().invokeRequest(getContext(), request);
        Intent intent = new Intent(getActivity(), ViewTaskActivity.class);
        intent.putExtra("TaskId", id);
        startActivityForResult(intent, 1);
    } catch (Exception e) {
        updateRList();
        Toast.makeText(getActivity(), "Task no longer exists", Toast.LENGTH_SHORT).show();
    }
}
Also used : GetTaskRequest(com.cmput301w18t05.taskzilla.request.command.GetTaskRequest) Intent(android.content.Intent)

Example 52 with Task

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

the class TasksRequesterFragment method onCreate.

/**
 * oncreate initialize task list and request and adapter for listview
 * as well as fetch the current user's tasks and putting it in listview
 * @param savedInstanceState the state of every fragment on the parent activity
 * @author myapplestory
 */
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set up listView and adapter
    taskList = new ArrayList<>();
    adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, taskList);
    // gets all of current user's tasks
    requestTasks = new GetTasksByRequesterUsernameRequest(cUser.getUsername());
    RequestManager.getInstance().invokeRequest(getContext(), requestTasks);
    taskList.addAll(requestTasks.getResult());
}
Also used : GetTasksByRequesterUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest)

Example 53 with Task

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

the class TasksRequesterFragment method updateBidded.

/**
 * if filter is requested, retrieve all requests owned by current user
 * from elastic search that have status 'bidded'
 */
public void updateBidded() {
    ArrayList<Task> res = cUser.getTasksRequested();
    taskList.clear();
    for (Task t : res) {
        if (t.getStatus().equalsIgnoreCase("bidded")) {
            taskList.add(t);
        }
    }
    adapter.notifyDataSetChanged();
}
Also used : Task(com.cmput301w18t05.taskzilla.Task)

Example 54 with Task

use of com.cmput301w18t05.taskzilla.Task 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 55 with Task

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

the class TasksProviderFragment method updatePList.

/**
 * retrieve the provider list from the elastic search using request manager
 * updating the task list
 */
public void updatePList() {
    requestTasks = new GetTasksByProviderUsernameRequest(currentUser.getInstance().getUsername());
    RequestManager.getInstance().invokeRequest(getContext(), requestTasks);
    taskList.clear();
    taskList.addAll(requestTasks.getResult());
    adapter.notifyDataSetChanged();
}
Also used : GetTasksByProviderUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetTasksByProviderUsernameRequest)

Aggregations

View (android.view.View)18 Task (com.cmput301w18t05.taskzilla.Task)16 MainActivity (com.cmput301w18t05.taskzilla.activity.MainActivity)10 AddTaskRequest (com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)9 AlertDialog (android.support.v7.app.AlertDialog)6 AdapterView (android.widget.AdapterView)6 ListView (android.widget.ListView)6 GetTaskRequest (com.cmput301w18t05.taskzilla.request.command.GetTaskRequest)6 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 EditText (android.widget.EditText)5 ImageButton (android.widget.ImageButton)5 DecimalFormat (java.text.DecimalFormat)5 DialogInterface (android.content.DialogInterface)4 Button (android.widget.Button)4 TextView (android.widget.TextView)4 AppCache (com.cmput301w18t05.taskzilla.AppCache)4 Bid (com.cmput301w18t05.taskzilla.Bid)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 ActionBar (android.support.v7.app.ActionBar)3