use of ve.com.abicelis.remindy.util.sorting.TaskSortingUtil 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;
}
use of ve.com.abicelis.remindy.util.sorting.TaskSortingUtil in project Remindy by abicelis.
the class RemindyDAO method getLocationBasedTasks.
/**
* Returns a List of Tasks (with Reminder and Attachments) which have TaskStatus.PROGRAMMED AND ReminderType.LOCATION_BASED, sorted by Location
* @return A List of TaskViewModel
*/
public List<TaskViewModel> getLocationBasedTasks(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 NON location-based task
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, TaskSortType.PLACE, resources);
return result;
}
use of ve.com.abicelis.remindy.util.sorting.TaskSortingUtil in project Remindy by abicelis.
the class RemindyDAO method getDoneTasks.
/**
* Returns a List of Tasks (with Reminder and Attachments) which have TaskStatus.DONE
* @param sortType TaskSortType enum value with which to sort results. By date or location
* @return A List of TaskViewModel
*/
public List<TaskViewModel> getDoneTasks(@NonNull TaskSortType sortType, Resources resources) throws CouldNotGetDataException, InvalidClassException {
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.DONE.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 has reminder, get it
if (current.getReminderType() != ReminderType.NONE)
current.setReminder(getReminderOfTask(current.getId(), current.getReminderType()));
tasks.add(current);
}
} finally {
cursor.close();
}
//Generate List<TaskViewModel> This List will be sorted and grouped!
result = new TaskSortingUtil().generateDoneTaskHeaderList(tasks, sortType, resources);
return result;
}
Aggregations