Search in sources :

Example 1 with TasksByPlaceComparator

use of ve.com.abicelis.remindy.model.TasksByPlaceComparator in project Remindy by abicelis.

the class TaskSortingUtil method handleSortingByPlace.

private void handleSortingByPlace(List<Task> tasks, ArrayList<TaskViewModel> result, Resources resources) {
    Collections.sort(tasks, new TasksByPlaceComparator());
    if (tasks.size() == 0)
        return;
    if (tasks.get(0).getReminderType() != ReminderType.LOCATION_BASED) {
        //There are no Location-based reminders, insert them all into result
        result.add(new TaskViewModel(resources.getString(R.string.task_header_no_location), false));
        dumpTaskBucketIntoViewModelList(tasks, result);
    } else {
        //Grab first location alias
        String lastPlaceAlias = ((LocationBasedReminder) tasks.get(0).getReminder()).getPlace().getAlias();
        result.add(new TaskViewModel(lastPlaceAlias, false));
        result.add(new TaskViewModel(tasks.get(0), TaskViewModelType.LOCATION_BASED_REMINDER));
        for (int i = 1; i < tasks.size(); i++) {
            if (tasks.get(i).getReminderType() != ReminderType.LOCATION_BASED) {
                //Got to a NON Location-based reminder? Add the rest of reminders and break.
                result.add(new TaskViewModel(resources.getString(R.string.task_header_no_location), false));
                List<Task> otherTasks = new ArrayList<>();
                for (int j = i; j < tasks.size(); j++) otherTasks.add(tasks.get(j));
                dumpTaskBucketIntoViewModelList(otherTasks, result);
                break;
            }
            String placeAlias = ((LocationBasedReminder) tasks.get(i).getReminder()).getPlace().getAlias();
            if (placeAlias.compareTo(lastPlaceAlias) != 0) {
                //New location alias? Add a header
                lastPlaceAlias = placeAlias;
                result.add(new TaskViewModel(lastPlaceAlias, false));
            }
            result.add(new TaskViewModel(tasks.get(i), TaskViewModelType.LOCATION_BASED_REMINDER));
        }
    }
}
Also used : Task(ve.com.abicelis.remindy.model.Task) TaskViewModel(ve.com.abicelis.remindy.viewmodel.TaskViewModel) ArrayList(java.util.ArrayList) TasksByPlaceComparator(ve.com.abicelis.remindy.model.TasksByPlaceComparator)

Aggregations

ArrayList (java.util.ArrayList)1 Task (ve.com.abicelis.remindy.model.Task)1 TasksByPlaceComparator (ve.com.abicelis.remindy.model.TasksByPlaceComparator)1 TaskViewModel (ve.com.abicelis.remindy.viewmodel.TaskViewModel)1