use of ve.com.abicelis.remindy.exception.CouldNotUpdateDataException in project Remindy by abicelis.
the class PlaceActivity method handleSaveOrUpdatePlace.
private void handleSaveOrUpdatePlace() {
BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
super.onDismissed(transientBottomBar, event);
setResult(RESULT_OK);
finish();
}
};
mDao = new RemindyDAO(getApplicationContext());
// Verify mPlace is set
if (mPlace.getLongitude() == 0) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_no_place, SnackbarUtil.SnackbarDuration.LONG, null);
return;
}
if (mPlace.getAlias() == null || mPlace.getAlias().isEmpty() || mPlace.getAlias().equals(getResources().getString(R.string.activity_place_alias_hint))) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.NOTICE, R.string.activity_place_snackbar_error_no_alias, SnackbarUtil.SnackbarDuration.LONG, null);
return;
}
if (mPlaceToEdit != null) {
try {
mDao.updatePlace(mPlace);
// Update geofences when updating places!
GeofenceUtil.updateGeofences(getApplicationContext(), mGoogleApiClient);
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_place_snackbar_edit_succesful, SnackbarUtil.SnackbarDuration.SHORT, callback);
} catch (CouldNotUpdateDataException e) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_saving, SnackbarUtil.SnackbarDuration.LONG, null);
}
} else {
try {
mDao.insertPlace(mPlace);
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_place_snackbar_save_succesful, SnackbarUtil.SnackbarDuration.SHORT, callback);
} catch (CouldNotInsertDataException e) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_saving, SnackbarUtil.SnackbarDuration.LONG, null);
}
}
}
use of ve.com.abicelis.remindy.exception.CouldNotUpdateDataException in project Remindy by abicelis.
the class TaskDetailActivity method onBackPressed.
@Override
public void onBackPressed() {
super.onBackPressed();
if (mTaskDataUpdated) {
try {
// Clean attachments
AttachmentUtil.cleanInvalidAttachments(mTask.getAttachments());
// Save changes
new RemindyDAO(this).updateTask(mTask);
// Update geofences
if (mUpdateGeofences || mTask.getReminderType().equals(ReminderType.LOCATION_BASED))
GeofenceUtil.updateGeofences(getApplicationContext(), mGoogleApiClient);
// Update alarms
if (mTask.getReminderType().equals(ReminderType.ONE_TIME) || mTask.getReminderType().equals(ReminderType.REPEATING)) {
// Remove task from triggeredTasks list
SharedPreferenceUtil.removeIdFromTriggeredTasks(getApplicationContext(), mTask.getId());
// Update alarms
AlarmManagerUtil.updateAlarms(getApplicationContext());
}
// See if reminder was edited, in which case refresh the whole home viewpager
String newReminderJson = new Gson().toJson(mTask.getReminder());
int taskDetailReturnActionType = (mOldReminderJson.equals(newReminderJson) ? TASK_DETAIL_RETURN_ACTION_EDITED : TASK_DETAIL_RETURN_ACTION_EDITED_REMINDER);
// Return task position to HomeListFragment, and also notify edition!!
Intent returnIntent = new Intent();
returnIntent.putExtra(TASK_DETAIL_RETURN_ACTION_TYPE, taskDetailReturnActionType);
returnIntent.putExtra(TASK_DETAIL_RETURN_TASK_POSITION, mPosition);
returnIntent.putExtra(TASK_DETAIL_RETURN_TASK_VIEWPAGER_INDEX, getViewPagerIndexFromTask(mTask));
setResult(RESULT_OK, returnIntent);
// When user backs out, transition back!
supportFinishAfterTransition();
} catch (CouldNotUpdateDataException e) {
SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_task_snackbar_error_updating_task, SnackbarUtil.SnackbarDuration.LONG, null);
}
}
}
use of ve.com.abicelis.remindy.exception.CouldNotUpdateDataException in project Remindy by abicelis.
the class TaskActionsIntentService method onHandleIntent.
@Override
protected void onHandleIntent(@Nullable Intent intent) {
if (intent == null || intent.getAction() == null)
return;
if (intent.getAction().equals(ACTION_SET_TASK_DONE)) {
int taskId = intent.getIntExtra(PARAM_TASK_ID, -1);
if (taskId != -1) {
// Dismiss the notification
NotificationManager mNotifyMgr = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.cancel(taskId);
RemindyDAO dao = new RemindyDAO(getApplicationContext());
try {
Task task = dao.getTask(taskId);
task.setDoneDate(CalendarUtil.getNewInstanceZeroedCalendar());
task.setStatus(TaskStatus.DONE);
dao.updateTask(task);
} catch (CouldNotGetDataException | CouldNotUpdateDataException e) {
Toast.makeText(this, getResources().getString(R.string.task_actions_service_could_not_set_done), Toast.LENGTH_SHORT).show();
}
}
} else if (intent.getAction().equals(ACTION_POSTPONE_TASK)) {
int taskId = intent.getIntExtra(PARAM_TASK_ID, -1);
if (taskId != -1) {
// Dismiss the notification
NotificationManager mNotifyMgr = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.cancel(taskId);
RemindyDAO dao = new RemindyDAO(getApplicationContext());
try {
Task task = dao.getTask(taskId);
Time time;
switch(task.getReminderType()) {
case REPEATING:
time = ((RepeatingReminder) task.getReminder()).getTime();
break;
case ONE_TIME:
time = ((OneTimeReminder) task.getReminder()).getTime();
break;
default:
// TODO: Show some kind of error?
return;
}
int timeInMinutes = time.getTimeInMinutes();
timeInMinutes += POSTPONE_MINUTES;
// Set max per day to 24:59:00
timeInMinutes = (timeInMinutes >= 1440 ? 1339 : timeInMinutes);
time.setTimeInMinutes(timeInMinutes);
dao.updateTask(task);
// Remove task from triggeredTasks list
SharedPreferenceUtil.removeIdFromTriggeredTasks(getApplicationContext(), task.getId());
// Update alarms
AlarmManagerUtil.updateAlarms(getApplicationContext());
} catch (CouldNotGetDataException | CouldNotUpdateDataException e) {
Toast.makeText(this, getResources().getString(R.string.task_actions_service_could_not_set_done), Toast.LENGTH_SHORT).show();
}
}
}
}
use of ve.com.abicelis.remindy.exception.CouldNotUpdateDataException 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