Search in sources :

Example 1 with GetTasksByProviderUsernameRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTasksByProviderUsernameRequest 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 2 with GetTasksByProviderUsernameRequest

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

the class TasksProviderFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Set up listview and adapter
    View v = inflater.inflate(R.layout.fragment_tasks_provider, container, false);
    taskList = new ArrayList<>();
    taskListView = v.findViewById(R.id.ProviderTasksListView);
    adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, taskList);
    taskListView.setAdapter(adapter);
    requestTasks = new GetTasksByProviderUsernameRequest(currentUser.getInstance().getUsername());
    RequestManager.getInstance().invokeRequest(getContext(), requestTasks);
    taskList.addAll(requestTasks.getResult());
    adapter.notifyDataSetChanged();
    taskListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            viewTask(taskList.get(position).getId());
        }
    });
    return v;
}
Also used : GetTasksByProviderUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetTasksByProviderUsernameRequest) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 3 with GetTasksByProviderUsernameRequest

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

Example 4 with GetTasksByProviderUsernameRequest

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

Aggregations

GetTasksByProviderUsernameRequest (com.cmput301w18t05.taskzilla.request.command.GetTasksByProviderUsernameRequest)4 Task (com.cmput301w18t05.taskzilla.Task)2 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 GetTasksByRequesterUsernameRequest (com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest)1