Search in sources :

Example 1 with TaskSortingUtil

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;
}
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 2 with TaskSortingUtil

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;
}
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 3 with TaskSortingUtil

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;
}
Also used : Task(ve.com.abicelis.remindy.model.Task) 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)

Aggregations

Cursor (android.database.Cursor)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 ArrayList (java.util.ArrayList)3 Task (ve.com.abicelis.remindy.model.Task)3 TaskSortingUtil (ve.com.abicelis.remindy.util.sorting.TaskSortingUtil)3 TaskViewModel (ve.com.abicelis.remindy.viewmodel.TaskViewModel)3 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)2