From c7479f3fdbfb175f5757218c6b1395c36bb573aa Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:25:02 -0400 Subject: Add options to control which kind of media to show in the markdown content. --- .../activities/CommentActivity.java | 2 +- .../infinityforreddit/activities/WikiActivity.java | 2 +- .../CommentsListingRecyclerViewAdapter.java | 30 ++++++++++++---------- .../adapters/CommentsRecyclerViewAdapter.java | 2 +- .../adapters/PostDetailRecyclerViewAdapter.java | 3 ++- .../adapters/RulesRecyclerViewAdapter.java | 3 ++- .../fragments/SidebarFragment.java | 2 +- .../markdown/ImageAndGifEntry.java | 18 ++++++++----- .../utils/SharedPreferencesUtils.java | 15 +++++++++++ app/src/main/res/values/arrays.xml | 22 ++++++++++++++++ app/src/main/res/values/strings.xml | 9 +++++++ app/src/main/res/xml/comment_preferences.xml | 8 ++++++ app/src/main/res/xml/post_details_preferences.xml | 8 ++++++ 13 files changed, 98 insertions(+), 26 deletions(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index fab5e216..0261eae5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -227,7 +227,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); }); ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin(); - imageAndGifEntry = new ImageAndGifEntry(this, mGlide, mediaMetadata -> { + imageAndGifEntry = new ImageAndGifEntry(this, mGlide, SharedPreferencesUtils.EMBEDDED_MEDIA_ALL, mediaMetadata -> { Intent imageIntent = new Intent(this, ViewImageOrGifActivity.class); if (mediaMetadata.isGIF) { imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index fede7776..691b411d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -176,7 +176,7 @@ public class WikiActivity extends BaseActivity { }); imageAndGifPlugin = new ImageAndGifPlugin(); imageAndGifEntry = new ImageAndGifEntry(this, - mGlide, mediaMetadata -> { + mGlide, SharedPreferencesUtils.EMBEDDED_MEDIA_ALL, mediaMetadata -> { Intent intent = new Intent(this, ViewImageOrGifActivity.class); if (mediaMetadata.isGIF) { intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index 296bb8a3..95ad046c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -198,20 +198,22 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { - Intent intent = new Intent(activity, ViewImageOrGifActivity.class); - if (mediaMetadata.isGIF) { - intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); - } else { - intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); - } - intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, username); - intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); - if (canStartActivity) { - canStartActivity = false; - activity.startActivity(intent); - } - }); + mImageAndGifEntry = new ImageAndGifEntry(activity, Glide.with(activity), + Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.EMBEDDED_MEDIA_TYPE, "15")), + mediaMetadata -> { + Intent intent = new Intent(activity, ViewImageOrGifActivity.class); + if (mediaMetadata.isGIF) { + intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); + } else { + intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + } + intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, username); + intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); + if (canStartActivity) { + canStartActivity = false; + activity.startActivity(intent); + } + }); recycledViewPool = new RecyclerView.RecycledViewPool(); } 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 dd6b9c91..f4000e5c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -244,7 +244,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { Intent intent = new Intent(activity, ViewImageOrGifActivity.class); if (mediaMetadata.isGIF) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index baf833ee..5f5c7cd7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -404,7 +404,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { Intent intent = new Intent(activity, ViewImageOrGifActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java index 6170d7dd..3be31942 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -38,6 +38,7 @@ import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMetho import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry; import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { private final BaseActivity activity; @@ -103,7 +104,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { Intent imageIntent = new Intent(activity, ViewImageOrGifActivity.class); if (mediaMetadata.isGIF) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java index b3f139b1..e1a1f13d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -163,7 +163,7 @@ public class SidebarFragment extends Fragment { }); ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin(); imageAndGifEntry = new ImageAndGifEntry(activity, - Glide.with(this), + Glide.with(this), SharedPreferencesUtils.EMBEDDED_MEDIA_ALL, mediaMetadata -> { Intent imageIntent = new Intent(activity, ViewImageOrGifActivity.class); if (mediaMetadata.isGIF) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java index 01dc27ab..aa053f4f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java @@ -53,8 +53,10 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry imageRequestBuilder; if (dataSavingMode) { - if (disableImagePreview) { + if (disableImagePreview || (node.mediaMetadata.isGIF && !canShowGif) || (!node.mediaMetadata.isGIF && !canShowImage)) { holder.binding.imageWrapperRelativeLayoutMarkdownImageAndGifBlock.setVisibility(View.GONE); holder.binding.captionTextViewMarkdownImageAndGifBlock.setVisibility(View.VISIBLE); holder.binding.captionTextViewMarkdownImageAndGifBlock.setGravity(Gravity.NO_GRAVITY); 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 51ad438b..ff2f800e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -256,6 +256,21 @@ public class SharedPreferencesUtils { return POST_DETAIL_FAB_LANDSCAPE_Y_BASE + display.getDisplayId(); } + public static final String EMBEDDED_MEDIA_TYPE = "embedded_media_type"; + public static final int EMBEDDED_MEDIA_ALL = 15; + + public static boolean canShowImage(int embeddedMediaType) { + return embeddedMediaType == 15 || embeddedMediaType == 7 || embeddedMediaType == 6 || embeddedMediaType == 3; + } + + public static boolean canShowGif(int embeddedMediaType) { + return embeddedMediaType == 15 || embeddedMediaType == 7 || embeddedMediaType == 5 || embeddedMediaType == 2; + } + + public static boolean canShowEmoji(int embeddedMediaType) { + return embeddedMediaType == 15 || embeddedMediaType == 6 || embeddedMediaType == 5 || embeddedMediaType == 1; + } + 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"; public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count"; diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index adb1cb64..3b94b241 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -698,4 +698,26 @@ @string/save_locally_and_online + + @string/all + @string/image_and_gif + @string/image_and_emoji + @string/gif_and_emoji + @string/image_embedded_media + @string/gif + @string/emoji + @string/none + + + + 15 + 7 + 6 + 5 + 3 + 2 + 1 + 0 + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 898df6ed..833411b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -642,6 +642,7 @@ Hide FAB in Post Feed Comment Divider Type Comment Filter + Embedded Media Type Cannot get the link @@ -1393,4 +1394,12 @@ Local Online + Image and GIF + Image and emoji + GIF and emoji + Image + Emoji + None + + diff --git a/app/src/main/res/xml/comment_preferences.xml b/app/src/main/res/xml/comment_preferences.xml index bfd4237a..79b49351 100644 --- a/app/src/main/res/xml/comment_preferences.xml +++ b/app/src/main/res/xml/comment_preferences.xml @@ -63,4 +63,12 @@ app:title="@string/settings_show_fewer_toolbar_options_threshold_title" app:singleLineTitle="false" /> + + \ No newline at end of file diff --git a/app/src/main/res/xml/post_details_preferences.xml b/app/src/main/res/xml/post_details_preferences.xml index 0cbf770f..3ff62eee 100644 --- a/app/src/main/res/xml/post_details_preferences.xml +++ b/app/src/main/res/xml/post_details_preferences.xml @@ -37,4 +37,12 @@ app:key="hide_the_number_of_comments" app:title="@string/settings_hide_the_number_of_comments" /> + + \ No newline at end of file -- cgit v1.2.3