Search in sources :

Example 1 with GetTasksByRequesterUsernameRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest in project Taskzilla by CMPUT301W18T05.

the class User method getTasksRequested.

/**
 * Get a list of tasks that this user has requested.
 * @return ArrayList
 */
public ArrayList<Task> getTasksRequested() {
    ArrayList<Task> res = new ArrayList<>();
    ArrayList<Task> temp;
    GetTasksByRequesterUsernameRequest requestTasks = new GetTasksByRequesterUsernameRequest(this.getUsername());
    RequestManager.getInstance().invokeRequest(requestTasks);
    temp = requestTasks.getResult();
    while (temp != null && !temp.isEmpty()) {
        res.addAll(temp);
        RequestManager.getInstance().invokeRequest(requestTasks);
        temp = requestTasks.getResult();
    }
    return res;
}
Also used : GetTasksByRequesterUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest) ArrayList(java.util.ArrayList)

Example 2 with GetTasksByRequesterUsernameRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest in project Taskzilla by CMPUT301W18T05.

the class ProfileFragment method setUserVisibleHint.

// Taken from https://stackoverflow.com/questions/41655797/refresh-fragment-when-change-between-tabs?noredirect=1&lq=1
// 2018-04-01
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isVisibleToUser) {
        // getActivity().getActionBar().setTitle("Profile");
        getView().setBackgroundColor(Color.parseColor(appColors.getActionBarColor()));
        taskList = new ArrayList<>();
        // gets all of current user's tasks
        requestTasksRequester = new GetTasksByRequesterUsernameRequest(user.getUsername());
        RequestManager.getInstance().invokeRequest(getContext(), requestTasksRequester);
        Integer tempNumRequests = requestTasksRequester.getResult().size();
        Integer numRequestsInteger = tempNumRequests;
        while (tempNumRequests > 0) {
            RequestManager.getInstance().invokeRequest(getContext(), requestTasksRequester);
            tempNumRequests = requestTasksRequester.getResult().size();
            numRequestsInteger += tempNumRequests;
        }
        numRequests = Integer.toString(numRequestsInteger);
        requestTasksProvider = new GetTasksByProviderUsernameRequest(user.getUsername());
        RequestManager.getInstance().invokeRequest(getContext(), requestTasksProvider);
        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(getContext(), requestTasksProvider);
            this.taskList.addAll(requestTasksProvider.getResult());
            for (Task task : taskList) {
                if (task.getStatus().equals("Completed")) {
                    tasksDone++;
                }
            }
        }
        numTasksDone = Integer.toString(tasksDone);
        numRequestsField.setText(numRequests);
        numTasksDoneField.setText(numTasksDone);
    }
}
Also used : Task(com.cmput301w18t05.taskzilla.Task) GetTasksByRequesterUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest) GetTasksByProviderUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetTasksByProviderUsernameRequest)

Example 3 with GetTasksByRequesterUsernameRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest in project Taskzilla by CMPUT301W18T05.

the class ProfileController method getNumberOfRequests.

/**
 * getNumberOfRequests
 * get the number of tasks that the user
 * has requested
 *
 * @param username
 * @return number of tasks requested by user
 */
public String getNumberOfRequests(String username) {
    requestTasksRequester = new GetTasksByRequesterUsernameRequest(username);
    RequestManager.getInstance().invokeRequest(ctx, requestTasksRequester);
    Integer tempNumRequests = requestTasksRequester.getResult().size();
    Integer numRequestsInteger = tempNumRequests;
    while (tempNumRequests > 0) {
        RequestManager.getInstance().invokeRequest(ctx, requestTasksRequester);
        tempNumRequests = requestTasksRequester.getResult().size();
        numRequestsInteger += tempNumRequests;
    }
    return Integer.toString(numRequestsInteger);
}
Also used : GetTasksByRequesterUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest)

Example 4 with GetTasksByRequesterUsernameRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest 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)

Aggregations

GetTasksByRequesterUsernameRequest (com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest)4 Task (com.cmput301w18t05.taskzilla.Task)1 GetTasksByProviderUsernameRequest (com.cmput301w18t05.taskzilla.request.command.GetTasksByProviderUsernameRequest)1 ArrayList (java.util.ArrayList)1