Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show collapsed comment count when toolbar closed. #1319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,11 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
}

if (comment.hasReply()) {
if (comment.getChildCount() > 0 && (mAlwaysShowChildCommentCount || !comment.isExpanded())) {
((CommentViewHolder) holder).expandButton.setText("+" + comment.getChildCount());
if (comment.getChildCount() > 0) {
if (mAlwaysShowChildCommentCount || !comment.isExpanded()) {
((CommentViewHolder) holder).expandButton.setText("+" + comment.getChildCount());
}
((CommentViewHolder) holder).topChildCommentCount.setText("+" + comment.getChildCount());
}
if (comment.isExpanded()) {
((CommentViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(collapseDrawable, null, null, null);
Expand All @@ -482,6 +485,8 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
((CommentViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
}

((CommentViewHolder) holder).updateTopChildCommentCountVisibility();

switch (comment.getVoteType()) {
case Comment.VOTE_TYPE_UPVOTE:
((CommentViewHolder) holder).upvoteButton
Expand Down Expand Up @@ -1125,10 +1130,12 @@ public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
((CommentViewHolder) holder).awardsTextView.setText("");
((CommentViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).expandButton.setVisibility(View.GONE);
((CommentViewHolder) holder).topChildCommentCount.setVisibility(View.GONE);
((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).topChildCommentCount.setText("");
((CommentViewHolder) holder).replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -1177,6 +1184,8 @@ public class CommentViewHolder extends RecyclerView.ViewHolder {
TextView commentTimeTextView;
@BindView(R.id.top_score_text_view_item_post_comment)
TextView topScoreTextView;
@BindView(R.id.top_child_comment_count_text_view_item_post_comment)
TextView topChildCommentCount;
@BindView(R.id.awards_text_view_item_comment)
TextView awardsTextView;
@BindView(R.id.comment_markdown_view_item_post_comment)
Expand Down Expand Up @@ -1261,6 +1270,7 @@ public class CommentViewHolder extends RecyclerView.ViewHolder {
commentTimeTextView.setTypeface(mActivity.typeface);
authorFlairTextView.setTypeface(mActivity.typeface);
topScoreTextView.setTypeface(mActivity.typeface);
topChildCommentCount.setTypeface(mActivity.typeface);
awardsTextView.setTypeface(mActivity.typeface);
scoreTextView.setTypeface(mActivity.typeface);
expandButton.setTypeface(mActivity.typeface);
Expand Down Expand Up @@ -1294,6 +1304,7 @@ public void unlockSwipe() {
commentTimeTextView.setTextColor(mSecondaryTextColor);
authorFlairTextView.setTextColor(mAuthorFlairTextColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
topChildCommentCount.setTextColor(mSecondaryTextColor);
awardsTextView.setTextColor(mSecondaryTextColor);
commentDivider.setBackgroundColor(mDividerColor);
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
Expand Down Expand Up @@ -1619,6 +1630,7 @@ public void failed() {
}
expandButton.setCompoundDrawablesWithIntrinsicBounds(collapseDrawable, null, null, null);
}
updateTopChildCommentCountVisibility();
}
} else if (mFullyCollapseComment) {
int commentPosition = mIsSingleCommentThreadMode ? getBindingAdapterPosition() - 1 : getBindingAdapterPosition();
Expand All @@ -1630,13 +1642,13 @@ public void failed() {

if (mSwapTapAndLong) {
if (mCommentToolbarHideOnClick) {
View.OnLongClickListener hideToolbarOnLongClickListener = view -> hideToolbar();
View.OnLongClickListener hideToolbarOnLongClickListener = view -> toggleToolbarVisibility();
itemView.setOnLongClickListener(hideToolbarOnLongClickListener);
commentTimeTextView.setOnLongClickListener(hideToolbarOnLongClickListener);
mMarkwonAdapter.setOnLongClickListener(v -> {
if (v instanceof TextView) {
if (((TextView) v).getSelectionStart() == -1 && ((TextView) v).getSelectionEnd() == -1) {
hideToolbar();
toggleToolbarVisibility();
}
}
return true;
Expand All @@ -1661,9 +1673,9 @@ public void failed() {
return;
}
}
hideToolbar();
toggleToolbarVisibility();
});
View.OnClickListener hideToolbarOnClickListener = view -> hideToolbar();
View.OnClickListener hideToolbarOnClickListener = view -> toggleToolbarVisibility();
itemView.setOnClickListener(hideToolbarOnClickListener);
commentTimeTextView.setOnClickListener(hideToolbarOnClickListener);
}
Expand All @@ -1687,20 +1699,47 @@ private boolean expandComments() {
return true;
}

private boolean hideToolbar() {
if (bottomConstraintLayout.getLayoutParams().height == 0) {
bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
topScoreTextView.setVisibility(View.GONE);
mFragment.delayTransition();
} else {
private boolean toggleToolbarVisibility() {
if (toolbarVisible()) {
mFragment.delayTransition();
bottomConstraintLayout.getLayoutParams().height = 0;
if (!mHideTheNumberOfVotes) {
topScoreTextView.setVisibility(View.VISIBLE);
}
updateTopChildCommentCountVisibility();
} else {
bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
topScoreTextView.setVisibility(View.GONE);
updateTopChildCommentCountVisibility();
mFragment.delayTransition();
}
return true;
}

private boolean toolbarVisible() {
return bottomConstraintLayout.getLayoutParams().height != 0;
}

/**
* Updates the visibility of the top child comment count from the current state.
*/
private void updateTopChildCommentCountVisibility() {
topChildCommentCount.setVisibility(showTopChildCommentCount() ? View.VISIBLE : View.GONE);
}

/**
* Only show the top comment count when the toolbar is not visible
* and the comment is collapsed and has children.
*
* @return Whether the top child comment count should be shown.
*/
private boolean showTopChildCommentCount() {
Comment comment = getCurrentComment(this);
if (comment == null) {
return false;
}
return !toolbarVisible() && !comment.isExpanded() && comment.getChildCount() > 0;
}
}

@Nullable
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/item_comment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@
android:fontFamily="?attr/font_family"
android:gravity="end"
android:textSize="?attr/font_default"
app:autoSizeTextType="uniform"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/top_child_comment_count_text_view_item_post_comment"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/top_child_comment_count_text_view_item_post_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:fontFamily="?attr/font_family"
android:gravity="end"
android:textSize="?attr/font_default"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/comment_time_text_view_item_post_comment"
app:layout_constraintTop_toTopOf="parent" />
Expand Down