From 4f8b313b3c42084e66fcdc0e3aaaf870c97b5688 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 3 Jul 2020 10:27:24 +0800 Subject: Fully collapsing comments is now available (barebone). --- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 159 ++++++++++++++++++--- .../infinityforreddit/CommentData.java | 11 ++ .../Utils/SharedPreferencesUtils.java | 1 + .../layout/fragment_comment_more_bottom_sheet.xml | 1 + .../res/layout/item_comment_fully_collapsed.xml | 56 ++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/interface_preference.xml | 5 + 7 files changed, 216 insertions(+), 18 deletions(-) create mode 100644 app/src/main/res/layout/item_comment_fully_collapsed.xml (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index e1392761..cb3bc599 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -121,10 +121,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter 0) { + switch (comment.getDepth() % 7) { + case 0: + ((CommentFullyCollapsedViewHolder) holder).verticalBlock + .setBackgroundColor(mCommentVerticalBarColor7); + break; + case 1: + ((CommentFullyCollapsedViewHolder) holder).verticalBlock + .setBackgroundColor(mCommentVerticalBarColor1); + break; + case 2: + ((CommentFullyCollapsedViewHolder) holder).verticalBlock + .setBackgroundColor(mCommentVerticalBarColor2); + break; + case 3: + ((CommentFullyCollapsedViewHolder) holder).verticalBlock + .setBackgroundColor(mCommentVerticalBarColor3); + break; + case 4: + ((CommentFullyCollapsedViewHolder) holder).verticalBlock + .setBackgroundColor(mCommentVerticalBarColor4); + break; + case 5: + ((CommentFullyCollapsedViewHolder) holder).verticalBlock + .setBackgroundColor(mCommentVerticalBarColor5); + break; + case 6: + ((CommentFullyCollapsedViewHolder) holder).verticalBlock + .setBackgroundColor(mCommentVerticalBarColor6); + break; + } + ViewGroup.LayoutParams params = ((CommentFullyCollapsedViewHolder) holder).verticalBlock.getLayoutParams(); + params.width = 8; + ((CommentFullyCollapsedViewHolder) holder).verticalBlock.setLayoutParams(params); + } } else if (holder instanceof LoadMoreChildCommentsViewHolder) { CommentData placeholder; placeholder = mIsSingleCommentThreadMode ? mVisibleComments.get(holder.getAdapterPosition() - 2) @@ -1251,8 +1315,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter authorTextView.performClick()); moreButton.setOnClickListener(view -> { - CommentData comment = getCurrentComment(); + CommentData comment = getCurrentComment(this); Bundle bundle = new Bundle(); if (!mPost.isArchived() && !mPost.isLocked() && comment.getAuthor().equals(mAccountName)) { bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); @@ -2756,7 +2831,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { - CommentData comment = getCurrentComment(); + CommentData comment = getCurrentComment(this); if (comment.isSaved()) { comment.setSaved(false); SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() { @@ -2935,7 +3010,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, getCurrentComment().getAuthor()); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, getCurrentComment(this).getAuthor()); mActivity.startActivity(intent); }); @@ -2943,7 +3018,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= 0 && commentPosition < mVisibleComments.size()) { - CommentData comment = getCurrentComment(); + CommentData comment = getCurrentComment(this); if (mVisibleComments.get(commentPosition).isExpanded()) { collapseChildren(commentPosition); expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp); @@ -3005,16 +3080,64 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + int commentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1; + if (commentPosition >= 0 && commentPosition < mVisibleComments.size()) { + CommentData comment = getCurrentComment(this); + comment.setExpanded(true); + ArrayList newList = new ArrayList<>(); + expandChildren(mVisibleComments.get(commentPosition).getChildren(), newList, 0); + mVisibleComments.get(commentPosition).setExpanded(true); + mVisibleComments.addAll(commentPosition + 1, newList); + + if (mIsSingleCommentThreadMode) { + notifyItemChanged(commentPosition + 2); + notifyItemRangeInserted(commentPosition + 3, newList.size()); + } else { + notifyItemChanged(commentPosition + 1); + notifyItemRangeInserted(commentPosition + 2, newList.size()); + } + } + }); + + itemView.setOnLongClickListener(view -> { + itemView.performClick(); + return true; + }); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java index 531ad81e..0880e19a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java @@ -46,6 +46,7 @@ public class CommentData implements Parcelable { private boolean scoreHidden; private boolean saved; private boolean isExpanded; + private boolean hasExpandedBefore; private ArrayList children; private ArrayList moreChildrenFullnames; private int moreChildrenStartingIndex; @@ -84,6 +85,7 @@ public class CommentData implements Parcelable { this.scoreHidden = scoreHidden; this.saved = saved; this.isExpanded = false; + this.hasExpandedBefore = false; moreChildrenStartingIndex = 0; isPlaceHolder = false; } @@ -120,6 +122,7 @@ public class CommentData implements Parcelable { hasReply = in.readByte() != 0; scoreHidden = in.readByte() != 0; isExpanded = in.readByte() != 0; + hasExpandedBefore = in.readByte() != 0; children = in.readArrayList(CommentData.class.getClassLoader()); moreChildrenFullnames = in.readArrayList(CommentData.class.getClassLoader()); moreChildrenStartingIndex = in.readInt(); @@ -250,6 +253,13 @@ public class CommentData implements Parcelable { public void setExpanded(boolean isExpanded) { this.isExpanded = isExpanded; + if (isExpanded && !hasExpandedBefore) { + hasExpandedBefore = true; + } + } + + public boolean hasExpandedBefore() { + return hasExpandedBefore; } public int getVoteType() { @@ -365,6 +375,7 @@ public class CommentData implements Parcelable { parcel.writeByte((byte) (hasReply ? 1 : 0)); parcel.writeByte((byte) (scoreHidden ? 1 : 0)); parcel.writeByte((byte) (isExpanded ? 1 : 0)); + parcel.writeByte((byte) (hasExpandedBefore ? 1 : 0)); parcel.writeList(children); parcel.writeList(moreChildrenFullnames); parcel.writeInt(moreChildrenStartingIndex); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 03c64165..1b6d9df6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -99,6 +99,7 @@ public class SharedPreferencesUtils { public static final String LOCK_BOTTOM_APP_BAR = "lock_bottom_app_bar"; public static final String COMMENT_TOOLBAR_HIDDEN = "comment_toolbar_hidden"; public static final String COMMENT_TOOLBAR_HIDE_ON_CLICK = "comment_toolbar_hide_on_click"; + public static final String FULLY_COLLAPSE_COMMENT = "fully_collapse_comment"; public static final String SHOW_COMMENT_DIVIDER = "show_comment_divider"; public static final String SHOW_ABSOLUTE_NUMBER_OF_VOTES = "show_absolute_number_of_votes"; public static final String CUSTOMIZE_LIGHT_THEME = "customize_light_theme"; diff --git a/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml b/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml index c1126a2d..5d8c86d0 100644 --- a/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml +++ b/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml @@ -121,6 +121,7 @@ android:text="@string/see_removed_comment" android:textColor="?attr/primaryTextColor" android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" android:visibility="gone" /> diff --git a/app/src/main/res/layout/item_comment_fully_collapsed.xml b/app/src/main/res/layout/item_comment_fully_collapsed.xml new file mode 100644 index 00000000..f77b683c --- /dev/null +++ b/app/src/main/res/layout/item_comment_fully_collapsed.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8c874679..debafeff 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -352,6 +352,7 @@ Show Top-level Comments First Show Comment Divider Click to Show/Hide Comment Toolbar + Fully Collapse Comment Comment Toolbar Hidden by Default Show Absolute Number of Votes Show Elapsed Time in Posts and Comments diff --git a/app/src/main/res/xml/interface_preference.xml b/app/src/main/res/xml/interface_preference.xml index 900ee84d..84d60853 100644 --- a/app/src/main/res/xml/interface_preference.xml +++ b/app/src/main/res/xml/interface_preference.xml @@ -69,6 +69,11 @@ app:key="comment_toolbar_hide_on_click" app:title="@string/settings_comment_toolbar_hide_on_click" /> + +