Skip to content

Commit

Permalink
Fix #1806 - viewing a single post in the pager now handles the case w…
Browse files Browse the repository at this point in the history
…hen the post doesn't already exist in the local database.
  • Loading branch information
nbradbury committed Sep 3, 2014
1 parent 614fd45 commit 572bcc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ protected void onPostExecute(Boolean result) {
// the server if it hasn't already been requested
if (!mHasAlreadyRequestedPost) {
mHasAlreadyRequestedPost = true;
AppLog.i(T.READER, "reader post detail > post not found, requesting it");
requestPost();
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.wordpress.android.models.ReaderPost;
import org.wordpress.android.models.ReaderPostList;
import org.wordpress.android.models.ReaderTag;
import org.wordpress.android.util.NetworkUtils;
import org.wordpress.android.ui.reader.ReaderAnim.AnimationEndListener;
import org.wordpress.android.ui.reader.ReaderAnim.Duration;
import org.wordpress.android.ui.reader.ReaderPostPagerEndFragment.EndFragmentType;
Expand All @@ -40,6 +39,7 @@
import org.wordpress.android.ui.reader.models.ReaderBlogIdPostIdList;
import org.wordpress.android.ui.reader.utils.ReaderUtils;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.NetworkUtils;
import org.wordpress.android.util.ToastUtils;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -232,15 +232,12 @@ private void loadPosts(final long blogId,
new Thread() {
@Override
public void run() {
final ReaderPostList postList;
final ReaderBlogIdPostIdList idList;
if (mIsSinglePostView) {
ReaderPost post = ReaderPostTable.getPost(blogId, postId);
if (post == null) {
return;
}
postList = new ReaderPostList();
postList.add(post);
idList = new ReaderBlogIdPostIdList();
idList.add(new ReaderBlogIdPostId(blogId, postId));
} else {
final ReaderPostList postList;
int maxPosts = ReaderConstants.READER_MAX_POSTS_TO_DISPLAY;
switch (getPostListType()) {
case TAG_FOLLOWED:
Expand All @@ -253,22 +250,22 @@ public void run() {
default:
return;
}
idList = postList.getBlogIdPostIdList();
}

final ReaderBlogIdPostIdList ids = postList.getBlogIdPostIdList();
final int currentPosition = mViewPager.getCurrentItem();
final int newPosition;
if (gotoNext) {
newPosition = ids.indexOf(blogId, postId) + 1;
newPosition = idList.indexOf(blogId, postId) + 1;
} else {
newPosition = ids.indexOf(blogId, postId);
newPosition = idList.indexOf(blogId, postId);
}

runOnUiThread(new Runnable() {
@Override
public void run() {
mPagerAdapter = new PostPagerAdapter(getFragmentManager());
mPagerAdapter.showPosts(ids);
mPagerAdapter.showPosts(idList);
mViewPager.setAdapter(mPagerAdapter);
if (mPagerAdapter.isValidPosition(newPosition)) {
mViewPager.setCurrentItem(newPosition);
Expand Down

1 comment on commit 572bcc2

@roundhill
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed fixed in the notifications branch 👍

Please sign in to comment.