diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-02-13 11:33:42 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-02-13 11:33:42 +0000 |
commit | 9d242f973b3a69694b5ae35a6e3e2ba763203f01 (patch) | |
tree | d713386d0348d4a7801708ff72bd7b4ae0b50bea /app/src | |
parent | b2aff0c04738135a01838493655832578c5f24c4 (diff) | |
download | infinity-for-reddit-9d242f973b3a69694b5ae35a6e3e2ba763203f01.tar infinity-for-reddit-9d242f973b3a69694b5ae35a6e3e2ba763203f01.tar.gz infinity-for-reddit-9d242f973b3a69694b5ae35a6e3e2ba763203f01.tar.bz2 infinity-for-reddit-9d242f973b3a69694b5ae35a6e3e2ba763203f01.tar.lz infinity-for-reddit-9d242f973b3a69694b5ae35a6e3e2ba763203f01.tar.xz infinity-for-reddit-9d242f973b3a69694b5ae35a6e3e2ba763203f01.tar.zst infinity-for-reddit-9d242f973b3a69694b5ae35a6e3e2ba763203f01.zip |
Fix getCurrentFragment() in ViewPostDetailActivity's ViewPager2's adapter. Fix newly-replied comments not shown in ViewPostDetailFragment.
Diffstat (limited to 'app/src')
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<Recy .into(((PostDetailBaseViewHolder) holder).mIconGifImageView); } - if (holder.getAdapterPosition() >= 0) { + if (holder.getBindingAdapterPosition() >= 0) { mPost.setAuthorIconUrl(iconImageUrl); } } @@ -1041,9 +1041,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } else if (holder instanceof CommentViewHolder) { Comment comment; if (mIsSingleCommentThreadMode) { - comment = mVisibleComments.get(holder.getAdapterPosition() - 2); + comment = mVisibleComments.get(holder.getBindingAdapterPosition() - 2); } else { - comment = mVisibleComments.get(holder.getAdapterPosition() - 1); + comment = mVisibleComments.get(holder.getBindingAdapterPosition() - 1); } if (mIsSingleCommentThreadMode && comment.getId().equals(mSingleCommentId)) { @@ -1189,9 +1189,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } else if (holder instanceof CommentFullyCollapsedViewHolder) { Comment comment; if (mIsSingleCommentThreadMode) { - comment = mVisibleComments.get(holder.getAdapterPosition() - 2); + comment = mVisibleComments.get(holder.getBindingAdapterPosition() - 2); } else { - comment = mVisibleComments.get(holder.getAdapterPosition() - 1); + comment = mVisibleComments.get(holder.getBindingAdapterPosition() - 1); } String authorWithPrefix = "u/" + comment.getAuthor(); @@ -1242,8 +1242,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } } else if (holder instanceof LoadMoreChildCommentsViewHolder) { Comment placeholder; - placeholder = mIsSingleCommentThreadMode ? mVisibleComments.get(holder.getAdapterPosition() - 2) - : mVisibleComments.get(holder.getAdapterPosition() - 1); + placeholder = mIsSingleCommentThreadMode ? mVisibleComments.get(holder.getBindingAdapterPosition() - 2) + : mVisibleComments.get(holder.getBindingAdapterPosition() - 1); ((LoadMoreChildCommentsViewHolder) holder).itemView.setPadding(placeholder.getDepth() * 8, 0, 0, 0); if (placeholder.getDepth() > 0) { @@ -1292,7 +1292,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } ((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setOnClickListener(view -> { - 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<Recy if (parentPosition < mVisibleComments.size() && parentComment.getFullName().equals(mVisibleComments.get(parentPosition).getFullName())) { if (mVisibleComments.get(parentPosition).isExpanded()) { - int commentPosition = mIsSingleCommentThreadMode ? holder.getAdapterPosition() - 2 : holder.getAdapterPosition() - 1; + int commentPosition = mIsSingleCommentThreadMode ? holder.getBindingAdapterPosition() - 2 : holder.getBindingAdapterPosition() - 1; int placeholderPosition = commentPosition; if (commentPosition >= 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<Recy @Override public int getPlayerOrder() { - return getAdapterPosition(); + return getBindingAdapterPosition(); } } @@ -3430,9 +3430,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); bundle.putParcelable(CommentMoreBottomSheetFragment.EXTRA_COMMENT, comment); if (mIsSingleCommentThreadMode) { - bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getAdapterPosition() - 2); + bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getBindingAdapterPosition() - 2); } else { - bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getAdapterPosition() - 1); + bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getBindingAdapterPosition() - 1); } bundle.putString(CommentMoreBottomSheetFragment.EXTRA_COMMENT_MARKDOWN, comment.getCommentMarkdown()); bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_IS_NSFW, mPost.isNSFW()); @@ -3467,9 +3467,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, comment.getFullName()); intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, true); - int parentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1; + int parentPosition = mIsSingleCommentThreadMode ? getBindingAdapterPosition() - 2 : getBindingAdapterPosition() - 1; intent.putExtra(CommentActivity.EXTRA_PARENT_POSITION_KEY, parentPosition); - mActivity.startActivityForResult(intent, CommentActivity.WRITE_COMMENT_REQUEST_CODE); + mFragment.startActivityForResult(intent, CommentActivity.WRITE_COMMENT_REQUEST_CODE); } }); @@ -3513,11 +3513,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy Utils.getNVotes(mShowAbsoluteNumberOfVotes, comment.getScore() + comment.getVoteType()))); - int position = getAdapterPosition(); + int position = getBindingAdapterPosition(); VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { @Override public void onVoteThingSuccess(int position) { - int currentPosition = getAdapterPosition(); + int currentPosition = getBindingAdapterPosition(); if (newVoteType.equals(APIUtils.DIR_UPVOTE)) { comment.setVoteType(Comment.VOTE_TYPE_UPVOTE); if (currentPosition == position) { @@ -3547,7 +3547,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy @Override public void onVoteThingFail(int position) { } - }, comment.getFullName(), newVoteType, getAdapterPosition()); + }, comment.getFullName(), newVoteType, getBindingAdapterPosition()); } }); @@ -3591,11 +3591,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy Utils.getNVotes(mShowAbsoluteNumberOfVotes, comment.getScore() + comment.getVoteType()))); - int position = getAdapterPosition(); + int position = getBindingAdapterPosition(); VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { @Override public void onVoteThingSuccess(int position1) { - int currentPosition = getAdapterPosition(); + int currentPosition = getBindingAdapterPosition(); if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) { comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE); if (currentPosition == position) { @@ -3625,21 +3625,21 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy @Override public void onVoteThingFail(int position1) { } - }, comment.getFullName(), newVoteType, getAdapterPosition()); + }, comment.getFullName(), newVoteType, getBindingAdapterPosition()); } }); saveButton.setOnClickListener(view -> { 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<Recy @Override public void failed() { comment.setSaved(true); - if (getAdapterPosition() == position) { + if (getBindingAdapterPosition() == position) { saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); } Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show(); @@ -3660,7 +3660,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy @Override public void success() { comment.setSaved(true); - if (getAdapterPosition() == position) { + if (getBindingAdapterPosition() == position) { saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); } Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show(); @@ -3669,7 +3669,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy @Override public void failed() { comment.setSaved(false); - if (getAdapterPosition() == position) { + if (getBindingAdapterPosition() == position) { saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); } Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show(); @@ -3690,7 +3690,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy expandButton.setOnClickListener(view -> { 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<Recy } } } else if (mFullyCollapseComment) { - int commentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1; + int commentPosition = mIsSingleCommentThreadMode ? getBindingAdapterPosition() - 2 : getBindingAdapterPosition() - 1; if (commentPosition >= 0 && commentPosition < mVisibleComments.size()) { collapseChildren(commentPosition); } @@ -3780,7 +3780,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy @Nullable private Comment getCurrentComment(RecyclerView.ViewHolder holder) { - return getCurrentComment(holder.getAdapterPosition()); + return getCurrentComment(holder.getBindingAdapterPosition()); } @Nullable @@ -3825,7 +3825,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } itemView.setOnClickListener(view -> { - 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) { |