From 1c81d3e0c9375d9b7d28ea521b16415028057c60 Mon Sep 17 00:00:00 2001 From: Sergei Kozelko Date: Sun, 4 Dec 2022 05:05:28 +0800 Subject: Fix placeholder position check (#1216) * Fix placeholder position check Because of the missed negation `placeholderPosition` could actually point to a different comment. As a result loaded comments would be displayed at a wrong position which could result in duplicated comments. * Extract placeholder search code Simple refactoring. The only notable change is that now technically `placeholderPosition` can be -1. In practice that should never happen, but I added checks anyways --- .../adapters/CommentsRecyclerViewAdapter.java | 145 ++++++++++----------- 1 file changed, 67 insertions(+), 78 deletions(-) (limited to 'app/src/main') 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 a1fb48c4..1b534a0c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -645,53 +645,39 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter= mVisibleComments.size() || commentPosition < 0 || !mVisibleComments.get(commentPosition).getFullName().equals(parentComment.getFullName())) { - for (int i = parentPosition + 1; i < mVisibleComments.size(); i++) { - if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) { - placeholderPosition = i; - break; - } - } - } + int placeholderPosition = findLoadMoreCommentsPlaceholderPosition(parentComment.getFullName(), commentPosition); - if (placeholderPosition >= mVisibleComments.size() || placeholderPosition < 0) { + if (placeholderPosition != -1) { mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false); mVisibleComments.get(placeholderPosition).setLoadMoreChildrenFailed(true); } @@ -783,18 +755,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter comments, ArrayList newList) { if (comments != null && comments.size() > 0) { for (Comment comment : comments) { -- cgit v1.2.3