Search in sources :

Example 1 with TasksByReminderDateComparator

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

the class TaskSortingUtil method generateProgrammedTaskHeaderList.

/* Programmed Tasks */
public ArrayList<TaskViewModel> generateProgrammedTaskHeaderList(List<Task> tasks, TaskSortType sortType, Resources resources) throws InvalidClassException {
    ArrayList<TaskViewModel> result = new ArrayList<>();
    clearTaskBuckets();
    if (sortType == TaskSortType.DATE) {
        // TODO: this comparator needs to take into account the RepeatingReminder's "next" event date to sort Tasks with RepeatingReminders properly
        Collections.sort(tasks, new TasksByReminderDateComparator());
        for (Task current : tasks) {
            if (current.getReminderType() == null)
                throw new NullPointerException("NULL ReminderType passed into TaskSortingUtil.generateProgrammedTaskHeaderList()");
            switch(current.getReminderType()) {
                case NONE:
                    throw new InvalidClassException("Wrong ReminderType passed into TaskSortingUtil.generateProgrammedTaskHeaderList()");
                case LOCATION_BASED:
                    tasksLocationBased.add(current);
                    break;
                case ONE_TIME:
                    insertProgrammedTaskIntoBucket(current, TaskUtil.getReminderEndCalendar(current.getReminder()));
                    break;
                case REPEATING:
                    insertProgrammedTaskIntoBucket(current, TaskUtil.getRepeatingReminderNextCalendar(((RepeatingReminder) current.getReminder())));
                    break;
                default:
                    throw new InvalidParameterException("Unhandled ReminderType passed into TaskSortingUtil.generateProgrammedTaskHeaderList()");
            }
        }
        if (tasksOverdue.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_overdue), true));
            dumpTaskBucketIntoViewModelList(tasksOverdue, result);
        }
        if (tasksLocationBased.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_location_based), false));
            dumpTaskBucketIntoViewModelList(tasksLocationBased, result);
        }
        if (tasksToday.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_today), false));
            dumpTaskBucketIntoViewModelList(tasksToday, result);
        }
        if (tasksTomorrow.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_tomorrow), false));
            dumpTaskBucketIntoViewModelList(tasksTomorrow, result);
        }
        if (tasksThisWeek.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_week), false));
            dumpTaskBucketIntoViewModelList(tasksThisWeek, result);
        }
        if (tasksNextWeek.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_next_week), false));
            dumpTaskBucketIntoViewModelList(tasksNextWeek, result);
        }
        if (tasksThisMonth.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_month), false));
            dumpTaskBucketIntoViewModelList(tasksThisMonth, result);
        }
        if (tasksNextMonth.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_next_month), false));
            dumpTaskBucketIntoViewModelList(tasksNextMonth, result);
        }
        if (tasksThisYear.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_year), false));
            dumpTaskBucketIntoViewModelList(tasksThisYear, result);
        }
        if (tasksNextYear.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_next_year), false));
            dumpTaskBucketIntoViewModelList(tasksNextYear, result);
        }
        if (tasksFuture.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_future), false));
            dumpTaskBucketIntoViewModelList(tasksFuture, result);
        }
    } else if (sortType == TaskSortType.PLACE) {
        handleSortingByPlace(tasks, result, resources);
    }
    return result;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Task(ve.com.abicelis.remindy.model.Task) TaskViewModel(ve.com.abicelis.remindy.viewmodel.TaskViewModel) TasksByReminderDateComparator(ve.com.abicelis.remindy.model.TasksByReminderDateComparator) InvalidClassException(java.io.InvalidClassException) ArrayList(java.util.ArrayList)

Aggregations

InvalidClassException (java.io.InvalidClassException)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 Task (ve.com.abicelis.remindy.model.Task)1 TasksByReminderDateComparator (ve.com.abicelis.remindy.model.TasksByReminderDateComparator)1 TaskViewModel (ve.com.abicelis.remindy.viewmodel.TaskViewModel)1