use of ve.com.abicelis.remindy.database.RemindyDAO 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.database.RemindyDAO 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.database.RemindyDAO 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.database.RemindyDAO in project Remindy by abicelis.
the class GeofenceNotificationIntentService method onHandleIntent.
@Override
protected void onHandleIntent(@Nullable Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = GeofenceErrorMessages.getErrorString(this, geofencingEvent.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
// Log the transition type
handleLogTransition(geofenceTransition);
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || //|| geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER //Skipping this transition because of alert spam issues
geofenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) {
for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
List<Task> tasks = new ArrayList<>();
try {
tasks = new RemindyDAO(this).getLocationBasedTasksAssociatedWithPlace(Integer.valueOf(geofence.getRequestId()), geofenceTransition);
} catch (CouldNotGetDataException e) {
/* Do nothing */
}
if (tasks.size() > 0) {
String notificationTitle = getGeofenceNotificationTitle(geofenceTransition, geofence);
String notificationText = getGeofenceNotificationText(tasks);
// Send notification and log the transition details.
NotificationUtil.displayLocationBasedNotification(this, Integer.valueOf(geofence.getRequestId()), notificationTitle, notificationText, tasks);
Log.i(TAG, notificationTitle + " " + notificationText);
}
}
}
}
use of ve.com.abicelis.remindy.database.RemindyDAO in project Remindy by abicelis.
the class EditLocationBasedReminderFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
//If fragment was just called, expect a reminder at REMINDER_ARGUMENT
if (getArguments().containsKey(REMINDER_ARGUMENT))
mReminder = (LocationBasedReminder) getArguments().getSerializable(REMINDER_ARGUMENT);
else
Toast.makeText(getActivity(), getResources().getString(R.string.error_unexpected), Toast.LENGTH_SHORT).show();
mDao = new RemindyDAO(getActivity());
mPlaces = mDao.getPlaces();
//Set mReminder to the first place if empty
if (mReminder.getPlace() == null)
mReminder.setPlace(mPlaces.get(0));
for (Place p : mPlaces) mPlaceTypes.add(p.getAlias());
}
Aggregations