Search in sources :

Example 1 with RemotePostPayload

use of org.wordpress.android.fluxc.store.PostStore.RemotePostPayload 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 2 with RemotePostPayload

use of org.wordpress.android.fluxc.store.PostStore.RemotePostPayload in project WordPress-Android by wordpress-mobile.

the class PostPreviewActivity method revertPost.

/*
     * reverts local changes for this post, replacing it with the latest version from the server
     */
private void revertPost() {
    if (isFinishing() || !NetworkUtils.checkConnection(this)) {
        return;
    }
    if (mIsUpdatingPost) {
        AppLog.d(AppLog.T.POSTS, "post preview > already updating post");
    } else {
        mIsUpdatingPost = true;
        showProgress();
        RemotePostPayload payload = new RemotePostPayload(mPost, mSite);
        mDispatcher.dispatch(PostActionBuilder.newFetchPostAction(payload));
    }
}
Also used : RemotePostPayload(org.wordpress.android.fluxc.store.PostStore.RemotePostPayload)

Aggregations

RemotePostPayload (org.wordpress.android.fluxc.store.PostStore.RemotePostPayload)2 Snackbar (android.support.design.widget.Snackbar)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1