Search in sources :

Example 21 with Task

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

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

the class TasksRequesterFragment method updateRequested.

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

Example 23 with Task

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

the class TasksRequesterFragment method updateAssigned.

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

Example 24 with Task

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

the class TasksRequesterFragment method updateCompleted.

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

Example 25 with Task

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

the class SearchFragment method onViewCreated.

/**
 * Determines what is done on the view once it has been created
 *
 * @param view                  The current activity
 * @param savedInstanceState    The state of the screen before interrupts appear, such as leaving the app
 */
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // expand search bar by default
    searchField = view.findViewById(R.id.searchView);
    /*
         * Listens for changes in the searchview
         * OnQueryTextChange invokes whenever the user types, while on the other hand
         * OnQueryTextSubmit invokes only when the user submits the keywords.
         *
         * There are 3 scenarios:
         *      1. if(sentence.length == 0)  and if(searchController.getKeywords().isEmpty() == true)
         *          sentence is the words the user types in.
         *
         *          These conditions check if the user entered in previous search words,
         *          if not then nothing happens since all tasks are shown to begin with
         *
         *      2. if(sentence.length == 0)  and if(searchController.getKeywords().isEmpty() == false)
         *
         *          These conditions are for when the user had previously searched for keywords and now wants
         *          to see all the available tasks. It first clears the listview then does a search returning all
         *          available tasks.
         *
         *      3. The last condition is when the user is searching for tasks by entering in keyword(s).
         *          This clears the listview and then proceeds to make a search request using the keyword(s)
         *          as a parameter. It then returns the tasks containing the keywords in the descriptions.
         *
         */
    searchField.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String text) {
            String sentence;
            sentence = text.toLowerCase();
            if (sentence.length() == 0) {
                // Checks if user entered text in search bar
                if (!searchController.getKeywords().isEmpty()) {
                    // Checks if keywords is empty, if yes return already loaded array of tasks
                    searchController.clearKeywords();
                    searchController.getAllRequest();
                }
            } else {
                // Adds keyword to list and loads new set of tasks based on keywords
                searchController.clearKeywords();
                searchController.addKeywords(sentence);
                searchController.searchRequest(sentence);
            }
            notifyChange();
            return false;
        }
    });
    mButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            viewMap();
        }
    });
    // Set up listview and adapter
    searchResults = new ArrayList<>();
    searchController = new SearchController(this, getActivity());
    adapterText = new TaskCustomAdapter(getActivity(), R.layout.tasks_list_view2, searchResults);
    availableTasksText.setAdapter(adapterText);
    /*
         *  Listens for user tapping on a task in the listview
         *
         *  Sets currentTask variable to the current task tapped, which
         *  is used later on to determine which item to remove from the listview
         *  if the item was deleted.
         */
    availableTasksText.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            currentTask = searchResults.get(i);
            viewTask(searchResults.get(i).getId());
        }
    });
    // get all available tasks
    searchController.getAllRequest();
}
Also used : SearchView(android.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SearchController(com.cmput301w18t05.taskzilla.controller.SearchController) TaskCustomAdapter(com.cmput301w18t05.taskzilla.TaskCustomAdapter) SearchView(android.widget.SearchView) AdapterView(android.widget.AdapterView)

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