Search in sources :

Example 1 with TaskViewModel

use of ve.com.abicelis.remindy.viewmodel.TaskViewModel 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)

Example 2 with TaskViewModel

use of ve.com.abicelis.remindy.viewmodel.TaskViewModel in project Remindy by abicelis.

the class TaskSortingUtil method generateDoneTaskHeaderList.

/* Done Tasks */
public ArrayList<TaskViewModel> generateDoneTaskHeaderList(List<Task> tasks, TaskSortType sortType, Resources resources) throws InvalidClassException {
    ArrayList<TaskViewModel> result = new ArrayList<>();
    clearTaskBuckets();
    if (sortType == TaskSortType.DATE) {
        // Sorting by doneDate!
        Collections.sort(tasks, new TasksByDoneDateComparator());
        for (Task current : tasks) {
            if (current.getReminderType() == null)
                throw new NullPointerException("NULL ReminderType passed into TaskSortingUtil.generateProgrammedTaskHeaderList()");
            insertDoneTaskIntoBucket(current, current.getDoneDate());
        }
        if (tasksToday.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_today), false));
            dumpTaskBucketIntoViewModelList(tasksToday, result);
        }
        if (tasksYesterday.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_yesterday), false));
            dumpTaskBucketIntoViewModelList(tasksYesterday, result);
        }
        if (tasksThisWeek.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_week), false));
            dumpTaskBucketIntoViewModelList(tasksThisWeek, result);
        }
        if (tasksLastWeek.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_last_week), false));
            dumpTaskBucketIntoViewModelList(tasksLastWeek, result);
        }
        if (tasksThisMonth.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_month), false));
            dumpTaskBucketIntoViewModelList(tasksThisMonth, result);
        }
        if (tasksLastMonth.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_last_month), false));
            dumpTaskBucketIntoViewModelList(tasksLastMonth, result);
        }
        if (tasksThisYear.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_year), false));
            dumpTaskBucketIntoViewModelList(tasksThisYear, result);
        }
        if (tasksLastYear.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_last_year), false));
            dumpTaskBucketIntoViewModelList(tasksLastYear, result);
        }
        if (tasksPast.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_past), false));
            dumpTaskBucketIntoViewModelList(tasksPast, result);
        }
    } else if (sortType == TaskSortType.PLACE) {
        handleSortingByPlace(tasks, result, resources);
    }
    return result;
}
Also used : Task(ve.com.abicelis.remindy.model.Task) TaskViewModel(ve.com.abicelis.remindy.viewmodel.TaskViewModel) TasksByDoneDateComparator(ve.com.abicelis.remindy.model.TasksByDoneDateComparator) ArrayList(java.util.ArrayList)

Example 3 with TaskViewModel

use of ve.com.abicelis.remindy.viewmodel.TaskViewModel in project Remindy by abicelis.

the class RemindyDAO method getProgrammedTasks.

/**
 * Returns a List of Tasks (with Reminder and Attachments) which have TaskStatus.PROGRAMMED
 * @param sortType TaskSortType enum value with which to sort results. By date or location
 * @return A List of TaskViewModel
 */
public List<TaskViewModel> getProgrammedTasks(@NonNull TaskSortType sortType, boolean includeLocationBasedTasks, Resources resources) throws CouldNotGetDataException, InvalidClassException {
    SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
    List<TaskViewModel> result;
    List<Task> tasks = new ArrayList<>();
    Cursor cursor = db.query(RemindyContract.TaskTable.TABLE_NAME, null, RemindyContract.TaskTable.COLUMN_NAME_STATUS.getName() + "=?", new String[] { TaskStatus.PROGRAMMED.name() }, null, null, null);
    try {
        while (cursor.moveToNext()) {
            Task current = getTaskFromCursor(cursor);
            if (// Skip location-based task
            !includeLocationBasedTasks && current.getReminderType() == ReminderType.LOCATION_BASED)
                continue;
            // Try to get the attachments, if there are any
            current.setAttachments(getAttachmentsOfTask(current.getId()));
            // If Task ReminderType.NONE, throw an error.
            if (current.getReminderType() == ReminderType.NONE)
                throw new CouldNotGetDataException("Error, Task with TaskStatus=PROGRAMMED has ReminderType=NONE");
            else
                current.setReminder(getReminderOfTask(current.getId(), current.getReminderType()));
            tasks.add(current);
        }
    } finally {
        cursor.close();
    }
    // Generate List<TaskViewModel>
    result = new TaskSortingUtil().generateProgrammedTaskHeaderList(tasks, sortType, resources);
    return result;
}
Also used : Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) TaskViewModel(ve.com.abicelis.remindy.viewmodel.TaskViewModel) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) TaskSortingUtil(ve.com.abicelis.remindy.util.sorting.TaskSortingUtil) Cursor(android.database.Cursor)

Example 4 with TaskViewModel

use of ve.com.abicelis.remindy.viewmodel.TaskViewModel 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)

Example 5 with TaskViewModel

use of ve.com.abicelis.remindy.viewmodel.TaskViewModel in project Remindy by abicelis.

the class HomeListFragment method updateViewholderItem.

/* Called from HomeActivity.onActivityResult() */
public void updateViewholderItem(int position) {
    // Task was edited, refresh task info and refresh recycler
    try {
        Task task = mDao.getTask(mTasks.get(position).getTask().getId());
        TaskViewModel taskViewModel = new TaskViewModel(task, ConversionUtil.taskReminderTypeToTaskViewmodelType(task.getReminderType()));
        mTasks.set(position, taskViewModel);
        mAdapter.notifyItemChanged(position);
    } catch (CouldNotGetDataException e) {
        SnackbarUtil.showSnackbar(mRecyclerView, SnackbarUtil.SnackbarType.ERROR, R.string.error_problem_updating_task_from_database, SnackbarUtil.SnackbarDuration.LONG, null);
    }
}
Also used : Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) TaskViewModel(ve.com.abicelis.remindy.viewmodel.TaskViewModel)

Aggregations

Task (ve.com.abicelis.remindy.model.Task)8 TaskViewModel (ve.com.abicelis.remindy.viewmodel.TaskViewModel)8 ArrayList (java.util.ArrayList)7 Cursor (android.database.Cursor)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)4 TaskSortingUtil (ve.com.abicelis.remindy.util.sorting.TaskSortingUtil)3 InvalidClassException (java.io.InvalidClassException)1 InvalidParameterException (java.security.InvalidParameterException)1 TasksByDoneDateComparator (ve.com.abicelis.remindy.model.TasksByDoneDateComparator)1 TasksByPlaceComparator (ve.com.abicelis.remindy.model.TasksByPlaceComparator)1 TasksByReminderDateComparator (ve.com.abicelis.remindy.model.TasksByReminderDateComparator)1 UnprogrammedTasksByTitleComparator (ve.com.abicelis.remindy.model.UnprogrammedTasksByTitleComparator)1