Search in sources :

Example 1 with UpdateResultListener

use of org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener in project WordPress-Android by wordpress-mobile.

the class ReaderCommentService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null) {
        return START_NOT_STICKY;
    }
    EventBus.getDefault().post(new ReaderEvents.UpdateCommentsStarted());
    final long blogId = intent.getLongExtra(ARG_BLOG_ID, 0);
    final long postId = intent.getLongExtra(ARG_POST_ID, 0);
    final long commentId = intent.getLongExtra(ARG_COMMENT_ID, 0);
    boolean requestNextPage = intent.getBooleanExtra(ARG_NEXT_PAGE, false);
    if (requestNextPage) {
        int prevPage = ReaderCommentTable.getLastPageNumberForPost(blogId, postId);
        mCurrentPage = prevPage + 1;
    } else {
        mCurrentPage = 1;
    }
    updateCommentsForPost(blogId, postId, mCurrentPage, new UpdateResultListener() {

        @Override
        public void onUpdateResult(UpdateResult result) {
            if (commentId > 0) {
                if (ReaderCommentTable.commentExists(blogId, postId, commentId) || !result.isNewOrChanged()) {
                    EventBus.getDefault().post(new ReaderEvents.UpdateCommentsEnded(result));
                    stopSelf();
                } else {
                    // Comment not found yet, request the next page
                    mCurrentPage++;
                    updateCommentsForPost(blogId, postId, mCurrentPage, this);
                }
            } else {
                EventBus.getDefault().post(new ReaderEvents.UpdateCommentsEnded(result));
                stopSelf();
            }
        }
    });
    return START_NOT_STICKY;
}
Also used : UpdateResultListener(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener) ReaderEvents(org.wordpress.android.ui.reader.ReaderEvents) UpdateResult(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult)

Example 2 with UpdateResultListener

use of org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener in project WordPress-Android by wordpress-mobile.

the class ReaderPostService method updatePostsInBlog.

private void updatePostsInBlog(long blogId, final UpdateAction action) {
    UpdateResultListener listener = new UpdateResultListener() {

        @Override
        public void onUpdateResult(UpdateResult result) {
            EventBus.getDefault().post(new ReaderEvents.UpdatePostsEnded(result, action));
            stopSelf();
        }
    };
    requestPostsForBlog(blogId, action, listener);
}
Also used : UpdateResultListener(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener) ReaderEvents(org.wordpress.android.ui.reader.ReaderEvents) UpdateResult(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult)

Example 3 with UpdateResultListener

use of org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener in project WordPress-Android by wordpress-mobile.

the class ReaderPostService method updatePostsInFeed.

private void updatePostsInFeed(long feedId, final UpdateAction action) {
    UpdateResultListener listener = new UpdateResultListener() {

        @Override
        public void onUpdateResult(UpdateResult result) {
            EventBus.getDefault().post(new ReaderEvents.UpdatePostsEnded(result, action));
            stopSelf();
        }
    };
    requestPostsForFeed(feedId, action, listener);
}
Also used : UpdateResultListener(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener) ReaderEvents(org.wordpress.android.ui.reader.ReaderEvents) UpdateResult(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult)

Aggregations

ReaderEvents (org.wordpress.android.ui.reader.ReaderEvents)3 UpdateResult (org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult)3 UpdateResultListener (org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener)3