Search in sources :

Example 6 with RemindyDAO

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();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) BaseTransientBottomBar(android.support.design.widget.BaseTransientBottomBar) Intent(android.content.Intent) CouldNotDeleteDataException(ve.com.abicelis.remindy.exception.CouldNotDeleteDataException) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Snackbar(android.support.design.widget.Snackbar)

Example 7 with RemindyDAO

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);
        }
    }
}
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 8 with RemindyDAO

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();
}
Also used : CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) Calendar(java.util.Calendar) AlarmManager(android.app.AlarmManager) TaskTriggerViewModel(ve.com.abicelis.remindy.viewmodel.TaskTriggerViewModel) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO)

Example 9 with RemindyDAO

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();
                }
            });
        }
    }
}
Also used : Status(com.google.android.gms.common.api.Status) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Place(ve.com.abicelis.remindy.model.Place)

Example 10 with RemindyDAO

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 "";
    }
}
Also used : PlaceNotFoundException(ve.com.abicelis.remindy.exception.PlaceNotFoundException) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Place(ve.com.abicelis.remindy.model.Place)

Aggregations

RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)12 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)5 Intent (android.content.Intent)4 BaseTransientBottomBar (android.support.design.widget.BaseTransientBottomBar)4 Snackbar (android.support.design.widget.Snackbar)4 Task (ve.com.abicelis.remindy.model.Task)4 CouldNotUpdateDataException (ve.com.abicelis.remindy.exception.CouldNotUpdateDataException)3 Place (ve.com.abicelis.remindy.model.Place)3 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 ArrayList (java.util.ArrayList)2 CouldNotDeleteDataException (ve.com.abicelis.remindy.exception.CouldNotDeleteDataException)2 CouldNotInsertDataException (ve.com.abicelis.remindy.exception.CouldNotInsertDataException)2 OneTimeReminder (ve.com.abicelis.remindy.model.reminder.OneTimeReminder)2 RepeatingReminder (ve.com.abicelis.remindy.model.reminder.RepeatingReminder)2 AlarmManager (android.app.AlarmManager)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 StringRes (android.support.annotation.StringRes)1 Status (com.google.android.gms.common.api.Status)1