use of ve.com.abicelis.remindy.exception.CouldNotDeleteDataException 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.CouldNotDeleteDataException 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.CouldNotDeleteDataException in project Remindy by abicelis.
the class TaskDetailActivity method handleDeleteTask.
public void handleDeleteTask() {
AlertDialog dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.activity_task_dialog_delete_title)).setMessage(getResources().getString(R.string.activity_task_dialog_delete_message)).setPositiveButton(getResources().getString(R.string.activity_task_dialog_delete_positive), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
FileUtil.deleteAttachmentFiles(TaskDetailActivity.this, mTask.getAttachments());
new RemindyDAO(TaskDetailActivity.this).deleteTask(mTask.getId());
BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
super.onDismissed(transientBottomBar, event);
//Return task position to HomeListFragment, and also notify deletion
Intent returnIntent = new Intent();
returnIntent.putExtra(TASK_DETAIL_RETURN_ACTION_TYPE, TASK_DETAIL_RETURN_ACTION_DELETED);
returnIntent.putExtra(TASK_DETAIL_RETURN_TASK_POSITION, mPosition);
returnIntent.putExtra(TASK_DETAIL_RETURN_TASK_VIEWPAGER_INDEX, getViewPagerIndexFromTask(mTask));
setResult(RESULT_OK, returnIntent);
finish();
}
};
SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_task_snackbar_task_deleted_successfully, SnackbarUtil.SnackbarDuration.SHORT, callback);
} catch (CouldNotDeleteDataException e) {
SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_task_snackbar_error_deleting_task, SnackbarUtil.SnackbarDuration.LONG, null);
}
dialog.dismiss();
}
}).setNegativeButton(getResources().getString(R.string.activity_task_dialog_delete_negative), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create();
dialog.show();
}
use of ve.com.abicelis.remindy.exception.CouldNotDeleteDataException in project Remindy by abicelis.
the class RemindyDAO method deletePlace.
/* Delete data from database */
/**
* Deletes a single Place, given its ID, also deletes Location-based reminders associated with place and updates Task ReminderType to NONE
* @param placeId The ID of the place to delete
*/
public boolean deletePlace(int placeId) throws CouldNotDeleteDataException {
SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
List<Task> tasks;
try {
tasks = getLocationBasedTasksAssociatedWithPlace(placeId, -1);
} catch (CouldNotGetDataException e) {
throw new CouldNotDeleteDataException("Error getting Task list associated with Place. PlaceID=" + placeId, e);
}
if (tasks.size() > 0) {
//Remove Location-based reminders from task, and update task ReminderType to NONE.
for (Task task : tasks) {
deleteReminderOfTask(task.getId());
task.setStatus(TaskStatus.UNPROGRAMMED);
task.setReminderType(ReminderType.NONE);
try {
updateTask(task);
} catch (CouldNotUpdateDataException e) {
throw new CouldNotDeleteDataException("Error updating RemidnerType of Task to NONE. TaskID=" + task.getId(), e);
}
}
}
return db.delete(RemindyContract.PlaceTable.TABLE_NAME, RemindyContract.PlaceTable._ID + " =?", new String[] { String.valueOf(placeId) }) > 0;
}
Aggregations