Fully collapsing comments with no children is available.

This commit is contained in:
Alex Ning 2020-09-13 23:06:56 +08:00
parent df1476692d
commit 4cf401756f
2 changed files with 12 additions and 4 deletions

View File

@ -567,7 +567,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
return VIEW_TYPE_POST_DETAIL_GALLERY; return VIEW_TYPE_POST_DETAIL_GALLERY;
default: default:
return VIEW_TYPE_POST_DETAIL_TEXT_TYPE; return VIEW_TYPE_POST_DETAIL_TEXT_TYPE;
} }
} }
@ -598,7 +597,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Comment comment = mVisibleComments.get(position - 2); Comment comment = mVisibleComments.get(position - 2);
if (!comment.isPlaceHolder()) { if (!comment.isPlaceHolder()) {
if (mFullyCollapseComment && comment.hasReply() && !comment.isExpanded() && comment.hasExpandedBefore()) { if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) {
return VIEW_TYPE_COMMENT_FULLY_COLLAPSED; return VIEW_TYPE_COMMENT_FULLY_COLLAPSED;
} }
return VIEW_TYPE_COMMENT; return VIEW_TYPE_COMMENT;
@ -616,7 +615,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Comment comment = mVisibleComments.get(position - 1); Comment comment = mVisibleComments.get(position - 1);
if (!comment.isPlaceHolder()) { if (!comment.isPlaceHolder()) {
if (mFullyCollapseComment && comment.hasReply() && !comment.isExpanded() && comment.hasExpandedBefore()) { if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) {
return VIEW_TYPE_COMMENT_FULLY_COLLAPSED; return VIEW_TYPE_COMMENT_FULLY_COLLAPSED;
} }
return VIEW_TYPE_COMMENT; return VIEW_TYPE_COMMENT;
@ -1552,7 +1551,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
} }
mVisibleComments.subList(position + 1, position + 1 + allChildrenSize).clear(); if (allChildrenSize > 0) {
mVisibleComments.subList(position + 1, position + 1 + allChildrenSize).clear();
}
if (mIsSingleCommentThreadMode) { if (mIsSingleCommentThreadMode) {
if (mFullyCollapseComment) { if (mFullyCollapseComment) {
notifyItemChanged(position + 2); notifyItemChanged(position + 2);
@ -3432,6 +3433,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp); expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp);
} }
} }
} else if (mFullyCollapseComment) {
int commentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1;
if (commentPosition >= 0 && commentPosition < mVisibleComments.size()) {
collapseChildren(commentPosition);
}
} }
}); });

View File

@ -102,6 +102,8 @@ public class ParseComment {
c.setExpanded(true); c.setExpanded(true);
} }
expandChildren(c.getChildren(), visibleComments, setExpanded); expandChildren(c.getChildren(), visibleComments, setExpanded);
} else {
c.setExpanded(true);
} }
if (c.hasMoreChildrenFullnames() && c.getMoreChildrenFullnames().size() > c.getMoreChildrenStartingIndex()) { if (c.hasMoreChildrenFullnames() && c.getMoreChildrenFullnames().size() > c.getMoreChildrenStartingIndex()) {
//Add a load more placeholder //Add a load more placeholder