Search in sources :

Example 1 with UnprogrammedTasksByTitleComparator

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

the class RemindyDAO method getUnprogrammedTasks.

/* Get data from database */
/**
     * Returns a List of Tasks (with Reminder and Attachments) which have TaskStatus.UNPROGRAMMED. Sorted Alphabetically by Task Title
     * @return A List of TaskViewModel
     */
public List<TaskViewModel> getUnprogrammedTasks() throws CouldNotGetDataException {
    SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
    List<TaskViewModel> result = new ArrayList<>();
    List<Task> tasks = new ArrayList<>();
    Cursor cursor = db.query(RemindyContract.TaskTable.TABLE_NAME, null, RemindyContract.TaskTable.COLUMN_NAME_STATUS.getName() + "=?", new String[] { TaskStatus.UNPROGRAMMED.name() }, null, null, null);
    try {
        while (cursor.moveToNext()) {
            Task current = getTaskFromCursor(cursor);
            //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, found task with TaskStatus=UNPROGRAMMED with ReminderType != NONE");
            tasks.add(current);
        }
    } finally {
        cursor.close();
    }
    //Sort tasks by title
    Collections.sort(tasks, new UnprogrammedTasksByTitleComparator());
    //Create viewModel
    for (int i = 0; i < tasks.size(); i++) {
        result.add(new TaskViewModel(tasks.get(i), TaskViewModelType.UNPROGRAMMED_REMINDER));
    }
    return result;
}
Also used : UnprogrammedTasksByTitleComparator(ve.com.abicelis.remindy.model.UnprogrammedTasksByTitleComparator) 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) Cursor(android.database.Cursor)

Aggregations

Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 ArrayList (java.util.ArrayList)1 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)1 Task (ve.com.abicelis.remindy.model.Task)1 UnprogrammedTasksByTitleComparator (ve.com.abicelis.remindy.model.UnprogrammedTasksByTitleComparator)1 TaskViewModel (ve.com.abicelis.remindy.viewmodel.TaskViewModel)1