Search in sources :

Example 1 with CouldNotInsertDataException

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

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

the class TaskActivity method handleTaskSave.

private void handleTaskSave() {
    AttachmentUtil.cleanInvalidAttachments(mTask.getAttachments());
    try {
        RemindyDAO dao = new RemindyDAO(this);
        if (!editingTask) {
            //Insert the task
            dao.insertTask(mTask);
            //Update geofences
            if (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());
            }
        }
        //If editing, Caller activity TaskDetailActivity will save the task.
        BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {

            @Override
            public void onDismissed(Snackbar transientBottomBar, int event) {
                super.onDismissed(transientBottomBar, event);
                Intent returnIntent = new Intent();
                returnIntent.putExtra(HomeActivity.NEW_TASK_RETURN_REMINDER_TYPE, mTask.getReminderType());
                returnIntent.putExtra(TaskActivity.TASK_TO_EDIT, mTask);
                //Task was created, set result to OK
                setResult(RESULT_OK, returnIntent);
                finish();
            }
        };
        SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_task_snackbar_save_successful, SnackbarUtil.SnackbarDuration.SHORT, callback);
    } catch (CouldNotInsertDataException e) {
        SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_task_snackbar_error_saving, SnackbarUtil.SnackbarDuration.SHORT, null);
    }
}
Also used : CouldNotInsertDataException(ve.com.abicelis.remindy.exception.CouldNotInsertDataException) BaseTransientBottomBar(android.support.design.widget.BaseTransientBottomBar) Intent(android.content.Intent) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Snackbar(android.support.design.widget.Snackbar)

Example 3 with CouldNotInsertDataException

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

the class RemindyDAO method insertAttachmentsOfTask.

/**
     * Inserts a List of Attachments associated to an Task, into the database.
     * @param taskId The id of the Task associated to the Attachments
     * @param attachments The List of Attachments to be inserted
     */
public long[] insertAttachmentsOfTask(int taskId, List<Attachment> attachments) throws CouldNotInsertDataException {
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    long[] newRowIds = new long[attachments.size()];
    for (int i = 0; i < attachments.size(); i++) {
        Attachment attachment = attachments.get(i);
        attachment.setTaskId(taskId);
        ContentValues values = getValuesFromAttachment(attachment);
        newRowIds[i] = db.insert(RemindyContract.AttachmentTable.TABLE_NAME, null, values);
        if (newRowIds[i] == -1)
            throw new CouldNotInsertDataException("There was a problem inserting the Attachment: " + attachments.toString());
    }
    return newRowIds;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) CouldNotInsertDataException(ve.com.abicelis.remindy.exception.CouldNotInsertDataException) Attachment(ve.com.abicelis.remindy.model.attachment.Attachment) LinkAttachment(ve.com.abicelis.remindy.model.attachment.LinkAttachment) ListAttachment(ve.com.abicelis.remindy.model.attachment.ListAttachment) AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) TextAttachment(ve.com.abicelis.remindy.model.attachment.TextAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment)

Example 4 with CouldNotInsertDataException

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

the class RemindyDAO method insertTask.

/**
     * Inserts a new Task and its associated Reminder and Attachments into the database.
     * @param task The Task (and associated Reminder and Attachments) to insert
     */
public long insertTask(Task task) throws CouldNotInsertDataException {
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    ContentValues values = getValuesFromTask(task);
    long newRowId;
    newRowId = db.insert(RemindyContract.TaskTable.TABLE_NAME, null, values);
    if (newRowId == -1)
        throw new CouldNotInsertDataException("There was a problem inserting the Task: " + task.toString());
    //Insert Attachments
    if (task.getAttachments() != null && task.getAttachments().size() > 0) {
        try {
            insertAttachmentsOfTask((int) newRowId, task.getAttachments());
        } catch (CouldNotInsertDataException e) {
            throw new CouldNotInsertDataException("There was a problem inserting the Attachments while inserting the Task: " + task.toString(), e);
        }
    }
    //Insert Reminder if it exists
    if (task.getReminder() != null) {
        try {
            insertReminderOfTask((int) newRowId, task.getReminder());
        } catch (CouldNotInsertDataException e) {
            throw new CouldNotInsertDataException("There was a problem inserting the Reminder while inserting the Task: " + task.toString(), e);
        }
    }
    return newRowId;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) CouldNotInsertDataException(ve.com.abicelis.remindy.exception.CouldNotInsertDataException)

Example 5 with CouldNotInsertDataException

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

the class RemindyDAO method insertPlace.

/* Insert data into database */
/**
     * Inserts a new Place into the database.
     * @param place The Place to be inserted
     */
public long insertPlace(Place place) throws CouldNotInsertDataException {
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    ContentValues values = getValuesFromPlace(place);
    long newRowId;
    newRowId = db.insert(RemindyContract.PlaceTable.TABLE_NAME, null, values);
    if (newRowId == -1)
        throw new CouldNotInsertDataException("There was a problem inserting the Place: " + place.toString());
    return newRowId;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) CouldNotInsertDataException(ve.com.abicelis.remindy.exception.CouldNotInsertDataException)

Aggregations

CouldNotInsertDataException (ve.com.abicelis.remindy.exception.CouldNotInsertDataException)6 ContentValues (android.content.ContentValues)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 BaseTransientBottomBar (android.support.design.widget.BaseTransientBottomBar)2 Snackbar (android.support.design.widget.Snackbar)2 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)2 Intent (android.content.Intent)1 CouldNotUpdateDataException (ve.com.abicelis.remindy.exception.CouldNotUpdateDataException)1 Attachment (ve.com.abicelis.remindy.model.attachment.Attachment)1 AudioAttachment (ve.com.abicelis.remindy.model.attachment.AudioAttachment)1 ImageAttachment (ve.com.abicelis.remindy.model.attachment.ImageAttachment)1 LinkAttachment (ve.com.abicelis.remindy.model.attachment.LinkAttachment)1 ListAttachment (ve.com.abicelis.remindy.model.attachment.ListAttachment)1 TextAttachment (ve.com.abicelis.remindy.model.attachment.TextAttachment)1 LocationBasedReminder (ve.com.abicelis.remindy.model.reminder.LocationBasedReminder)1 OneTimeReminder (ve.com.abicelis.remindy.model.reminder.OneTimeReminder)1 RepeatingReminder (ve.com.abicelis.remindy.model.reminder.RepeatingReminder)1