Search in sources :

Example 31 with Snackbar

use of android.support.design.widget.Snackbar in project YourAppIdea by Michenux.

the class SnackbarHelper method showErrorLongMessageWithAction.

public static void showErrorLongMessageWithAction(View view, @StringRes int message, @StringRes int actionMessage, View.OnClickListener actionOnClickListener) {
    Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_LONG).setAction(actionMessage, actionOnClickListener);
    snackbar.setActionTextColor(Color.RED);
    View sbView = snackbar.getView();
    TextView textView = (TextView) sbView.findViewById(org.michenux.drodrolib.R.id.snackbar_text);
    textView.setTextColor(Color.YELLOW);
    snackbar.show();
}
Also used : TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) Snackbar(android.support.design.widget.Snackbar)

Example 32 with Snackbar

use of android.support.design.widget.Snackbar in project WordPress-Android by wordpress-mobile.

the class CommentsActivity method onModerateComment.

@Override
public void onModerateComment(final SiteModel site, final CommentModel comment, final CommentStatus newStatus) {
    FragmentManager fm = getFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStack();
    }
    if (newStatus == CommentStatus.APPROVED || newStatus == CommentStatus.UNAPPROVED) {
        getListFragment().updateEmptyView();
        comment.setStatus(newStatus.toString());
        mDispatcher.dispatch(CommentActionBuilder.newUpdateCommentAction(comment));
        mDispatcher.dispatch(CommentActionBuilder.newPushCommentAction(new RemoteCommentPayload(mSite, comment)));
    } else if (newStatus == CommentStatus.SPAM || newStatus == CommentStatus.TRASH || newStatus == CommentStatus.DELETED) {
        mTrashedComments.add(comment);
        getListFragment().removeComment(comment);
        String message = (newStatus == CommentStatus.TRASH ? getString(R.string.comment_trashed) : newStatus == CommentStatus.SPAM ? getString(R.string.comment_spammed) : getString(R.string.comment_deleted_permanently));
        View.OnClickListener undoListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mTrashedComments.remove(comment);
                getListFragment().loadComments();
            }
        };
        Snackbar snackbar = Snackbar.make(getListFragment().getView(), message, Snackbar.LENGTH_LONG).setAction(R.string.undo, undoListener);
        // do the actual moderation once the undo bar has been hidden
        snackbar.setCallback(new Snackbar.Callback() {

            @Override
            public void onDismissed(Snackbar snackbar, int event) {
                super.onDismissed(snackbar, event);
                // comment will no longer exist in moderating list if action was undone
                if (!mTrashedComments.contains(comment)) {
                    return;
                }
                mTrashedComments.remove(comment);
                moderateComment(comment, newStatus);
            }
        });
        snackbar.show();
    }
}
Also used : FragmentManager(android.app.FragmentManager) View(android.view.View) RemoteCommentPayload(org.wordpress.android.fluxc.store.CommentStore.RemoteCommentPayload) Snackbar(android.support.design.widget.Snackbar)

Example 33 with Snackbar

use of android.support.design.widget.Snackbar in project WordPress-Android by wordpress-mobile.

the class PostsListFragment method trashPost.

/*
     * send the passed post to the trash with undo
     */
private void trashPost(final PostModel post) {
    //been posted to the server so they can be trashed w/o further care
    if (!isAdded() || (!post.isLocalDraft() && !NetworkUtils.checkConnection(getActivity())) || getPostListAdapter() == null) {
        return;
    }
    // remove post from the list and add it to the list of trashed posts
    getPostListAdapter().hidePost(post);
    mTrashedPosts.add(post);
    // make sure empty view shows if user deleted the only post
    if (getPostListAdapter().getItemCount() == 0) {
        updateEmptyView(EmptyViewMessageType.NO_CONTENT);
    }
    View.OnClickListener undoListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // user undid the trash, so unhide the post and remove it from the list of trashed posts
            mTrashedPosts.remove(post);
            getPostListAdapter().unhidePost(post);
            hideEmptyView();
        }
    };
    // different undo text if this is a local draft since it will be deleted rather than trashed
    String text;
    if (post.isLocalDraft()) {
        text = mIsPage ? getString(R.string.page_deleted) : getString(R.string.post_deleted);
    } else {
        text = mIsPage ? getString(R.string.page_trashed) : getString(R.string.post_trashed);
    }
    Snackbar snackbar = Snackbar.make(getView().findViewById(R.id.coordinator), text, Snackbar.LENGTH_LONG).setAction(R.string.undo, undoListener);
    // wait for the undo snackbar to disappear before actually deleting the post
    snackbar.setCallback(new Snackbar.Callback() {

        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            super.onDismissed(snackbar, event);
            // user undid the trash, so don't perform the deletion
            if (!mTrashedPosts.contains(post)) {
                return;
            }
            // remove from the list of trashed posts in case onDismissed is called multiple
            // times - this way the above check prevents us making the call to delete it twice
            // https://code.google.com/p/android/issues/detail?id=190529
            mTrashedPosts.remove(post);
            if (post.isLocalDraft()) {
                mDispatcher.dispatch(PostActionBuilder.newRemovePostAction(post));
                // delete the pending draft notification if available
                mShouldCancelPendingDraftNotification = false;
                int pushId = PendingDraftsNotificationsUtils.makePendingDraftNotificationId(post.getId());
                NativeNotificationsUtils.dismissNotification(pushId, getActivity());
            } else {
                mDispatcher.dispatch(PostActionBuilder.newDeletePostAction(new RemotePostPayload(post, mSite)));
            }
        }
    });
    mPostIdForPostToBeDeleted = post.getId();
    mShouldCancelPendingDraftNotification = true;
    snackbar.show();
}
Also used : RemotePostPayload(org.wordpress.android.fluxc.store.PostStore.RemotePostPayload) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Snackbar(android.support.design.widget.Snackbar)

Example 34 with Snackbar

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

use of android.support.design.widget.Snackbar in project Remindy by abicelis.

the class EditImageAttachmentActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_image_attachment);
    mContainer = (RelativeLayout) findViewById(R.id.activity_edit_image_attachment_container);
    mImage = (ImageView) findViewById(R.id.activity_edit_image_attachment_image);
    mCrop = (FloatingActionButton) findViewById(R.id.activity_edit_image_attachment_crop);
    mRotate = (FloatingActionButton) findViewById(R.id.activity_edit_image_attachment_rotate);
    mCamera = (FloatingActionButton) findViewById(R.id.activity_edit_image_attachment_camera);
    mOk = (Button) findViewById(R.id.activity_edit_image_attachment_ok);
    mCancel = (Button) findViewById(R.id.activity_edit_image_attachment_cancel);
    if (savedInstanceState != null) {
        //Rotated screen!
        mImageAttachment = (ImageAttachment) savedInstanceState.getSerializable(IMAGE_ATTACHMENT_EXTRA);
        mHolderPosition = savedInstanceState.getInt(HOLDER_POSITION_EXTRA);
        mEditingExistingImageAttachment = savedInstanceState.getBoolean(EDITING_ATTACHMENT_EXTRA);
        mImageBackup = ImageUtil.getBitmap(new File(FileUtil.getImageAttachmentDir(this), mImageAttachment.getImageFilename()));
        if (mImageBackup == null) {
            //IF image was deleted from device
            mImageBackup = ImageUtil.getBitmap(mImageAttachment.getThumbnail());
            saveThumbnailAsImageFile(mImageBackup);
        }
        mImage.setImageBitmap(mImageBackup);
    } else {
        if (getIntent().hasExtra(HOLDER_POSITION_EXTRA) && getIntent().hasExtra(IMAGE_ATTACHMENT_EXTRA)) {
            mHolderPosition = getIntent().getIntExtra(HOLDER_POSITION_EXTRA, -1);
            mImageAttachment = (ImageAttachment) getIntent().getSerializableExtra(IMAGE_ATTACHMENT_EXTRA);
            if (mImageAttachment.getImageFilename() != null && !mImageAttachment.getImageFilename().isEmpty()) {
                mImageBackup = ImageUtil.getBitmap(new File(FileUtil.getImageAttachmentDir(this), mImageAttachment.getImageFilename()));
                if (mImageBackup == null) {
                    //IF image was deleted from device
                    mImageBackup = ImageUtil.getBitmap(mImageAttachment.getThumbnail());
                    saveThumbnailAsImageFile(mImageBackup);
                }
                mEditingExistingImageAttachment = true;
                mImage.setImageBitmap(mImageBackup);
            } else {
                mImageAttachment = new ImageAttachment();
                mImageAttachment.setImageFilename(UUID.randomUUID().toString() + IMAGE_FILE_EXTENSION);
                handleShowCameraGalleryDialog();
            }
        } else {
            BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {

                @Override
                public void onDismissed(Snackbar transientBottomBar, int event) {
                    super.onDismissed(transientBottomBar, event);
                    setResult(RESULT_CANCELED);
                    finish();
                }
            };
            Log.e(TAG, "Missing HOLDER_POSITION_EXTRA and/or IMAGE_ATTACHMENT_EXTRA parameters in EditImageAttachmentActivity.");
            SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.ERROR, R.string.error_unexpected, SnackbarUtil.SnackbarDuration.LONG, callback);
            finish();
        }
    //            mImageAttachment = new ImageAttachment(new byte[0], "09ce7135-86d6-4d93-bcc5-1fbff5651d0f.jpg");
    //            mImageBackup = ImageUtil.getBitmap(new File(FileUtil.getImageAttachmentDir(this), mImageAttachment.getImageFilename()));
    //            mEditingExistingImageAttachment = true;
    //            mImage.setImageBitmap(mImageBackup);
    }
    mRotation = 0;
    mCrop.setOnClickListener(this);
    mRotate.setOnClickListener(this);
    mCamera.setOnClickListener(this);
    mOk.setOnClickListener(this);
    mCancel.setOnClickListener(this);
}
Also used : BaseTransientBottomBar(android.support.design.widget.BaseTransientBottomBar) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment) File(java.io.File) 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