From 2f912a523ee910ef75958365d89d2405cb6e5fc7 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 7 Jan 2021 15:36:23 +0800 Subject: New option in data saving mode: Only disable preview in video and gif posts. --- .../CommentAndPostRecyclerViewAdapter.java | 46 +++++++++------- .../adapters/PostRecyclerViewAdapter.java | 64 +++++++++++++--------- ...eOnlyDisablePreviewInVideoAndGifPostsEvent.java | 9 +++ .../infinityforreddit/fragments/PostFragment.java | 9 +++ .../settings/DataSavingModePreferenceFragment.java | 11 +++- .../utils/SharedPreferencesUtils.java | 1 + 6 files changed, 93 insertions(+), 47 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeOnlyDisablePreviewInVideoAndGifPostsEvent.java (limited to 'app/src/main/java/ml') 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 25f82e1e..bdfb619f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -124,20 +124,21 @@ import static ml.docilealligator.infinityforreddit.activities.CommentActivity.WR public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter implements CacheManager { private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY = 1; private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW = 2; - private static final int VIEW_TYPE_POST_DETAIL_IMAGE_AND_GIF_AUTOPLAY = 3; - private static final int VIEW_TYPE_POST_DETAIL_LINK = 4; - private static final int VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK = 5; - private static final int VIEW_TYPE_POST_DETAIL_GALLERY = 6; - private static final int VIEW_TYPE_POST_DETAIL_TEXT_TYPE = 7; - private static final int VIEW_TYPE_FIRST_LOADING = 8; - private static final int VIEW_TYPE_FIRST_LOADING_FAILED = 9; - private static final int VIEW_TYPE_NO_COMMENT_PLACEHOLDER = 10; - private static final int VIEW_TYPE_COMMENT = 11; - private static final int VIEW_TYPE_COMMENT_FULLY_COLLAPSED = 12; - private static final int VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS = 13; - private static final int VIEW_TYPE_IS_LOADING_MORE_COMMENTS = 14; - private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 15; - private static final int VIEW_TYPE_VIEW_ALL_COMMENTS = 16; + private static final int VIEW_TYPE_POST_DETAIL_IMAGE = 3; + private static final int VIEW_TYPE_POST_DETAIL_GIF_AUTOPLAY = 4; + private static final int VIEW_TYPE_POST_DETAIL_LINK = 5; + private static final int VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK = 6; + private static final int VIEW_TYPE_POST_DETAIL_GALLERY = 7; + private static final int VIEW_TYPE_POST_DETAIL_TEXT_TYPE = 8; + private static final int VIEW_TYPE_FIRST_LOADING = 9; + private static final int VIEW_TYPE_FIRST_LOADING_FAILED = 10; + private static final int VIEW_TYPE_NO_COMMENT_PLACEHOLDER = 11; + private static final int VIEW_TYPE_COMMENT = 12; + private static final int VIEW_TYPE_COMMENT_FULLY_COLLAPSED = 13; + private static final int VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS = 14; + private static final int VIEW_TYPE_IS_LOADING_MORE_COMMENTS = 15; + private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 16; + private static final int VIEW_TYPE_VIEW_ALL_COMMENTS = 17; private AppCompatActivity mActivity; private Retrofit mRetrofit; @@ -178,6 +179,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter previews = post.getPreviews(); if (previews != null && !previews.isEmpty()) { + if (post.getPostType() != Post.GIF_TYPE && post.getPostType() != Post.VIDEO_TYPE) { + ((PostCompactBaseViewHolder) holder).imageView.setVisibility(View.VISIBLE); + ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + } loadImage(holder, post, previews.get(0)); } } @@ -960,15 +966,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { @@ -35,5 +37,12 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat { return true; }); } + + if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { + onlyDisablePreviewInVideoAndGifPostsPreference.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeOnlyDisablePreviewInVideoAndGifPostsEvent((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 8cfd5ce5..c288bb15 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -149,6 +149,7 @@ public class SharedPreferencesUtils { public static final String LANGUAGE_DEFAULT_VALUE = "auto"; public static final String ENABLE_SEARCH_HISTORY = "enable_search_history"; public static final String POST_FILTER = "post_filter"; + public static final String ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS = "only_disable_preview_in_video_and_gif_posts"; 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"; -- cgit v1.2.3