Search in sources :

Example 6 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 7 with TaskViewModel

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

Example 8 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