From d5c65ff492a9ad2b74df58837b389990c18cea3d Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 27 Jun 2021 22:01:06 +0800 Subject: Fix not showing all comments in single comment thread mode in CommentsRecyclerViewAdapter. --- .../adapters/CommentsRecyclerViewAdapter.java | 45 ++++++++++++---------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 4f70b5fb..2d7b3b1f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -13,6 +13,7 @@ import android.text.Spanned; import android.text.TextPaint; import android.text.style.ClickableSpan; import android.text.util.Linkify; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -773,6 +774,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { if (expandButton.getVisibility() == View.VISIBLE) { int commentPosition = mIsSingleCommentThreadMode ? getBindingAdapterPosition() - 1 : getBindingAdapterPosition(); - if (commentPosition >= 0 && commentPosition < mVisibleComments.size()) { - Comment comment = getCurrentComment(this); - if (comment != null) { - if (mVisibleComments.get(commentPosition).isExpanded()) { - collapseChildren(commentPosition); - expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp); + Comment comment = getCurrentComment(this); + if (comment != null) { + if (mVisibleComments.get(commentPosition).isExpanded()) { + collapseChildren(commentPosition); + Log.i("asdfasdf", "ssf"); + expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp); + } else { + comment.setExpanded(true); + ArrayList newList = new ArrayList<>(); + expandChildren(mVisibleComments.get(commentPosition).getChildren(), newList, 0); + mVisibleComments.get(commentPosition).setExpanded(true); + mVisibleComments.addAll(commentPosition + 1, newList); + + if (mIsSingleCommentThreadMode) { + notifyItemRangeInserted(commentPosition + 2, newList.size()); } else { - comment.setExpanded(true); - ArrayList newList = new ArrayList<>(); - expandChildren(mVisibleComments.get(commentPosition).getChildren(), newList, 0); - mVisibleComments.get(commentPosition).setExpanded(true); - mVisibleComments.addAll(commentPosition + 1, newList); - - if (mIsSingleCommentThreadMode) { - notifyItemRangeInserted(commentPosition + 2, newList.size()); - } else { - notifyItemRangeInserted(commentPosition + 1, newList.size()); - } - expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp); + notifyItemRangeInserted(commentPosition + 1, newList.size()); } + expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp); } } } else if (mFullyCollapseComment) { -- cgit v1.2.3