use of org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult 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;
}
use of org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult 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);
}
use of org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult 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);
}
use of org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult in project WordPress-Android by wordpress-mobile.
the class ReaderPostActions method handleUpdatePostResponse.
private static void handleUpdatePostResponse(final ReaderPost localPost, final JSONObject jsonObject, final UpdateResultListener resultListener) {
if (jsonObject == null) {
if (resultListener != null) {
resultListener.onUpdateResult(UpdateResult.FAILED);
}
return;
}
final Handler handler = new Handler();
new Thread() {
@Override
public void run() {
ReaderPost serverPost = ReaderPost.fromJson(jsonObject);
// before calling isSamePost (since the difference in those IDs causes it to return false)
if (serverPost.feedId == 0 && localPost.feedId != 0) {
serverPost.feedId = localPost.feedId;
}
if (serverPost.feedItemId == 0 && localPost.feedItemId != 0) {
serverPost.feedItemId = localPost.feedItemId;
}
boolean hasChanges = !serverPost.isSamePost(localPost);
if (hasChanges) {
AppLog.d(T.READER, "post updated");
// copy changes over to the local post - this is done instead of simply overwriting
// the local post with the server post because the server post was retrieved using
// the read/sites/$siteId/posts/$postId endpoint which is missing some information
// https://github.com/wordpress-mobile/WordPress-Android/issues/3164
localPost.numReplies = serverPost.numReplies;
localPost.numLikes = serverPost.numLikes;
localPost.isFollowedByCurrentUser = serverPost.isFollowedByCurrentUser;
localPost.isLikedByCurrentUser = serverPost.isLikedByCurrentUser;
localPost.isCommentsOpen = serverPost.isCommentsOpen;
localPost.setTitle(serverPost.getTitle());
localPost.setText(serverPost.getText());
ReaderPostTable.addOrUpdatePost(localPost);
}
// ensures that the liking avatars are immediately available to post detail
if (handlePostLikes(serverPost, jsonObject)) {
hasChanges = true;
}
if (resultListener != null) {
final UpdateResult result = (hasChanges ? UpdateResult.CHANGED : UpdateResult.UNCHANGED);
handler.post(new Runnable() {
public void run() {
resultListener.onUpdateResult(result);
}
});
}
}
}.start();
}
Aggregations