Search in sources :

Example 36 with Snackbar

use of android.support.design.widget.Snackbar 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 37 with Snackbar

use of android.support.design.widget.Snackbar 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 38 with Snackbar

use of android.support.design.widget.Snackbar 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 39 with Snackbar

use of android.support.design.widget.Snackbar in project teaTime by ancfdy.

the class SnackbarUtils method IndefiniteSnackbar.

/**
     * 自定义时常显示Snackbar,可选预设类型
     * @param view
     * @param message
     * @param type
     * @return
     */
public static Snackbar IndefiniteSnackbar(View view, String message, int duration, int type) {
    Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_INDEFINITE).setDuration(duration);
    switchType(snackbar, type);
    return snackbar;
}
Also used : Snackbar(android.support.design.widget.Snackbar)

Example 40 with Snackbar

use of android.support.design.widget.Snackbar in project teaTime by ancfdy.

the class SnackbarUtils method ShortSnackbar.

/**
     * 短显示Snackbar,可选预设类型
     * @param view
     * @param message
     * @param type
     * @return
     */
public static Snackbar ShortSnackbar(View view, String message, int type) {
    Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_SHORT);
    switchType(snackbar, type);
    return snackbar;
}
Also used : Snackbar(android.support.design.widget.Snackbar)

Aggregations

Snackbar (android.support.design.widget.Snackbar)102 View (android.view.View)56 TextView (android.widget.TextView)25 Intent (android.content.Intent)13 RecyclerView (android.support.v7.widget.RecyclerView)13 BaseTransientBottomBar (android.support.design.widget.BaseTransientBottomBar)10 ImageView (android.widget.ImageView)10 ViewGroup (android.view.ViewGroup)8 DialogInterface (android.content.DialogInterface)7 LayoutInflater (android.view.LayoutInflater)6 AdapterView (android.widget.AdapterView)6 LinearLayout (android.widget.LinearLayout)6 ListView (android.widget.ListView)6 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)5 AlertDialog (android.app.AlertDialog)4 Context (android.content.Context)4 Nullable (android.support.annotation.Nullable)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 File (java.io.File)4 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)4