Skip to content

Commit 572bcc2

Browse files
committed
Fix #1806 - viewing a single post in the pager now handles the case when the post doesn't already exist in the local database.
1 parent 614fd45 commit 572bcc2

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ protected void onPostExecute(Boolean result) {
10801080
// the server if it hasn't already been requested
10811081
if (!mHasAlreadyRequestedPost) {
10821082
mHasAlreadyRequestedPost = true;
1083+
AppLog.i(T.READER, "reader post detail > post not found, requesting it");
10831084
requestPost();
10841085
}
10851086
return;

WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.wordpress.android.models.ReaderPost;
2626
import org.wordpress.android.models.ReaderPostList;
2727
import org.wordpress.android.models.ReaderTag;
28-
import org.wordpress.android.util.NetworkUtils;
2928
import org.wordpress.android.ui.reader.ReaderAnim.AnimationEndListener;
3029
import org.wordpress.android.ui.reader.ReaderAnim.Duration;
3130
import org.wordpress.android.ui.reader.ReaderPostPagerEndFragment.EndFragmentType;
@@ -40,6 +39,7 @@
4039
import org.wordpress.android.ui.reader.models.ReaderBlogIdPostIdList;
4140
import org.wordpress.android.ui.reader.utils.ReaderUtils;
4241
import org.wordpress.android.util.AppLog;
42+
import org.wordpress.android.util.NetworkUtils;
4343
import org.wordpress.android.util.ToastUtils;
4444

4545
import javax.annotation.Nonnull;
@@ -232,15 +232,12 @@ private void loadPosts(final long blogId,
232232
new Thread() {
233233
@Override
234234
public void run() {
235-
final ReaderPostList postList;
235+
final ReaderBlogIdPostIdList idList;
236236
if (mIsSinglePostView) {
237-
ReaderPost post = ReaderPostTable.getPost(blogId, postId);
238-
if (post == null) {
239-
return;
240-
}
241-
postList = new ReaderPostList();
242-
postList.add(post);
237+
idList = new ReaderBlogIdPostIdList();
238+
idList.add(new ReaderBlogIdPostId(blogId, postId));
243239
} else {
240+
final ReaderPostList postList;
244241
int maxPosts = ReaderConstants.READER_MAX_POSTS_TO_DISPLAY;
245242
switch (getPostListType()) {
246243
case TAG_FOLLOWED:
@@ -253,22 +250,22 @@ public void run() {
253250
default:
254251
return;
255252
}
253+
idList = postList.getBlogIdPostIdList();
256254
}
257255

258-
final ReaderBlogIdPostIdList ids = postList.getBlogIdPostIdList();
259256
final int currentPosition = mViewPager.getCurrentItem();
260257
final int newPosition;
261258
if (gotoNext) {
262-
newPosition = ids.indexOf(blogId, postId) + 1;
259+
newPosition = idList.indexOf(blogId, postId) + 1;
263260
} else {
264-
newPosition = ids.indexOf(blogId, postId);
261+
newPosition = idList.indexOf(blogId, postId);
265262
}
266263

267264
runOnUiThread(new Runnable() {
268265
@Override
269266
public void run() {
270267
mPagerAdapter = new PostPagerAdapter(getFragmentManager());
271-
mPagerAdapter.showPosts(ids);
268+
mPagerAdapter.showPosts(idList);
272269
mViewPager.setAdapter(mPagerAdapter);
273270
if (mPagerAdapter.isValidPosition(newPosition)) {
274271
mViewPager.setCurrentItem(newPosition);

0 commit comments

Comments
 (0)