From 5a5011f19e7c6fa75fe3ee9d19035af2a3ea12be Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 29 Jan 2022 11:11:36 +0800 Subject: [PATCH] New option: Settings->Interface->Comment->Show Fewer Toolbar Options Starting From. --- .../infinityforreddit/AppComponent.java | 3 +++ .../adapters/CommentsRecyclerViewAdapter.java | 7 ++--- .../settings/CommentPreferenceFragment.java | 27 +++++++++++++++++++ .../utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/comment_preferences.xml | 7 +++++ 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 1f758dfc..a3f45e59 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -82,6 +82,7 @@ import ml.docilealligator.infinityforreddit.services.EditProfileService; import ml.docilealligator.infinityforreddit.services.MaterialYouService; import ml.docilealligator.infinityforreddit.services.SubmitPostService; import ml.docilealligator.infinityforreddit.settings.AdvancedPreferenceFragment; +import ml.docilealligator.infinityforreddit.settings.CommentPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.CrashReportsFragment; import ml.docilealligator.infinityforreddit.settings.CustomizeBottomAppBarFragment; import ml.docilealligator.infinityforreddit.settings.CustomizeMainPageTabsFragment; @@ -292,4 +293,6 @@ public interface AppComponent { void inject(EditProfileActivity editProfileActivity); void inject(FontPreferenceFragment fontPreferenceFragment); + + void inject(CommentPreferenceFragment commentPreferenceFragment); } 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 1cd992ad..89d9c58d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -115,6 +115,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter depthThreshold) { + if (comment.getDepth() >= mDepthThreshold) { ((CommentViewHolder) holder).saveButton.setVisibility(View.GONE); ((CommentViewHolder) holder).replyButton.setVisibility(View.GONE); } else { @@ -1260,7 +1261,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter depthThreshold) { + if (comment.getDepth() >= mDepthThreshold) { bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_SHOW_REPLY_AND_SAVE_OPTION, true); } CommentMoreBottomSheetFragment commentMoreBottomSheetFragment = new CommentMoreBottomSheetFragment(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java index 336d7c62..2baef8f2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java @@ -1,18 +1,45 @@ package ml.docilealligator.infinityforreddit.settings; +import android.content.SharedPreferences; import android.os.Bundle; +import androidx.preference.Preference; +import androidx.preference.SeekBarPreference; + +import javax.inject.Inject; +import javax.inject.Named; + +import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class CommentPreferenceFragment extends CustomFontPreferenceFragmentCompat { + @Inject + @Named("default") + SharedPreferences sharedPreferences; + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.comment_preferences, rootKey); + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + if (activity.typeface != null) { setFont(activity.typeface); } + + SeekBarPreference showFewerToolbarOptionsThresholdSeekBarPreference = findPreference(SharedPreferencesUtils.SHOW_FEWER_TOOLBAR_OPTIONS_THRESHOLD); + + if (showFewerToolbarOptionsThresholdSeekBarPreference != null) { + showFewerToolbarOptionsThresholdSeekBarPreference.setSummary(getString(R.string.settings_show_fewer_toolbar_options_threshold_summary, sharedPreferences.getInt(SharedPreferencesUtils.SHOW_FEWER_TOOLBAR_OPTIONS_THRESHOLD, 5))); + + showFewerToolbarOptionsThresholdSeekBarPreference.setOnPreferenceChangeListener((Preference.OnPreferenceChangeListener) (preference, newValue) -> { + showFewerToolbarOptionsThresholdSeekBarPreference.setSummary( + getString(R.string.settings_show_fewer_toolbar_options_threshold_summary, (Integer) newValue)); + return true; + }); + } } } \ No newline at end of file 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 7291de2c..6b1a30af 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -203,6 +203,7 @@ public class SharedPreferencesUtils { public static final String FIXED_HEIGHT_PREVIEW_IN_CARD = "fixed_height_preview_in_card"; public static final String HIDE_TEXT_POST_CONTENT = "hide_text_post_content"; public static final String HIDE_COMMENT_AWARDS = "hide_comment_awards"; + public static final String SHOW_FEWER_TOOLBAR_OPTIONS_THRESHOLD = "show_fewer_toolbar_options_threshold"; 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 c1a9b8c7..167b02eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -627,6 +627,8 @@ Fixed Height in Card Hide Text Post Content Hide Comment Awards + Show Fewer Toolbar Options Starting From + Level %1$d 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 9455ec35..b7736545 100644 --- a/app/src/main/res/xml/comment_preferences.xml +++ b/app/src/main/res/xml/comment_preferences.xml @@ -37,4 +37,11 @@ app:key="hide_comment_awards" android:title="@string/settings_hide_comment_awards_title" /> + + \ No newline at end of file