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);
}
}
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;
}
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();
}
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);
}
Aggregations