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;
}
Aggregations