Search in sources :

Example 1 with CouldNotGetDataException

use of ve.com.abicelis.remindy.exception.CouldNotGetDataException in project Remindy by abicelis.

the class PlaceActivity method handleDeletePlace.

private void handleDeletePlace() {
    mDao = new RemindyDAO(getApplicationContext());
    final BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {

        @Override
        public void onDismissed(Snackbar transientBottomBar, int event) {
            super.onDismissed(transientBottomBar, event);
            setResult(RESULT_OK);
            finish();
        }
    };
    // Check if Place is associated with at least one location-based reminder
    List<Task> locationBasedTasks = new ArrayList<>();
    try {
        locationBasedTasks = mDao.getLocationBasedTasksAssociatedWithPlace(mPlace.getId(), -1);
    } catch (CouldNotGetDataException e) {
        SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_deleting, SnackbarUtil.SnackbarDuration.LONG, null);
    }
    // if there are tasks that use this place, warn user
    @StringRes int title = (locationBasedTasks.size() > 0 ? R.string.activity_place_dialog_delete_with_associated_tasks_title : R.string.activity_place_dialog_delete_title);
    @StringRes int message = (locationBasedTasks.size() > 0 ? R.string.activity_place_dialog_delete_with_associated_tasks_message : R.string.activity_place_dialog_delete_message);
    @StringRes int positive = (locationBasedTasks.size() > 0 ? R.string.activity_place_dialog_delete_with_associated_tasks_positive : R.string.activity_place_dialog_delete_positive);
    @StringRes int negative = (locationBasedTasks.size() > 0 ? R.string.activity_place_dialog_delete_negative : R.string.activity_place_dialog_delete_negative);
    AlertDialog dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(title)).setMessage(getResources().getString(message)).setPositiveButton(getResources().getString(positive), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                mDao.deletePlace(mPlace.getId());
                SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_place_snackbar_delete_succesful, SnackbarUtil.SnackbarDuration.SHORT, callback);
                dialog.dismiss();
            } catch (CouldNotDeleteDataException e) {
                SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_deleting, SnackbarUtil.SnackbarDuration.LONG, callback);
            }
        }
    }).setNegativeButton(getResources().getString(negative), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    }).create();
    dialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) DialogInterface(android.content.DialogInterface) StringRes(android.support.annotation.StringRes) BaseTransientBottomBar(android.support.design.widget.BaseTransientBottomBar) ArrayList(java.util.ArrayList) CouldNotDeleteDataException(ve.com.abicelis.remindy.exception.CouldNotDeleteDataException) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Snackbar(android.support.design.widget.Snackbar)

Example 2 with CouldNotGetDataException

use of ve.com.abicelis.remindy.exception.CouldNotGetDataException 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 3 with CouldNotGetDataException

use of ve.com.abicelis.remindy.exception.CouldNotGetDataException in project Remindy by abicelis.

the class RemindyDAO method deleteTask.

/**
 * Deletes a Task and associated Attachments and Reminder
 * @param taskId The ID of the task
 */
public boolean deleteTask(int taskId) throws CouldNotDeleteDataException {
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    Task task;
    try {
        task = getTask(taskId);
    } catch (CouldNotGetDataException e) {
        throw new CouldNotDeleteDataException("Failed to get task from database. TaskID=" + taskId, e);
    }
    // Delete task's attachments
    deleteAttachmentsOfTask(taskId);
    // If task has a reminder, delete it
    if (task.getReminderType() != ReminderType.NONE) {
        deleteReminderOfTask(taskId);
    }
    // Finally, delete the task
    return db.delete(RemindyContract.TaskTable.TABLE_NAME, RemindyContract.TaskTable._ID + " =?", new String[] { String.valueOf(taskId) }) > 0;
}
Also used : Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) CouldNotDeleteDataException(ve.com.abicelis.remindy.exception.CouldNotDeleteDataException) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 4 with CouldNotGetDataException

use of ve.com.abicelis.remindy.exception.CouldNotGetDataException in project Remindy by abicelis.

the class RemindyDAO method getTask.

/**
 * Returns a Task (with Reminder and Attachments) given a taskId
 * @param taskId    The ID of the Task to get.
 */
public Task getTask(int taskId) throws CouldNotGetDataException, SQLiteConstraintException {
    SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
    Cursor cursor = db.query(RemindyContract.TaskTable.TABLE_NAME, null, RemindyContract.PlaceTable._ID + "=?", new String[] { String.valueOf(taskId) }, null, null, null);
    if (cursor.getCount() == 0)
        throw new CouldNotGetDataException("Specified Task not found in the database. Passed id=" + taskId);
    if (cursor.getCount() > 1)
        throw new SQLiteConstraintException("Database UNIQUE constraint failure, more than one record found. Passed value=" + taskId);
    cursor.moveToNext();
    Task task = getTaskFromCursor(cursor);
    task.setAttachments(getAttachmentsOfTask(taskId));
    if (task.getReminderType() != ReminderType.NONE)
        task.setReminder(getReminderOfTask(taskId, task.getReminderType()));
    return task;
}
Also used : CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) Task(ve.com.abicelis.remindy.model.Task) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) Cursor(android.database.Cursor)

Example 5 with CouldNotGetDataException

use of ve.com.abicelis.remindy.exception.CouldNotGetDataException in project Remindy by abicelis.

the class GeofenceNotificationIntentService method onHandleIntent.

@Override
protected void onHandleIntent(@Nullable Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        String errorMessage = GeofenceErrorMessages.getErrorString(this, geofencingEvent.getErrorCode());
        Log.e(TAG, errorMessage);
        return;
    }
    // Get the transition type.
    int geofenceTransition = geofencingEvent.getGeofenceTransition();
    // Log the transition type
    handleLogTransition(geofenceTransition);
    // Test that the reported transition was of interest.
    if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || // || geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER   //Skipping this transition because of alert spam issues
    geofenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) {
        for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
            List<Task> tasks = new ArrayList<>();
            try {
                tasks = new RemindyDAO(this).getLocationBasedTasksAssociatedWithPlace(Integer.valueOf(geofence.getRequestId()), geofenceTransition);
            } catch (CouldNotGetDataException e) {
                Log.e("TAG", "Could not get data, geofence notification service.", e);
            }
            if (tasks.size() > 0) {
                String notificationTitle = getGeofenceNotificationTitle(geofenceTransition, geofence);
                String notificationText = getGeofenceNotificationText(tasks);
                // Send notification and log the transition details.
                NotificationUtil.displayLocationBasedNotification(this, Integer.valueOf(geofence.getRequestId()), notificationTitle, notificationText, tasks);
                Log.i(TAG, notificationTitle + " " + notificationText);
            }
        }
    }
}
Also used : Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) ArrayList(java.util.ArrayList) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) GeofencingEvent(com.google.android.gms.location.GeofencingEvent) Geofence(com.google.android.gms.location.Geofence)

Aggregations

CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)15 Task (ve.com.abicelis.remindy.model.Task)12 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)9 Cursor (android.database.Cursor)7 ArrayList (java.util.ArrayList)6 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)5 OneTimeReminder (ve.com.abicelis.remindy.model.reminder.OneTimeReminder)4 RepeatingReminder (ve.com.abicelis.remindy.model.reminder.RepeatingReminder)4 TaskViewModel (ve.com.abicelis.remindy.viewmodel.TaskViewModel)4 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)3 CouldNotDeleteDataException (ve.com.abicelis.remindy.exception.CouldNotDeleteDataException)3 Calendar (java.util.Calendar)2 CouldNotUpdateDataException (ve.com.abicelis.remindy.exception.CouldNotUpdateDataException)2 Time (ve.com.abicelis.remindy.model.Time)2 TaskSortingUtil (ve.com.abicelis.remindy.util.sorting.TaskSortingUtil)2 TaskTriggerViewModel (ve.com.abicelis.remindy.viewmodel.TaskTriggerViewModel)2 AlarmManager (android.app.AlarmManager)1 AlertDialog (android.app.AlertDialog)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1