From 9ad6d705e6e83c3b9768a0fc34557286bc5eccbd Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 20 Apr 2021 23:58:46 +0800 Subject: Fix post not updating in PostFragment after voting it in ViewPostDetailFragment. --- .../activities/ViewPostDetailActivity.java | 5 ++-- .../adapters/PostRecyclerViewAdapter.java | 34 +++++++++++----------- .../events/PostUpdateEventToDetailActivity.java | 11 ------- .../PostUpdateEventToPostDetailFragment.java | 11 +++++++ .../fragments/ViewPostDetailFragment.java | 4 +-- 5 files changed, 33 insertions(+), 32 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/events/PostUpdateEventToDetailActivity.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/events/PostUpdateEventToPostDetailFragment.java diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 41a09c37..48ae7d93 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -113,7 +113,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele private String mAccessToken; private String mAccountName; private long postFragmentId; - private int postListPosition = -1; + private int postListPosition; private int orientation; private boolean mVolumeKeysNavigateComments; private boolean isNsfwSubreddit; @@ -172,6 +172,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele EventBus.getDefault().post(new NeedForPostListFromPostFragmentEvent(postFragmentId)); } + postListPosition = getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, -1); isNsfwSubreddit = getIntent().getBooleanExtra(EXTRA_IS_NSFW_SUBREDDIT, false); fragmentManager = getSupportFragmentManager(); @@ -519,7 +520,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele bundle.putString(ViewPostDetailFragment.EXTRA_POST_ID, getIntent().getStringExtra(EXTRA_POST_ID)); } else { bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post); - bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, position); + bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, postListPosition); } bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID)); bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 5e64c959..95be0ca5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -90,7 +90,7 @@ import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData; import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; -import ml.docilealligator.infinityforreddit.events.PostUpdateEventToDetailActivity; +import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment; import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; @@ -2393,7 +2393,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter