diff options
author | Sergei Kozelko <KozelkoS@yandex.ru> | 2022-10-16 09:06:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-16 09:06:10 +0000 |
commit | d11fb884c26c739e9e919ec98c1a0990f0953c93 (patch) | |
tree | a001dbe8425fd828d5bfe8c0b9a5e2aff3d7a788 /app/src/main/java/ml/docilealligator | |
parent | 297c20f5d34a49816fc2e954c156d0d3c49f19c9 (diff) | |
download | infinity-for-reddit-d11fb884c26c739e9e919ec98c1a0990f0953c93.tar infinity-for-reddit-d11fb884c26c739e9e919ec98c1a0990f0953c93.tar.gz infinity-for-reddit-d11fb884c26c739e9e919ec98c1a0990f0953c93.tar.bz2 infinity-for-reddit-d11fb884c26c739e9e919ec98c1a0990f0953c93.tar.lz infinity-for-reddit-d11fb884c26c739e9e919ec98c1a0990f0953c93.tar.xz infinity-for-reddit-d11fb884c26c739e9e919ec98c1a0990f0953c93.tar.zst infinity-for-reddit-d11fb884c26c739e9e919ec98c1a0990f0953c93.zip |
Fix comment expanding logic (#1155)
Child comment expanding was broken because it did not take into account children
of children of children and deeper levels of comments when calculating new
comment's position.
Replaced with a simple tree to list conversion in pre-order.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java | 20 |
1 files changed, 8 insertions, 12 deletions
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 aee4be21..feaedc98 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -802,16 +802,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi return -1; } - private void expandChildren(ArrayList<Comment> comments, ArrayList<Comment> newList, int position) { + private void expandChildren(ArrayList<Comment> comments, ArrayList<Comment> newList) { if (comments != null && comments.size() > 0) { - newList.addAll(position, comments); - for (int i = 0; i < comments.size(); i++) { - position++; - if (comments.get(i).getChildren() != null && comments.get(i).getChildren().size() > 0) { - expandChildren(comments.get(i).getChildren(), newList, position); - position = position + comments.get(i).getChildren().size(); - } - comments.get(i).setExpanded(true); + for (Comment comment : comments) { + newList.add(comment); + expandChildren(comment.getChildren(), newList); + comment.setExpanded(true); } } } @@ -909,7 +905,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi mVisibleComments.get(parentPosition).setHasReply(true); if (!mVisibleComments.get(parentPosition).isExpanded()) { ArrayList<Comment> newList = new ArrayList<>(); - expandChildren(mVisibleComments.get(parentPosition).getChildren(), newList, 0); + expandChildren(mVisibleComments.get(parentPosition).getChildren(), newList); mVisibleComments.get(parentPosition).setExpanded(true); mVisibleComments.addAll(parentPosition + 1, newList); if (mIsSingleCommentThreadMode) { @@ -1572,7 +1568,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } else { comment.setExpanded(true); ArrayList<Comment> newList = new ArrayList<>(); - expandChildren(mVisibleComments.get(commentPosition).getChildren(), newList, 0); + expandChildren(mVisibleComments.get(commentPosition).getChildren(), newList); mVisibleComments.get(commentPosition).setExpanded(true); mVisibleComments.addAll(commentPosition + 1, newList); @@ -1740,7 +1736,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi if (comment != null) { comment.setExpanded(true); ArrayList<Comment> newList = new ArrayList<>(); - expandChildren(mVisibleComments.get(commentPosition).getChildren(), newList, 0); + expandChildren(mVisibleComments.get(commentPosition).getChildren(), newList); mVisibleComments.get(commentPosition).setExpanded(true); mVisibleComments.addAll(commentPosition + 1, newList); |