diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-07-20 12:13:11 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-07-20 12:13:11 +0000 |
commit | 568aa7a78f37f7dd4c4c027e9701467887da799f (patch) | |
tree | 297c65c99896b15ab0a02b88ac577c23976de379 | |
parent | f68e4aad09427570ea0ceb2623576be125cd767a (diff) | |
download | infinity-for-reddit-568aa7a78f37f7dd4c4c027e9701467887da799f.tar infinity-for-reddit-568aa7a78f37f7dd4c4c027e9701467887da799f.tar.gz infinity-for-reddit-568aa7a78f37f7dd4c4c027e9701467887da799f.tar.bz2 infinity-for-reddit-568aa7a78f37f7dd4c4c027e9701467887da799f.tar.lz infinity-for-reddit-568aa7a78f37f7dd4c4c027e9701467887da799f.tar.xz infinity-for-reddit-568aa7a78f37f7dd4c4c027e9701467887da799f.tar.zst infinity-for-reddit-568aa7a78f37f7dd4c4c027e9701467887da799f.zip |
New option: Default Link Post Layout.
Diffstat (limited to '')
8 files changed, 107 insertions, 2 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 c0f29cce..ff3ff317 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -148,6 +148,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private boolean canStartActivity = true; private int mPostType; private int mPostLayout; + private int mDefaultLinkPostLayout; private int mColorPrimaryLightTheme; private int mColorAccent; private int mCardViewBackgroundColor; @@ -295,6 +296,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mHideTheNumberOfComments = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false); mPostLayout = postLayout; + mDefaultLinkPostLayout = Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.DEFAULT_LINK_POST_LAYOUT_KEY, "-1")); mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); mColorAccent = customThemeWrapper.getColorAccent(); @@ -382,8 +384,24 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView case Post.IMAGE_TYPE: return VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE; case Post.LINK_TYPE: + switch (mDefaultLinkPostLayout) { + case SharedPreferencesUtils.POST_LAYOUT_COMPACT: + return VIEW_TYPE_POST_COMPACT; + case SharedPreferencesUtils.POST_LAYOUT_GALLERY: + return VIEW_TYPE_POST_GALLERY; + case SharedPreferencesUtils.POST_LAYOUT_CARD_2: + return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW; + } return VIEW_TYPE_POST_CARD_LINK_TYPE; case Post.NO_PREVIEW_LINK_TYPE: + switch (mDefaultLinkPostLayout) { + case SharedPreferencesUtils.POST_LAYOUT_COMPACT: + return VIEW_TYPE_POST_COMPACT; + case SharedPreferencesUtils.POST_LAYOUT_GALLERY: + return VIEW_TYPE_POST_GALLERY; + case SharedPreferencesUtils.POST_LAYOUT_CARD_2: + return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW; + } return VIEW_TYPE_POST_CARD_NO_PREVIEW_LINK_TYPE; case Post.GALLERY_TYPE: return VIEW_TYPE_POST_CARD_GALLERY_TYPE; @@ -393,6 +411,23 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } return VIEW_TYPE_POST_CARD_TEXT_TYPE; } else if (mPostLayout == SharedPreferencesUtils.POST_LAYOUT_COMPACT) { + Post post = getItem(position); + if (post != null) { + if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) { + switch (mDefaultLinkPostLayout) { + case SharedPreferencesUtils.POST_LAYOUT_CARD: + if (post.getPostType() == Post.LINK_TYPE) { + return VIEW_TYPE_POST_CARD_LINK_TYPE; + } else { + return VIEW_TYPE_POST_CARD_NO_PREVIEW_LINK_TYPE; + } + case SharedPreferencesUtils.POST_LAYOUT_GALLERY: + return VIEW_TYPE_POST_GALLERY; + case SharedPreferencesUtils.POST_LAYOUT_CARD_2: + return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW; + } + } + } return VIEW_TYPE_POST_COMPACT; } else if (mPostLayout == SharedPreferencesUtils.POST_LAYOUT_GALLERY) { return VIEW_TYPE_POST_GALLERY; @@ -410,10 +445,22 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW; case Post.GIF_TYPE: case Post.IMAGE_TYPE: - case Post.LINK_TYPE: - case Post.NO_PREVIEW_LINK_TYPE: case Post.GALLERY_TYPE: return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW; + case Post.LINK_TYPE: + case Post.NO_PREVIEW_LINK_TYPE: + switch (mDefaultLinkPostLayout) { + case SharedPreferencesUtils.POST_LAYOUT_CARD: + if (post.getPostType() == Post.LINK_TYPE) { + return VIEW_TYPE_POST_CARD_LINK_TYPE; + } else { + return VIEW_TYPE_POST_CARD_NO_PREVIEW_LINK_TYPE; + } + case SharedPreferencesUtils.POST_LAYOUT_GALLERY: + return VIEW_TYPE_POST_GALLERY; + case SharedPreferencesUtils.POST_LAYOUT_COMPACT: + return VIEW_TYPE_POST_COMPACT; + } default: return VIEW_TYPE_POST_CARD_2_TEXT_TYPE; } @@ -1846,6 +1893,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mHideTheNumberOfComments = hideTheNumberOfComments; } + public void setDefaultLinkPostLayout(int defaultLinkPostLayout) { + mDefaultLinkPostLayout = defaultLinkPostLayout; + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeDefaultLinkPostLayoutEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeDefaultLinkPostLayoutEvent.java new file mode 100644 index 00000000..d7897beb --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeDefaultLinkPostLayoutEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.events; + +public class ChangeDefaultLinkPostLayoutEvent { + public int defaultLinkPostLayout; + + public ChangeDefaultLinkPostLayoutEvent(int defaultLinkPostLayout) { + this.defaultLinkPostLayout = defaultLinkPostLayout; + } +} 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 828f2f64..223dcf2b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -82,6 +82,7 @@ import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer; import ml.docilealligator.infinityforreddit.events.ChangeAutoplayNsfwVideosEvent; import ml.docilealligator.infinityforreddit.events.ChangeCompactLayoutToolbarHiddenByDefaultEvent; import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent; +import ml.docilealligator.infinityforreddit.events.ChangeDefaultLinkPostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeDisableImagePreviewEvent; import ml.docilealligator.infinityforreddit.events.ChangeEnableSwipeActionSwitchEvent; @@ -1673,6 +1674,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } @Subscribe + public void onChangeDefaultLinkPostLayoutEvent(ChangeDefaultLinkPostLayoutEvent event) { + if (mAdapter != null) { + mAdapter.setDefaultLinkPostLayout(event.defaultLinkPostLayout); + refreshAdapter(); + } + } + + @Subscribe public void onChangeShowAbsoluteNumberOfVotesEvent(ChangeShowAbsoluteNumberOfVotesEvent changeShowAbsoluteNumberOfVotesEvent) { if (mAdapter != null) { mAdapter.setShowAbsoluteNumberOfVotes(changeShowAbsoluteNumberOfVotesEvent.showAbsoluteNumberOfVotes); 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 f3a4f30c..5b508a96 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,7 @@ import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.events.ChangeCompactLayoutToolbarHiddenByDefaultEvent; +import ml.docilealligator.infinityforreddit.events.ChangeDefaultLinkPostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeHidePostFlairEvent; import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent; @@ -31,6 +32,7 @@ public class PostPreferenceFragment extends PreferenceFragmentCompat { setPreferencesFromResource(R.xml.post_preferences, rootKey); ListPreference defaultPostLayoutList = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); + ListPreference defaultLinkPostLayoutList = findPreference(SharedPreferencesUtils.DEFAULT_LINK_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); @@ -50,6 +52,13 @@ public class PostPreferenceFragment extends PreferenceFragmentCompat { }); } + if (defaultLinkPostLayoutList != null) { + defaultLinkPostLayoutList.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeDefaultLinkPostLayoutEvent(Integer.parseInt((String) newValue))); + return true; + }); + } + if (showDividerInCompactLayoutSwitch != null) { showDividerInCompactLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ShowDividerInCompactLayoutPreferenceEvent((Boolean) newValue)); 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 a9a75626..470aad37 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -184,6 +184,7 @@ public class SharedPreferencesUtils { public static final String APPLY_MATERIAL_YOU = "apply_material_you"; public static final String VIDEO_PLAYER_AUTOMATIC_LANDSCAPE_ORIENTATION = "video_player_automatic_landscape_orientation"; public static final String REMEMBER_MUTING_OPTION_IN_POST_FEED = "remember_muting_option_in_post_feed"; + public static final String DEFAULT_LINK_POST_LAYOUT_KEY = "default_link_post_layout"; 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/arrays.xml b/app/src/main/res/values/arrays.xml index 38370d05..a22e1f60 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -55,6 +55,22 @@ <item>2</item> </string-array> + <string-array name="settings_default_link_post_layout"> + <item>@string/link_post_layout_auto</item> + <item>@string/post_layout_card</item> + <item>@string/post_layout_card_2</item> + <item>@string/post_layout_compact</item> + <item>@string/post_layout_gallery</item> + </string-array> + + <string-array name="settings_default_link_post_layout_values"> + <item>-1</item> + <item>0</item> + <item>3</item> + <item>1</item> + <item>2</item> + </string-array> + <string-array name="settings_video_autoplay"> <item>@string/always_on</item> <item>@string/only_on_wifi</item> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f44c7c92..b0cf0dde 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -401,6 +401,7 @@ <string name="settings_time_format_title">Time Format</string> <string name="settings_category_post_title">Post</string> <string name="settings_default_post_layout">Default Post Layout</string> + <string name="settings_default_link_post_layout">Default Link Post Layout</string> <string name="settings_show_divider_in_compact_layout">Show Divider</string> <string name="settings_show_thumbnail_on_the_left_in_compact_layout">Show Thumbnail on the Left</string> <string name="settings_number_of_columns_in_post_feed_title">The Number of Columns in Post Feed</string> @@ -619,6 +620,7 @@ <string name="favorites">Favorites</string> <string name="all">All</string> + <string name="link_post_layout_auto">Auto</string> <string name="post_layout_card">Card Layout</string> <string name="post_layout_compact">Compact Layout</string> <string name="post_layout_gallery">Gallery Layout</string> diff --git a/app/src/main/res/xml/post_preferences.xml b/app/src/main/res/xml/post_preferences.xml index 7ea526a5..55f9f5c2 100644 --- a/app/src/main/res/xml/post_preferences.xml +++ b/app/src/main/res/xml/post_preferences.xml @@ -10,6 +10,14 @@ app:title="@string/settings_default_post_layout" app:useSimpleSummaryProvider="true" /> + <ListPreference + app:defaultValue="-1" + android:entries="@array/settings_default_link_post_layout" + app:entryValues="@array/settings_default_link_post_layout_values" + app:key="default_link_post_layout" + app:title="@string/settings_default_link_post_layout" + app:useSimpleSummaryProvider="true" /> + <Preference app:title="@string/settings_number_of_columns_in_post_feed_title" app:fragment="ml.docilealligator.infinityforreddit.settings.NumberOfColumnsInPostFeedPreferenceFragment" /> |