From 9d242f973b3a69694b5ae35a6e3e2ba763203f01 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 13 Feb 2021 19:33:42 +0800 Subject: Fix getCurrentFragment() in ViewPostDetailActivity's ViewPager2's adapter. Fix newly-replied comments not shown in ViewPostDetailFragment. --- .../activities/ViewPostDetailActivity.java | 3 +- .../CommentAndPostRecyclerViewAdapter.java | 58 +++++++++++----------- 2 files changed, 30 insertions(+), 31 deletions(-) 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 b4efef1f..bda02b54 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -55,7 +55,6 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.NeedForPostListFromPostFragmentEvent; import ml.docilealligator.infinityforreddit.events.ProvidePostListToViewPostDetailActivityEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -454,7 +453,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele return null; } Fragment fragment = fragmentManager.findFragmentByTag("f" + viewPager2.getCurrentItem()); - if (fragment instanceof PostFragment) { + if (fragment instanceof ViewPostDetailFragment) { return (ViewPostDetailFragment) fragment; } return null; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index 11a9df06..d7116056 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -752,7 +752,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= 0) { + if (holder.getBindingAdapterPosition() >= 0) { mPost.setAuthorIconUrl(iconImageUrl); } } @@ -1041,9 +1041,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter 0) { @@ -1292,7 +1292,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { - int commentPosition = mIsSingleCommentThreadMode ? holder.getAdapterPosition() - 2 : holder.getAdapterPosition() - 1; + int commentPosition = mIsSingleCommentThreadMode ? holder.getBindingAdapterPosition() - 2 : holder.getBindingAdapterPosition() - 1; int parentPosition = getParentPosition(commentPosition); if (parentPosition >= 0) { Comment parentComment = mVisibleComments.get(parentPosition); @@ -1421,7 +1421,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= mVisibleComments.size() || commentPosition < 0 || !mVisibleComments.get(commentPosition).getFullName().equals(parentComment.getFullName())) { for (int i = parentPosition + 1; i < mVisibleComments.size(); i++) { @@ -2719,7 +2719,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { Comment comment = getCurrentComment(this); if (comment != null) { - int position = getAdapterPosition(); + int position = getBindingAdapterPosition(); if (comment.isSaved()) { comment.setSaved(false); SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() { @Override public void success() { comment.setSaved(false); - if (getAdapterPosition() == position) { + if (getBindingAdapterPosition() == position) { saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); } Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show(); @@ -3648,7 +3648,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { if (expandButton.getVisibility() == View.VISIBLE) { - int commentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1; + int commentPosition = mIsSingleCommentThreadMode ? getBindingAdapterPosition() - 2 : getBindingAdapterPosition() - 1; if (commentPosition >= 0 && commentPosition < mVisibleComments.size()) { Comment comment = getCurrentComment(this); if (comment != null) { @@ -3714,7 +3714,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= 0 && commentPosition < mVisibleComments.size()) { collapseChildren(commentPosition); } @@ -3780,7 +3780,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { - int commentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1; + int commentPosition = mIsSingleCommentThreadMode ? getBindingAdapterPosition() - 2 : getBindingAdapterPosition() - 1; if (commentPosition >= 0 && commentPosition < mVisibleComments.size()) { Comment comment = getCurrentComment(this); if (comment != null) { -- cgit v1.2.3