diff options
author | Alex Ning <chineseperson5@gmail.com> | 2022-01-17 09:30:56 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2022-01-17 09:30:56 +0000 |
commit | 5eaf4ab8fef1c50cfec708f2f15d3ee4fdd3df47 (patch) | |
tree | 6fb0735fe7327df91411967e02eae5c1485d5e59 /app | |
parent | 9ab1e6904c7b8a03449648eda3816a8c02d6e1fa (diff) | |
download | infinity-for-reddit-5eaf4ab8fef1c50cfec708f2f15d3ee4fdd3df47.tar infinity-for-reddit-5eaf4ab8fef1c50cfec708f2f15d3ee4fdd3df47.tar.gz infinity-for-reddit-5eaf4ab8fef1c50cfec708f2f15d3ee4fdd3df47.tar.bz2 infinity-for-reddit-5eaf4ab8fef1c50cfec708f2f15d3ee4fdd3df47.tar.lz infinity-for-reddit-5eaf4ab8fef1c50cfec708f2f15d3ee4fdd3df47.tar.xz infinity-for-reddit-5eaf4ab8fef1c50cfec708f2f15d3ee4fdd3df47.tar.zst infinity-for-reddit-5eaf4ab8fef1c50cfec708f2f15d3ee4fdd3df47.zip |
Show child reply count in comments.
Diffstat (limited to 'app')
8 files changed, 95 insertions, 11 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index 6ebce53e..33fd9075 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -374,7 +374,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment @BindView(R.id.save_button_item_post_comment) ImageView saveButton; @BindView(R.id.expand_button_item_post_comment) - ImageView expandButton; + TextView expandButton; @BindView(R.id.reply_button_item_post_comment) ImageView replyButton; @BindView(R.id.divider_item_comment) @@ -434,7 +434,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment scoreTextView.setTextColor(mCommentIconAndInfoColor); downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); moreButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); - expandButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); saveButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); commentDivider.setBackgroundColor(mDividerColor); 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 512140c1..89a60635 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -114,6 +114,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi private boolean isInitiallyLoadingFailed; private boolean mHasMoreComments; private boolean loadMoreCommentsFailed; + private Drawable expandDrawable; + private Drawable collapseDrawable; private int depthThreshold = 5; private int mColorPrimaryLightTheme; @@ -236,6 +238,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi mHasMoreComments = false; loadMoreCommentsFailed = false; + expandDrawable = Utils.getTintedDrawable(activity, R.drawable.ic_expand_more_grey_24dp, customThemeWrapper.getCommentIconAndInfoColor()); + collapseDrawable = Utils.getTintedDrawable(activity, R.drawable.ic_expand_less_grey_24dp, customThemeWrapper.getCommentIconAndInfoColor()); + mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); mColorAccent = customThemeWrapper.getColorAccent(); mCircularProgressBarBackgroundColor = customThemeWrapper.getCircularProgressBarBackground(); @@ -430,10 +435,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } if (comment.hasReply()) { + if (comment.getChildCount() > 0) { + ((CommentViewHolder) holder).expandButton.setText("+" + comment.getChildCount()); + } if (comment.isExpanded()) { - ((CommentViewHolder) holder).expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp); + ((CommentViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(collapseDrawable, null, null, null); } else { - ((CommentViewHolder) holder).expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp); + ((CommentViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(expandDrawable, null, null, null); } ((CommentViewHolder) holder).expandButton.setVisibility(View.VISIBLE); } @@ -486,6 +494,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi if (comment != null) { String authorWithPrefix = "u/" + comment.getAuthor(); ((CommentFullyCollapsedViewHolder) holder).usernameTextView.setText(authorWithPrefix); + if (comment.getChildCount() > 0) { + ((CommentFullyCollapsedViewHolder) holder).childCountTextView.setVisibility(View.VISIBLE); + ((CommentFullyCollapsedViewHolder) holder).childCountTextView.setText("+" + comment.getChildCount()); + } else { + ((CommentFullyCollapsedViewHolder) holder).childCountTextView.setVisibility(View.GONE); + } if (mShowElapsedTime) { ((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis())); } else { @@ -603,6 +617,11 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } mVisibleComments.get(parentPosition).addChildren(expandedComments); + if (mIsSingleCommentThreadMode) { + notifyItemChanged(parentPosition + 1); + } else { + notifyItemChanged(parentPosition); + } } else { for (int i = 0; i < mVisibleComments.size(); i++) { if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) { @@ -635,6 +654,11 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi mVisibleComments.get(i).getChildren().get(mVisibleComments.get(i).getChildren().size() - 1) .setLoadMoreChildrenFailed(false); mVisibleComments.get(i).addChildren(expandedComments); + if (mIsSingleCommentThreadMode) { + notifyItemChanged(i + 1); + } else { + notifyItemChanged(i); + } break; } @@ -846,8 +870,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } else { mVisibleComments.add(parentPosition + 1, comment); if (mIsSingleCommentThreadMode) { + notifyItemChanged(parentPosition + 1); notifyItemInserted(parentPosition + 2); } else { + notifyItemChanged(parentPosition); notifyItemInserted(parentPosition + 1); } } @@ -1017,6 +1043,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi ((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); ((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor); ((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); + ((CommentViewHolder) holder).expandButton.setText(""); ((CommentViewHolder) holder).replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); } } @@ -1076,7 +1103,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi @BindView(R.id.save_button_item_post_comment) ImageView saveButton; @BindView(R.id.expand_button_item_post_comment) - ImageView expandButton; + TextView expandButton; @BindView(R.id.reply_button_item_post_comment) ImageView replyButton; @BindView(R.id.vertical_block_indentation_item_comment) @@ -1125,6 +1152,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi topScoreTextView.setTypeface(mActivity.typeface); awardsTextView.setTypeface(mActivity.typeface); scoreTextView.setTypeface(mActivity.typeface); + expandButton.setTypeface(mActivity.typeface); } if (mActivity.contentTypeface != null) { commentMarkdownView.setTypeface(mActivity.contentTypeface); @@ -1141,7 +1169,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi scoreTextView.setTextColor(mCommentIconAndInfoColor); downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); moreButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); - expandButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); + expandButton.setTextColor(mCommentIconAndInfoColor); saveButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN); @@ -1426,7 +1454,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi if (comment != null) { if (mVisibleComments.get(commentPosition).isExpanded()) { collapseChildren(commentPosition); - expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp); + expandButton.setCompoundDrawablesWithIntrinsicBounds(expandDrawable, null, null, null); } else { comment.setExpanded(true); ArrayList<Comment> newList = new ArrayList<>(); @@ -1439,7 +1467,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } else { notifyItemRangeInserted(commentPosition + 1, newList.size()); } - expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp); + expandButton.setCompoundDrawablesWithIntrinsicBounds(collapseDrawable, null, null, null); } } } else if (mFullyCollapseComment) { @@ -1536,6 +1564,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi CommentIndentationView commentIndentationView; @BindView(R.id.user_name_text_view_item_comment_fully_collapsed) TextView usernameTextView; + @BindView(R.id.child_count_text_view_item_comment_fully_collapsed) + TextView childCountTextView; @BindView(R.id.score_text_view_item_comment_fully_collapsed) TextView scoreTextView; @BindView(R.id.time_text_view_item_comment_fully_collapsed) @@ -1549,11 +1579,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi if (mActivity.typeface != null) { usernameTextView.setTypeface(mActivity.typeface); + childCountTextView.setTypeface(mActivity.typeface); scoreTextView.setTypeface(mActivity.typeface); commentTimeTextView.setTypeface(mActivity.typeface); } itemView.setBackgroundColor(mFullyCollapsedCommentBackgroundColor); usernameTextView.setTextColor(mUsernameColor); + childCountTextView.setTextColor(mSecondaryTextColor); scoreTextView.setTextColor(mSecondaryTextColor); commentTimeTextView.setTextColor(mSecondaryTextColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 476651e8..a59f2dc1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -1046,6 +1046,13 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } } + public void addOneComment() { + if (mPost != null) { + mPost.setNComments(mPost.getNComments() + 1); + notifyItemChanged(0); + } + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof PostDetailBaseViewHolder) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java index 7cb0b695..0663cac7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java @@ -44,6 +44,7 @@ public class Comment implements Parcelable { private String permalink; private String awards; private int depth; + private int childCount; private boolean collapsed; private boolean hasReply; private boolean scoreHidden; @@ -130,6 +131,7 @@ public class Comment implements Parcelable { permalink = in.readString(); awards = in.readString(); depth = in.readInt(); + childCount = in.readInt(); collapsed = in.readByte() != 0; hasReply = in.readByte() != 0; scoreHidden = in.readByte() != 0; @@ -239,6 +241,14 @@ public class Comment implements Parcelable { return depth; } + public int getChildCount() { + return childCount; + } + + public void setChildCount(int childCount) { + this.childCount = childCount; + } + public boolean isCollapsed() { return collapsed; } @@ -304,10 +314,12 @@ public class Comment implements Parcelable { children.addAll(moreChildren); } } + childCount += moreChildren == null ? 0 : moreChildren.size(); } public void addChild(Comment comment) { addChild(comment, 0); + childCount++; } public void addChild(Comment comment, int position) { @@ -387,6 +399,7 @@ public class Comment implements Parcelable { parcel.writeString(permalink); parcel.writeString(awards); parcel.writeInt(depth); + parcel.writeInt(childCount); parcel.writeByte((byte) (collapsed ? 1 : 0)); parcel.writeByte((byte) (hasReply ? 1 : 0)); parcel.writeByte((byte) (scoreHidden ? 1 : 0)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java index 0244cc25..245c9e60 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java @@ -135,12 +135,24 @@ public class ParseComment { parseCommentRecursion(childrenArray, children, nextMoreChildrenFullnames, singleComment.getDepth()); singleComment.addChildren(children); singleComment.setMoreChildrenFullnames(nextMoreChildrenFullnames); + singleComment.setChildCount(getChildCount(singleComment)); } newCommentData.add(singleComment); } } + private static int getChildCount(Comment comment) { + if (comment.getChildren() == null) { + return 0; + } + int count = 0; + for (Comment c : comment.getChildren()) { + count += getChildCount(c); + } + return comment.getChildren().size() + count; + } + private static void expandChildren(ArrayList<Comment> comments, ArrayList<Comment> visibleComments, boolean setExpanded) { for (Comment c : comments) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index eabcb073..a7b4a15b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -703,12 +703,18 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic if (mCommentsAdapter != null) { mCommentsAdapter.addComment(comment); } + if (mPostAdapter != null) { + mPostAdapter.addOneComment(); + } } public void addChildComment(Comment comment, String parentFullname, int parentPosition) { if (mCommentsAdapter != null) { mCommentsAdapter.addChildComment(comment, parentFullname, parentPosition); } + if (mPostAdapter != null) { + mPostAdapter.addOneComment(); + } } public void editComment(String commentAuthor, String commentContentMarkdown, int position) { diff --git a/app/src/main/res/layout/item_comment.xml b/app/src/main/res/layout/item_comment.xml index e6d3f89d..e087c087 100644 --- a/app/src/main/res/layout/item_comment.xml +++ b/app/src/main/res/layout/item_comment.xml @@ -171,15 +171,18 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent"/> - <ImageView + <TextView android:id="@+id/expand_button_item_post_comment" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:padding="8dp" + android:gravity="center" + android:paddingStart="8dp" + android:paddingEnd="8dp" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" android:background="?actionBarItemBackground" android:clickable="true" android:focusable="true" - android:src="@drawable/ic_expand_less_grey_24dp" android:visibility="gone" app:layout_constraintEnd_toStartOf="@+id/save_button_item_post_comment" app:layout_constraintTop_toTopOf="parent" diff --git a/app/src/main/res/layout/item_comment_fully_collapsed.xml b/app/src/main/res/layout/item_comment_fully_collapsed.xml index b1023c7e..8f547138 100644 --- a/app/src/main/res/layout/item_comment_fully_collapsed.xml +++ b/app/src/main/res/layout/item_comment_fully_collapsed.xml @@ -22,6 +22,18 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" + android:maxLines="1" + android:fontFamily="?attr/font_family" + android:paddingStart="16dp" + android:paddingTop="12dp" + android:paddingEnd="8dp" + android:paddingBottom="12dp" + android:textSize="?attr/font_default" /> + + <TextView + android:id="@+id/child_count_text_view_item_comment_fully_collapsed" + android:layout_width="wrap_content" + android:layout_height="wrap_content" android:fontFamily="?attr/font_family" android:paddingStart="16dp" android:paddingTop="12dp" |