use of ve.com.abicelis.remindy.database.RemindyDAO in project Remindy by abicelis.
the class TaskDetailActivity method handleDeleteTask.
public void handleDeleteTask() {
AlertDialog dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.activity_task_dialog_delete_title)).setMessage(getResources().getString(R.string.activity_task_dialog_delete_message)).setPositiveButton(getResources().getString(R.string.activity_task_dialog_delete_positive), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
FileUtil.deleteAttachmentFiles(TaskDetailActivity.this, mTask.getAttachments());
new RemindyDAO(TaskDetailActivity.this).deleteTask(mTask.getId());
BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
super.onDismissed(transientBottomBar, event);
//Return task position to HomeListFragment, and also notify deletion
Intent returnIntent = new Intent();
returnIntent.putExtra(TASK_DETAIL_RETURN_ACTION_TYPE, TASK_DETAIL_RETURN_ACTION_DELETED);
returnIntent.putExtra(TASK_DETAIL_RETURN_TASK_POSITION, mPosition);
returnIntent.putExtra(TASK_DETAIL_RETURN_TASK_VIEWPAGER_INDEX, getViewPagerIndexFromTask(mTask));
setResult(RESULT_OK, returnIntent);
finish();
}
};
SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_task_snackbar_task_deleted_successfully, SnackbarUtil.SnackbarDuration.SHORT, callback);
} catch (CouldNotDeleteDataException e) {
SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_task_snackbar_error_deleting_task, SnackbarUtil.SnackbarDuration.LONG, null);
}
dialog.dismiss();
}
}).setNegativeButton(getResources().getString(R.string.activity_task_dialog_delete_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 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.database.RemindyDAO in project Remindy by abicelis.
the class AlarmManagerUtil method updateAlarms.
public static void updateAlarms(Context context) {
Log.d(TAG, "Updating alarms.");
List<Integer> triggeredTasks = SharedPreferenceUtil.getTriggeredTaskList(context);
Log.d(TAG, "TriggeredTask IDs = " + TextUtils.join(",", triggeredTasks));
//Get next task to trigger
TaskTriggerViewModel task;
try {
task = new RemindyDAO(context).getNextTaskToTrigger(triggeredTasks);
} catch (CouldNotGetDataException e) {
task = null;
}
if (task != null) {
Log.d(TAG, "Got Task ID " + task.getTask().getId() + ". Title:" + task.getTask().getTitle());
int triggerMinutesBeforeNotification = SharedPreferenceUtil.getTriggerMinutesBeforeNotification(context).getMinutes();
Calendar triggerTime = Calendar.getInstance();
CalendarUtil.copyCalendar(task.getTriggerDateWithTime(), triggerTime);
triggerTime.add(Calendar.MINUTE, -triggerMinutesBeforeNotification);
//Build intent
Intent triggerIntent = new Intent(context, TriggerTaskNotificationReceiver.class);
triggerIntent.putExtra(TriggerTaskNotificationReceiver.TASK_ID_EXTRA, task.getTask().getId());
if (triggerTime.compareTo(Calendar.getInstance()) <= 0) {
//Trigger now
Log.d(TAG, "Triggering now!");
context.sendBroadcast(triggerIntent);
} else {
//Set Alarm
Log.d(TAG, "Programming alarm for " + triggerTime.getTime());
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, triggerIntent, 0);
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
manager.set(AlarmManager.RTC_WAKEUP, triggerTime.getTimeInMillis(), pendingIntent);
}
}
Toast.makeText(context, "Alarms updated!", Toast.LENGTH_SHORT).show();
}
use of ve.com.abicelis.remindy.database.RemindyDAO in project Remindy by abicelis.
the class GeofenceUtil method addGeofences.
/* GeoFence management methods */
public static void addGeofences(final Context context, GoogleApiClient googleApiClient) {
checkGoogleApiClient(googleApiClient);
List<Place> places = new RemindyDAO(context).getActivePlaces();
if (places.size() > 0) {
if (PackageManager.PERMISSION_GRANTED == ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) {
LocationServices.GeofencingApi.addGeofences(googleApiClient, getGeofencingRequest(places), getGeofencePendingIntent(context)).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess())
Toast.makeText(context, "Geofences added/updated!", Toast.LENGTH_SHORT).show();
}
});
}
}
}
use of ve.com.abicelis.remindy.database.RemindyDAO in project Remindy by abicelis.
the class GeofenceNotificationIntentService method getGeofenceNotificationTitle.
private String getGeofenceNotificationTitle(int geofenceTransition, Geofence triggeringGeofence) {
String transition = "";
switch(geofenceTransition) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
transition = getResources().getString(R.string.notification_service_geofence_enter);
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
transition = getResources().getString(R.string.notification_service_geofence_exit);
break;
case Geofence.GEOFENCE_TRANSITION_DWELL:
//transition = getResources().getString(R.string.notification_service_geofence_dwell);
transition = getResources().getString(R.string.notification_service_geofence_enter);
break;
}
int placeId = Integer.valueOf(triggeringGeofence.getRequestId());
try {
Place place = new RemindyDAO(this).getPlace(placeId);
return String.format(Locale.getDefault(), getResources().getString(R.string.notification_service_geofence_title), transition, place.getAlias());
} catch (PlaceNotFoundException e) {
return "";
}
}
Aggregations