Search in sources :

Example 1 with CouldNotUpdateDataException

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);
        }
    }
}
Also used : CouldNotUpdateDataException(ve.com.abicelis.remindy.exception.CouldNotUpdateDataException) CouldNotInsertDataException(ve.com.abicelis.remindy.exception.CouldNotInsertDataException) BaseTransientBottomBar(android.support.design.widget.BaseTransientBottomBar) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Snackbar(android.support.design.widget.Snackbar)

Example 2 with CouldNotUpdateDataException

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);
        }
    }
}
Also used : CouldNotUpdateDataException(ve.com.abicelis.remindy.exception.CouldNotUpdateDataException) Gson(com.google.gson.Gson) Intent(android.content.Intent) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO)

Example 3 with CouldNotUpdateDataException

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();
            }
        }
    }
}
Also used : CouldNotUpdateDataException(ve.com.abicelis.remindy.exception.CouldNotUpdateDataException) Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) NotificationManager(android.app.NotificationManager) OneTimeReminder(ve.com.abicelis.remindy.model.reminder.OneTimeReminder) RepeatingReminder(ve.com.abicelis.remindy.model.reminder.RepeatingReminder) Time(ve.com.abicelis.remindy.model.Time) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO)

Example 4 with CouldNotUpdateDataException

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;
}
Also used : CouldNotUpdateDataException(ve.com.abicelis.remindy.exception.CouldNotUpdateDataException) 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)

Aggregations

CouldNotUpdateDataException (ve.com.abicelis.remindy.exception.CouldNotUpdateDataException)4 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)3 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)2 Task (ve.com.abicelis.remindy.model.Task)2 NotificationManager (android.app.NotificationManager)1 Intent (android.content.Intent)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 BaseTransientBottomBar (android.support.design.widget.BaseTransientBottomBar)1 Snackbar (android.support.design.widget.Snackbar)1 Gson (com.google.gson.Gson)1 CouldNotDeleteDataException (ve.com.abicelis.remindy.exception.CouldNotDeleteDataException)1 CouldNotInsertDataException (ve.com.abicelis.remindy.exception.CouldNotInsertDataException)1 Time (ve.com.abicelis.remindy.model.Time)1 OneTimeReminder (ve.com.abicelis.remindy.model.reminder.OneTimeReminder)1 RepeatingReminder (ve.com.abicelis.remindy.model.reminder.RepeatingReminder)1