diff options
Diffstat (limited to 'app/src/main/java/ml')
7 files changed, 104 insertions, 73 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 495a6df4..3ad2c699 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -213,7 +213,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin(); Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this, miscPlugin, imageAndGifPlugin, parentTextColor, parentSpoilerBackgroundColor, null); - MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(this, mSharedPreferences, mGlide, new ImageAndGifEntry.OnItemClickListener() { + MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(this, mGlide, new ImageAndGifEntry.OnItemClickListener() { @Override public void onItemClick(Post.MediaMetadata mediaMetadata) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index 0825a8fa..e6084948 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -147,7 +147,7 @@ public class FullMarkdownActivity extends BaseActivity { miscPlugin, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, null); MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(this, - mSharedPreferences, Glide.with(this), new ImageAndGifEntry.OnItemClickListener() { + Glide.with(this), new ImageAndGifEntry.OnItemClickListener() { @Override public void onItemClick(Post.MediaMetadata mediaMetadata) { 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 2df36e7b..714dc5c1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -183,7 +183,7 @@ public class WikiActivity extends BaseActivity { markwon = MarkdownUtils.createFullRedditMarkwon(this, miscPlugin, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener); - markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(this, mSharedPreferences, + markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(this, mGlide, new ImageAndGifEntry.OnItemClickListener() { @Override public void onItemClick(Post.MediaMetadata mediaMetadata) { 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 e3746a7e..11b04252 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -146,6 +146,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler private SaveMemoryCenterInisdeDownsampleStrategy mSaveMemoryCenterInsideDownsampleStrategy; private ImageAndGifPlugin mImageAndGifPlugin; private Markwon mPostDetailMarkwon; + private ImageAndGifEntry mImageAndGifEntry; private final MarkwonAdapter mMarkwonAdapter; private String mAccessToken; private String mAccountName; @@ -245,69 +246,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler int markdownColor = customThemeWrapper.getPostContentColor(); int postSpoilerBackgroundColor = markdownColor | 0xFF000000; int linkColor = customThemeWrapper.getLinkColor(); - MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() { - @Override - public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { - if (mActivity.contentTypeface != null) { - textView.setTypeface(mActivity.contentTypeface); - } - textView.setTextColor(markdownColor); - textView.setHighlightColor(Color.TRANSPARENT); - textView.setOnLongClickListener(view -> { - if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) { - CopyTextBottomSheetFragment.show( - mActivity.getSupportFragmentManager(), - mPost.getSelfTextPlain(), mPost.getSelfText() - ); - } - return true; - }); - } - - @Override - public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { - builder.linkResolver((view, link) -> { - Intent intent = new Intent(mActivity, LinkResolverActivity.class); - Uri uri = Uri.parse(link); - intent.setData(uri); - intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, mPost.isNSFW()); - mActivity.startActivity(intent); - }); - } - - @Override - public void configureTheme(@NonNull MarkwonTheme.Builder builder) { - builder.linkColor(linkColor); - } - }; - BetterLinkMovementMethod.OnLinkLongClickListener onLinkLongClickListener = (textView, url) -> { - if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) { - UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url); - urlMenuBottomSheetFragment.setArguments(bundle); - urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); - } - return true; - }; - mImageAndGifPlugin = new ImageAndGifPlugin(); - mPostDetailMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity, - miscPlugin, mImageAndGifPlugin, markdownColor, postSpoilerBackgroundColor, onLinkLongClickListener); - mMarkwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(activity, sharedPreferences, - mGlide, new ImageAndGifEntry.OnItemClickListener() { - @Override - public void onItemClick(Post.MediaMetadata mediaMetadata) { - Intent intent = new Intent(activity, ViewImageOrGifActivity.class); - intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); - intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); - if (canStartActivity) { - canStartActivity = false; - activity.startActivity(intent); - } - } - })); mSeparatePostAndComments = separatePostAndComments; mLegacyAutoplayVideoControllerUI = sharedPreferences.getBoolean(SharedPreferencesUtils.LEGACY_AUTOPLAY_VIDEO_CONTROLLER_UI, false); @@ -399,6 +337,70 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } mExoCreator = exoCreator; + + MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() { + @Override + public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { + if (mActivity.contentTypeface != null) { + textView.setTypeface(mActivity.contentTypeface); + } + textView.setTextColor(markdownColor); + textView.setHighlightColor(Color.TRANSPARENT); + textView.setOnLongClickListener(view -> { + if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) { + CopyTextBottomSheetFragment.show( + mActivity.getSupportFragmentManager(), + mPost.getSelfTextPlain(), mPost.getSelfText() + ); + } + return true; + }); + } + + @Override + public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { + builder.linkResolver((view, link) -> { + Intent intent = new Intent(mActivity, LinkResolverActivity.class); + Uri uri = Uri.parse(link); + intent.setData(uri); + intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, mPost.isNSFW()); + mActivity.startActivity(intent); + }); + } + + @Override + public void configureTheme(@NonNull MarkwonTheme.Builder builder) { + builder.linkColor(linkColor); + } + }; + BetterLinkMovementMethod.OnLinkLongClickListener onLinkLongClickListener = (textView, url) -> { + if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) { + UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url); + urlMenuBottomSheetFragment.setArguments(bundle); + urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); + } + return true; + }; + mImageAndGifPlugin = new ImageAndGifPlugin(); + mPostDetailMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity, + miscPlugin, mImageAndGifPlugin, markdownColor, postSpoilerBackgroundColor, onLinkLongClickListener); + mImageAndGifEntry = new ImageAndGifEntry(activity, + mGlide, mDataSavingMode, + (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (mPost.isSpoiler() && mNeedBlurSpoiler), + mediaMetadata -> { + Intent intent = new Intent(activity, ViewImageOrGifActivity.class); + intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW()); + intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName()); + intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); + if (canStartActivity) { + canStartActivity = false; + activity.startActivity(intent); + } + }); + mMarkwonAdapter = MarkdownUtils.createTablesAdapter(mImageAndGifEntry); } public void setCanStartActivity(boolean canStartActivity) { 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 1f0a8451..a2dac6d9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -144,7 +144,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler shortNameTextView.setTypeface(activity.typeface); } markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(activity, - activity.getDefaultSharedPreferences(), Glide.with(activity), + Glide.with(activity), new ImageAndGifEntry.OnItemClickListener() { @Override public void onItemClick(Post.MediaMetadata mediaMetadata) { 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 54cd4241..81653baa 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -51,7 +51,6 @@ import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel; -import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class SidebarFragment extends Fragment { @@ -151,7 +150,7 @@ public class SidebarFragment extends Fragment { Markwon markwon = MarkdownUtils.createFullRedditMarkwon(activity, miscPlugin, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener); MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(activity, - activity.getDefaultSharedPreferences(),Glide.with(this), + Glide.with(this), new ImageAndGifEntry.OnItemClickListener() { @Override public void onItemClick(Post.MediaMetadata mediaMetadata) { 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 1e3460ec..89e3dcce 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java @@ -25,20 +25,43 @@ import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.databinding.MarkdownImageAndGifBlockBinding; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, ImageAndGifEntry.Holder> { private BaseActivity baseActivity; private RequestManager glide; private SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInsideDownsampleStrategy; private OnItemClickListener onItemClickListener; + private boolean dataSavingMode; + private boolean blurImage; - public ImageAndGifEntry(BaseActivity baseActivity, SharedPreferences sharedPreferences, - RequestManager glide, OnItemClickListener onItemClickListener) { + public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, + OnItemClickListener onItemClickListener) { this.baseActivity = baseActivity; this.glide = glide; + SharedPreferences sharedPreferences = baseActivity.getDefaultSharedPreferences(); this.saveMemoryCenterInsideDownsampleStrategy = new SaveMemoryCenterInisdeDownsampleStrategy( Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION, "5000000"))); this.onItemClickListener = onItemClickListener; + + String dataSavingModeString = sharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF); + if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) { + dataSavingMode = true; + } else if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) { + dataSavingMode = Utils.getConnectedNetwork(baseActivity) == Utils.NETWORK_TYPE_CELLULAR; + } + } + + public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, boolean dataSavingMode, boolean blurImage, + OnItemClickListener onItemClickListener) { + this.baseActivity = baseActivity; + this.glide = glide; + SharedPreferences sharedPreferences = baseActivity.getDefaultSharedPreferences(); + this.saveMemoryCenterInsideDownsampleStrategy = new SaveMemoryCenterInisdeDownsampleStrategy( + Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION, "5000000"))); + this.onItemClickListener = onItemClickListener; + this.dataSavingMode = dataSavingMode; + this.blurImage = blurImage; } @NonNull @@ -53,8 +76,15 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima holder.binding.progressBarMarkdownImageAndGifBlock.setVisibility(View.VISIBLE); - RequestBuilder<Drawable> imageRequestBuilder = glide.load(node.mediaMetadata.original.url).listener(holder.requestListener); - boolean blurImage = false; + RequestBuilder<Drawable> imageRequestBuilder; + if (dataSavingMode) { + imageRequestBuilder = glide.load(node.mediaMetadata.downscaled.url).listener(holder.requestListener); + holder.binding.imageViewMarkdownImageAndGifBlock.setRatio((float) node.mediaMetadata.downscaled.y / node.mediaMetadata.downscaled.x); + } else { + imageRequestBuilder = glide.load(node.mediaMetadata.original.url).listener(holder.requestListener); + holder.binding.imageViewMarkdownImageAndGifBlock.setRatio((float) node.mediaMetadata.original.y / node.mediaMetadata.original.x); + } + if (blurImage) { imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) .into(holder.binding.imageViewMarkdownImageAndGifBlock); |