diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-02-23 16:15:37 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-02-23 16:15:37 +0000 |
commit | 07e2e1e746164eb39c20a1bacbb53bdfc3f8d2c8 (patch) | |
tree | b10b88fb362bfcad2f235cab77c201b32b265a3c /app/src/main/java | |
parent | 73ddafdfccc3f6bb69df13b06a2b7b68e9f6dce8 (diff) | |
download | infinity-for-reddit-07e2e1e746164eb39c20a1bacbb53bdfc3f8d2c8.tar infinity-for-reddit-07e2e1e746164eb39c20a1bacbb53bdfc3f8d2c8.tar.gz infinity-for-reddit-07e2e1e746164eb39c20a1bacbb53bdfc3f8d2c8.tar.bz2 infinity-for-reddit-07e2e1e746164eb39c20a1bacbb53bdfc3f8d2c8.tar.lz infinity-for-reddit-07e2e1e746164eb39c20a1bacbb53bdfc3f8d2c8.tar.xz infinity-for-reddit-07e2e1e746164eb39c20a1bacbb53bdfc3f8d2c8.tar.zst infinity-for-reddit-07e2e1e746164eb39c20a1bacbb53bdfc3f8d2c8.zip |
New options: hide post type and hide the number of awards. Tweak settings.
Diffstat (limited to 'app/src/main/java')
7 files changed, 104 insertions, 43 deletions
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<Post, RecyclerView private boolean mMarkPostsAsReadAfterVoting; private boolean mMarkPostsAsReadOnScroll; private boolean mHideReadPostsAutomatically; + private boolean mHidePostType; + private boolean mHideTheNumberOfAwards; private Drawable mCommentIcon; private NetworkState networkState; private ExoCreator mExoCreator; @@ -279,6 +281,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mMarkPostsAsReadOnScroll = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false); mHideReadPostsAutomatically = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false); + mHidePostType = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false); + mHideTheNumberOfAwards = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false); + mPostLayout = postLayout; mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); @@ -604,7 +609,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView Utils.setHTMLWithImageToTextView(((PostBaseViewHolder) holder).flairTextView, flair, false); } - if (nAwards > 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<Post, RecyclerView ((PostBaseViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); } + if (mHidePostType) { + ((PostBaseViewHolder) holder).typeTextView.setVisibility(View.GONE); + } else { + ((PostBaseViewHolder) holder).typeTextView.setVisibility(View.VISIBLE); + } + if (holder instanceof PostVideoAutoplayViewHolder) { ((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE); Post.Preview preview = getSuitablePreview(post.getPreviews()); @@ -1082,7 +1093,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView Utils.setHTMLWithImageToTextView(((PostCompactBaseViewHolder) holder).flairTextView, flair, false); } - if (nAwards > 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<Post, RecyclerView ((PostCompactBaseViewHolder) holder).crosspostImageView.setVisibility(View.VISIBLE); } + if (mHidePostType) { + ((PostCompactBaseViewHolder) holder).typeTextView.setVisibility(View.GONE); + } else { + ((PostCompactBaseViewHolder) holder).typeTextView.setVisibility(View.VISIBLE); + } + switch (post.getPostType()) { case Post.IMAGE_TYPE: ((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.image); @@ -1740,6 +1757,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mOnlyDisablePreviewInVideoAndGifPosts = onlyDisablePreviewInVideoAndGifPosts; } + public void setHidePostType(boolean hidePostType) { + mHidePostType = hidePostType; + } + + public void setHideTheNumberOfAwards(boolean hideTheNumberOfAwards) { + mHideTheNumberOfAwards = hideTheNumberOfAwards; + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); @@ -1754,11 +1779,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostBaseViewHolder) holder).itemView.setVisibility(View.VISIBLE); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams(); params.height = ViewGroup.LayoutParams.WRAP_CONTENT; - int marginPixel = (int) Utils.convertDpToPixel(8, mActivity); - if (holder instanceof PostCard2VideoAutoplayViewHolder || holder instanceof PostCard2WithPreviewViewHolder - || holder instanceof PostCard2TextTypeViewHolder) { - ((PostBaseViewHolder) holder).itemView.setPadding(0, marginPixel, 0, 0); + if (holder instanceof PostCard2VideoAutoplayViewHolder || holder instanceof PostCard2WithPreviewViewHolder) { + int paddingPixel = (int) Utils.convertDpToPixel(16, mActivity); + ((PostBaseViewHolder) holder).itemView.setPadding(0, paddingPixel, 0, 0); + } else if (holder instanceof PostCard2TextTypeViewHolder) { + int paddingPixel = (int) Utils.convertDpToPixel(12, mActivity); + ((PostBaseViewHolder) holder).itemView.setPadding(0, paddingPixel, 0, 0); } else { + int marginPixel = (int) Utils.convertDpToPixel(8, mActivity); params.topMargin = marginPixel; params.bottomMargin = marginPixel; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHidePostTypeEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHidePostTypeEvent.java new file mode 100644 index 00000000..da9a07be --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHidePostTypeEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.events; + +public class ChangeHidePostTypeEvent { + public boolean hidePostType; + + public ChangeHidePostTypeEvent(boolean hidePostType) { + this.hidePostType = hidePostType; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideTheNumberOfAwardsEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideTheNumberOfAwardsEvent.java new file mode 100644 index 00000000..ef9330af --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideTheNumberOfAwardsEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.events; + +public class ChangeHideTheNumberOfAwardsEvent { + public boolean hideTheNumberOfAwards; + + public ChangeHideTheNumberOfAwardsEvent(boolean hideTheNumberOfAwards) { + this.hideTheNumberOfAwards = hideTheNumberOfAwards; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index dc0fa55f..7841efc2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -84,6 +84,8 @@ import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent; import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeDisableImagePreviewEvent; import ml.docilealligator.infinityforreddit.events.ChangeEnableSwipeActionSwitchEvent; +import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent; +import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent; import ml.docilealligator.infinityforreddit.events.ChangeLongPressToHideToolbarInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeMuteAutoplayingVideosEvent; import ml.docilealligator.infinityforreddit.events.ChangeMuteNSFWVideoEvent; @@ -1639,6 +1641,22 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + @Subscribe + public void onChangeHidePostTypeEvent(ChangeHidePostTypeEvent event) { + if (mAdapter != null) { + mAdapter.setHidePostType(event.hidePostType); + refreshAdapter(); + } + } + + @Subscribe + public void onChangeHideTheNumberOfAwardsEvent(ChangeHideTheNumberOfAwardsEvent event) { + if (mAdapter != null) { + mAdapter.setHideTheNumberOfAwards(event.hideTheNumberOfAwards); + refreshAdapter(); + } + } + private void refreshAdapter() { int previousPosition = -1; if (mLinearLayoutManager != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java index 08011d3a..f04c205a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java @@ -11,6 +11,8 @@ import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.events.ChangeCompactLayoutToolbarHiddenByDefaultEvent; import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent; +import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent; +import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent; import ml.docilealligator.infinityforreddit.events.ChangeLongPressToHideToolbarInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeShowAbsoluteNumberOfVotesEvent; import ml.docilealligator.infinityforreddit.events.ShowDividerInCompactLayoutPreferenceEvent; @@ -23,36 +25,38 @@ public class PostPreferenceFragment extends PreferenceFragmentCompat { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.post_preferences, rootKey); - ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); - SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); - SwitchPreference showThumbnailOnTheRightInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_LEFT_IN_COMPACT_LAYOUT); - SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES); + ListPreference defaultPostLayoutList = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); + SwitchPreference showDividerInCompactLayoutSwitch = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); + SwitchPreference showThumbnailOnTheRightInCompactLayoutSwitch = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_LEFT_IN_COMPACT_LAYOUT); + SwitchPreference showAbsoluteNumberOfVotesSwitch = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES); SwitchPreference longPressToHideToolbarInCompactLayoutSwitch = findPreference(SharedPreferencesUtils.LONG_PRESS_TO_HIDE_TOOLBAR_IN_COMPACT_LAYOUT); SwitchPreference postCompactLayoutToolbarHiddenByDefaultSwitch = findPreference(SharedPreferencesUtils.POST_COMPACT_LAYOUT_TOOLBAR_HIDDEN_BY_DEFAULT); + SwitchPreference hidePostTypeSwitch = findPreference(SharedPreferencesUtils.HIDE_POST_TYPE); + SwitchPreference hideTheNumberOfAwardsSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS); - if (defaultPostLayoutSwitch != null) { - defaultPostLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + 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); |