Search in sources :

Example 1 with RemindyDAO

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

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

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();
}
Also used : AlertDialog(android.app.AlertDialog) Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) DialogInterface(android.content.DialogInterface) StringRes(android.support.annotation.StringRes) BaseTransientBottomBar(android.support.design.widget.BaseTransientBottomBar) ArrayList(java.util.ArrayList) CouldNotDeleteDataException(ve.com.abicelis.remindy.exception.CouldNotDeleteDataException) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Snackbar(android.support.design.widget.Snackbar)

Example 4 with RemindyDAO

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);
            }
        }
    }
}
Also used : Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) ArrayList(java.util.ArrayList) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) GeofencingEvent(com.google.android.gms.location.GeofencingEvent) Geofence(com.google.android.gms.location.Geofence)

Example 5 with RemindyDAO

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());
}
Also used : LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder) 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