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