From 6092b92d41ec38e000ba30f8706b0161702378df Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:07:48 -0400 Subject: [PATCH] Fix issues in fully expanding comments in CommentsRecyclerViewAdapterNew. --- .../CommentsRecyclerViewAdapterNew.java | 45 +++++++++++++++++ .../ViewPostDetailFragmentViewModelNew.kt | 49 ++++++++++--------- 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapterNew.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapterNew.java index dac8bb78..44620a25 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapterNew.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapterNew.java @@ -8,6 +8,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.text.Spanned; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -675,6 +676,50 @@ public class CommentsRecyclerViewAdapterNew extends ListAdapter 420) { + if (((CommentFullyCollapsedViewHolder) holder).saveButton != null) { + ((CommentFullyCollapsedViewHolder) holder).saveButton.setVisibility(View.VISIBLE); + } + if (((CommentFullyCollapsedViewHolder) holder).replyButton != null) { + ((CommentFullyCollapsedViewHolder) holder).replyButton.setVisibility(View.VISIBLE); + } + if (((CommentFullyCollapsedViewHolder) holder).expandButton != null) { + ((CommentFullyCollapsedViewHolder) holder).expandButton.setVisibility(View.VISIBLE); + } + } else if (bottomToolbarWidth > 350) { + if (((CommentFullyCollapsedViewHolder) holder).saveButton != null) { + ((CommentFullyCollapsedViewHolder) holder).saveButton.setVisibility(View.VISIBLE); + } + if (((CommentFullyCollapsedViewHolder) holder).replyButton != null) { + ((CommentFullyCollapsedViewHolder) holder).replyButton.setVisibility(View.GONE); + } + if (((CommentFullyCollapsedViewHolder) holder).expandButton != null) { + ((CommentFullyCollapsedViewHolder) holder).expandButton.setVisibility(View.VISIBLE); + } + } else if (bottomToolbarWidth > 300) { + if (((CommentFullyCollapsedViewHolder) holder).saveButton != null) { + ((CommentFullyCollapsedViewHolder) holder).saveButton.setVisibility(View.GONE); + } + if (((CommentFullyCollapsedViewHolder) holder).replyButton != null) { + ((CommentFullyCollapsedViewHolder) holder).replyButton.setVisibility(View.GONE); + } + if (((CommentFullyCollapsedViewHolder) holder).expandButton != null) { + ((CommentFullyCollapsedViewHolder) holder).expandButton.setVisibility(View.VISIBLE); + } + } else { + if (((CommentFullyCollapsedViewHolder) holder).saveButton != null) { + ((CommentFullyCollapsedViewHolder) holder).saveButton.setVisibility(View.GONE); + } + if (((CommentFullyCollapsedViewHolder) holder).replyButton != null) { + ((CommentFullyCollapsedViewHolder) holder).replyButton.setVisibility(View.GONE); + } + if (((CommentFullyCollapsedViewHolder) holder).expandButton != null) { + ((CommentFullyCollapsedViewHolder) holder).expandButton.setVisibility(View.GONE); + } + }*/ } } else if (holder instanceof LoadMoreChildCommentsViewHolder) { Comment placeholder = getItem(position); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/viewmodels/ViewPostDetailFragmentViewModelNew.kt b/app/src/main/java/ml/docilealligator/infinityforreddit/viewmodels/ViewPostDetailFragmentViewModelNew.kt index 1675112c..a1cac237 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/viewmodels/ViewPostDetailFragmentViewModelNew.kt +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/viewmodels/ViewPostDetailFragmentViewModelNew.kt @@ -1081,23 +1081,23 @@ class ViewPostDetailFragmentViewModelNew( if (it.isExpanded) { return collapseComment(position) } else { - if (!it.children.isNullOrEmpty()) { - val newList = ArrayList() - expandComment(it.children, newList) + val updatedComment = Comment(it) + updatedComment.setExpanded(true) - val updatedComment = Comment(it) - updatedComment.setExpanded(true) + val newList = ArrayList() + expandComment(it.children, newList) - val updatedComments = ArrayList(comments) - updatedComments[position] = updatedComment + val updatedComments = ArrayList(comments) + updatedComments[position] = updatedComment + if (newList.isNotEmpty()) { updatedComments.addAll(position + 1, newList) - - _dataState.value = _dataState.value.copy( - comments = updatedComments - ) - - return true } + + _dataState.value = _dataState.value.copy( + comments = updatedComments + ) + + return newList.isNotEmpty() } } } @@ -1122,6 +1122,9 @@ class ViewPostDetailFragmentViewModelNew( _dataState.value.comments?.let { comments -> val comment = comments.getOrNull(position) comment?.let { + val updatedComment = Comment(it) + updatedComment.setExpanded(false) + val depth: Int = it.depth var allChildrenSize = 0 for (i in position + 1.. 0) { - val updatedComment = Comment(it) - updatedComment.setExpanded(false) - - val updatedComments = ArrayList(comments) - updatedComments[position] = updatedComment updatedComments.subList(position + 1, position + 1 + allChildrenSize).clear() - - _dataState.value = _dataState.value.copy( - comments = updatedComments - ) - - return true } + + _dataState.value = _dataState.value.copy( + comments = updatedComments + ) + + return allChildrenSize > 0 } }