diff options
Diffstat (limited to 'app/src/main/java/ml')
9 files changed, 51 insertions, 26 deletions
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<Comment mMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity, miscPlugin, mEmoteCloseBracketInlineProcessor, mEmotePlugin, mImageAndGifPlugin, mCommentColor, commentSpoilerBackgroundColor, onLinkLongClickListener); - mImageAndGifEntry = new ImageAndGifEntry(activity, Glide.with(activity), 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); - } - }); + 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<RecyclerVi boolean doNotBlurNsfwInNsfwSubreddits = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : mAccountName) + SharedPreferencesUtils.DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS, false); boolean needBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : mAccountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false); boolean blurImage = (post.isNSFW() && needBlurNsfw && !(doNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && needBlurSpoiler); - mImageAndGifEntry = new ImageAndGifEntry(activity, mGlide, blurImage, + mImageAndGifEntry = new ImageAndGifEntry(activity, mGlide, Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.EMBEDDED_MEDIA_TYPE, "15")), blurImage, mediaMetadata -> { 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<Recycler miscPlugin, mEmoteCloseBracketInlineProcessor, mEmotePlugin, mImageAndGifPlugin, markdownColor, postSpoilerBackgroundColor, onLinkLongClickListener); mImageAndGifEntry = new ImageAndGifEntry(activity, - mGlide, mDataSavingMode, mDisableImagePreview, + mGlide, Integer.parseInt(postDetailsSharedPreferences.getString(SharedPreferencesUtils.EMBEDDED_MEDIA_TYPE, "15")), + mDataSavingMode, mDisableImagePreview, (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (mPost.isSpoiler() && mNeedBlurSpoiler), mediaMetadata -> { 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<RulesRecyclerViewAdapter.RuleViewHolder> { private final BaseActivity activity; @@ -103,7 +104,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler }); imageAndGifPlugin = new ImageAndGifPlugin(); imageAndGifEntry = new ImageAndGifEntry(activity, - Glide.with(activity), + Glide.with(activity), 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/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<ImageAndGifBlock, Ima private final int primaryTextColor; private final int postContentColor; private final int linkColor; + private final boolean canShowImage; + private final boolean canShowGif; - public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, + public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, int embeddedMediaType, OnItemClickListener onItemClickListener) { this.baseActivity = baseActivity; this.glide = glide; @@ -66,6 +68,8 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima primaryTextColor = baseActivity.getCustomThemeWrapper().getPrimaryTextColor(); postContentColor = baseActivity.getCustomThemeWrapper().getPostContentColor(); linkColor = baseActivity.getCustomThemeWrapper().getLinkColor(); + canShowImage = SharedPreferencesUtils.canShowImage(embeddedMediaType); + canShowGif = SharedPreferencesUtils.canShowGif(embeddedMediaType); String dataSavingModeString = sharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF); if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) { @@ -76,13 +80,13 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima disableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false); } - public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, boolean blurImage, - OnItemClickListener onItemClickListener) { - this(baseActivity, glide, onItemClickListener); + public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, int embeddedMediaType, + boolean blurImage, OnItemClickListener onItemClickListener) { + this(baseActivity, glide, embeddedMediaType, onItemClickListener); this.blurImage = blurImage; } - public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, boolean dataSavingMode, + public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, int embeddedMediaType, boolean dataSavingMode, boolean disableImagePreview, boolean blurImage, OnItemClickListener onItemClickListener) { this.baseActivity = baseActivity; @@ -98,6 +102,8 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima primaryTextColor = baseActivity.getCustomThemeWrapper().getPrimaryTextColor(); postContentColor = baseActivity.getCustomThemeWrapper().getPostContentColor(); linkColor = baseActivity.getCustomThemeWrapper().getLinkColor(); + canShowImage = SharedPreferencesUtils.canShowImage(embeddedMediaType); + canShowGif = SharedPreferencesUtils.canShowGif(embeddedMediaType); } @NonNull @@ -125,7 +131,7 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima RequestBuilder<Drawable> 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"; |