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