From 07e2e1e746164eb39c20a1bacbb53bdfc3f8d2c8 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 24 Feb 2021 00:15:37 +0800 Subject: New options: hide post type and hide the number of awards. Tweak settings. --- .../adapters/PostRecyclerViewAdapter.java | 40 +++++++++++++++++---- .../events/ChangeHidePostTypeEvent.java | 9 +++++ .../events/ChangeHideTheNumberOfAwardsEvent.java | 9 +++++ .../infinityforreddit/fragments/PostFragment.java | 18 ++++++++++ .../settings/PostPreferenceFragment.java | 42 +++++++++++++++------- .../utils/SharedPreferencesUtils.java | 2 ++ .../infinityforreddit/utils/Utils.java | 27 ++------------ 7 files changed, 104 insertions(+), 43 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHidePostTypeEvent.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideTheNumberOfAwardsEvent.java (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 04b23880..87025e50 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -208,6 +208,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter 0) { + if (nAwards > 0 && !mHideTheNumberOfAwards) { ((PostBaseViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE); if (nAwards == 1) { ((PostBaseViewHolder) holder).awardsTextView.setText(mActivity.getString(R.string.one_award)); @@ -652,6 +657,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter 0) { + if (nAwards > 0 && !mHideTheNumberOfAwards) { ((PostCompactBaseViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE); if (nAwards == 1) { ((PostCompactBaseViewHolder) holder).awardsTextView.setText(mActivity.getString(R.string.one_award)); @@ -1138,6 +1149,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + if (defaultPostLayoutList != null) { + defaultPostLayoutList.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeDefaultPostLayoutEvent(Integer.parseInt((String) newValue))); return true; }); } - if (showDividerInCompactLayout != null) { - showDividerInCompactLayout.setOnPreferenceChangeListener((preference, newValue) -> { + if (showDividerInCompactLayoutSwitch != null) { + showDividerInCompactLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ShowDividerInCompactLayoutPreferenceEvent((Boolean) newValue)); return true; }); } - if (showThumbnailOnTheRightInCompactLayout != null) { - showThumbnailOnTheRightInCompactLayout.setOnPreferenceChangeListener((preference, newValue) -> { + if (showThumbnailOnTheRightInCompactLayoutSwitch != null) { + showThumbnailOnTheRightInCompactLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ShowThumbnailOnTheRightInCompactLayoutEvent((Boolean) newValue)); return true; }); } - if (showAbsoluteNumberOfVotes != null) { - showAbsoluteNumberOfVotes.setOnPreferenceChangeListener((preference, newValue) -> { + if (showAbsoluteNumberOfVotesSwitch != null) { + showAbsoluteNumberOfVotesSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeShowAbsoluteNumberOfVotesEvent((Boolean) newValue)); return true; }); @@ -71,5 +75,19 @@ public class PostPreferenceFragment extends PreferenceFragmentCompat { return true; }); } + + if (hidePostTypeSwitch != null) { + hidePostTypeSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeHidePostTypeEvent((Boolean) newValue)); + return true; + }); + } + + if (hideTheNumberOfAwardsSwitch != null) { + hideTheNumberOfAwardsSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeHideTheNumberOfAwardsEvent((Boolean) 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 86c562fc..965f8145 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -163,6 +163,8 @@ public class SharedPreferencesUtils { public static final String USER_DEFAULT_SORT_TYPE = "user_default_sort_type"; public static final String USER_DEFAULT_SORT_TIME = "user_default_sort_time"; public static final String CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT = "click_to_show_media_in_gallery_layout"; + public static final String HIDE_POST_TYPE = "hide_post_type"; + public static final String HIDE_THE_NUMBER_OF_AWARDS = "hide_the_number_of_awards"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index a43b0ffc..de048168 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -15,6 +15,7 @@ import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.text.HtmlCompat; @@ -49,30 +50,6 @@ public class Utils { .replaceAll("(^|^ *|\\n *)######(?!($|\\s|#))", "$0 ")); return fixSuperScript(regexed); - //Fix superscript - /*int startIndex = regexed.indexOf("^"); - while (startIndex >= 0 && startIndex + 1 < regexed.length()) { - char currentChar = regexed.charAt(startIndex + 1); - if (currentChar == '^') { - regexed.insert(startIndex, '^'); - startIndex = regexed.indexOf("^", startIndex + 1); - } else if (currentChar == ' ' || currentChar == '\n') { - regexed.insert(startIndex + 1, '^'); - startIndex = regexed.indexOf("^", startIndex + 2); - } else if (currentChar == '(') { - int closeBracketIndex = regexed.indexOf(")", startIndex + 2); - if (closeBracketIndex > 0) { - - } - } else { - if (startIndex + 1 == regexed.length() - 1) { - regexed.append('^'); - startIndex++; - } - startIndex++; - } - } - return regexed.toString();*/ } public static String fixSuperScript(StringBuilder regexed) { @@ -309,7 +286,7 @@ public class Utils { @Nullable public static Drawable getTintedDrawable(Context context, int drawableId, int color) { - Drawable drawable = context.getDrawable(drawableId); + Drawable drawable = ContextCompat.getDrawable(context, drawableId); if (drawable != null) { Drawable wrappedDrawable = DrawableCompat.wrap(drawable).mutate(); DrawableCompat.setTint(wrappedDrawable, color); -- cgit v1.2.3