From b21eb89271d5818721e56b8198ddcddcc9875a61 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 10 May 2021 12:00:51 +0800 Subject: [PATCH] New option: Show Only One Comment Level Indicator. --- .../CommentAndPostRecyclerViewAdapter.java | 6 ++++++ .../customviews/CommentIndentationView.java | 18 +++++++++++++++--- .../utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/comment_preferences.xml | 5 +++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index a3e8dbb4..ed4df937 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -186,6 +186,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter depthThreshold) { ((CommentViewHolder) holder).saveButton.setVisibility(View.GONE); @@ -1167,6 +1171,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter startXs; private final int spacing; private final int pathWidth; + private boolean showOnlyOneDivider = false; public CommentIndentationView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); @@ -49,9 +50,16 @@ public class CommentIndentationView extends LinearLayout { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - for (int i = 0; i < startXs.size(); i++) { - paint.setColor(colors[i % 7]); - canvas.drawLine(startXs.get(i), 0, startXs.get(i), getHeight(), paint); + if (showOnlyOneDivider) { + if (startXs.size() > 0) { + paint.setColor(colors[(startXs.size() - 1) % 7]); + canvas.drawLine(startXs.get(startXs.size() - 1), 0, startXs.get(startXs.size() - 1), getHeight(), paint); + } + } else { + for (int i = 0; i < startXs.size(); i++) { + paint.setColor(colors[i % 7]); + canvas.drawLine(startXs.get(i), 0, startXs.get(i), getHeight(), paint); + } } } @@ -89,6 +97,10 @@ public class CommentIndentationView extends LinearLayout { invalidate(); } + public void setShowOnlyOneDivider(boolean showOnlyOneDivider) { + this.showOnlyOneDivider = showOnlyOneDivider; + } + private static class SavedState extends BaseSavedState { ArrayList startXs; Integer[] colors; 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 dc585d93..1125d71a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -177,6 +177,7 @@ public class SharedPreferencesUtils { public static final String NUMBER_OF_COLUMNS_IN_POST_FEED_PORTRAIT_CARD_LAYOUT_2 = "number_of_columns_in_post_feed_portrait_card_layout_2"; public static final String NUMBER_OF_COLUMNS_IN_POST_FEED_LANDSCAPE_CARD_LAYOUT_2 = "number_of_columns_in_post_feed_landscape_card_layout_2"; public static final String DISABLE_NSFW_FOREVER = "disable_nsfw_forever"; + public static final String SHOW_ONLY_ONE_COMMENT_LEVEL_INDICATOR = "show_only_one_comment_level_indicator"; public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 492d8376..c3456e0e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -562,6 +562,7 @@ Crash Reports Dangerous Disable NSFW Forever + Show Only One Comment Level Indicator Cannot get the link diff --git a/app/src/main/res/xml/comment_preferences.xml b/app/src/main/res/xml/comment_preferences.xml index 2248d7f3..a9510dc5 100644 --- a/app/src/main/res/xml/comment_preferences.xml +++ b/app/src/main/res/xml/comment_preferences.xml @@ -12,6 +12,11 @@ app:key="show_comment_divider" app:title="@string/settings_show_comment_divider_title" /> + +