aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-11-27 17:56:44 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-11-27 17:56:44 +0000
commit966bac159702a1fc648d8448f58f5a2138ebb346 (patch)
tree58d4a5e3b61e058c89c9eb32b71961b1d04b40e1 /app
parentfbfd0a3fb24bfd5d2066640b241b1fd3cd33b747 (diff)
downloadinfinity-for-reddit-966bac159702a1fc648d8448f58f5a2138ebb346.tar
infinity-for-reddit-966bac159702a1fc648d8448f58f5a2138ebb346.tar.gz
infinity-for-reddit-966bac159702a1fc648d8448f58f5a2138ebb346.tar.bz2
infinity-for-reddit-966bac159702a1fc648d8448f58f5a2138ebb346.tar.lz
infinity-for-reddit-966bac159702a1fc648d8448f58f5a2138ebb346.tar.xz
infinity-for-reddit-966bac159702a1fc648d8448f58f5a2138ebb346.tar.zst
infinity-for-reddit-966bac159702a1fc648d8448f58f5a2138ebb346.zip
Hide images and gifs in ImageAndGifEntry and EmotePlugin if corresponding data saving settings are enabled.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomMarkwonAdapter.java)22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java48
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java4
12 files changed, 120 insertions, 28 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 9ff5cf9c..a6af969e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
@@ -60,11 +60,12 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesB
import ml.docilealligator.infinityforreddit.comment.Comment;
import ml.docilealligator.infinityforreddit.comment.SendComment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter;
+import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.databinding.ActivityCommentBinding;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
+import ml.docilealligator.infinityforreddit.markdown.EmotePlugin;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
@@ -214,9 +215,10 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
}
};
EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
+ EmotePlugin emotePlugin = EmotePlugin.create(this);
ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin();
Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
- miscPlugin, emoteCloseBracketInlineProcessor, imageAndGifPlugin, parentTextColor,
+ miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, parentTextColor,
parentSpoilerBackgroundColor, null);
CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(this, mGlide, mediaMetadata -> {
Intent imageIntent = new Intent(this, ViewImageOrGifActivity.class);
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 3897323b..33363ec3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
@@ -38,13 +38,14 @@ import io.noties.markwon.core.MarkwonTheme;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter;
+import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager;
import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
+import ml.docilealligator.infinityforreddit.markdown.EmotePlugin;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
@@ -143,9 +144,10 @@ public class FullMarkdownActivity extends BaseActivity {
}
};
EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
+ EmotePlugin emotePlugin = EmotePlugin.create(this);
ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin();
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(this,
- miscPlugin, emoteCloseBracketInlineProcessor, imageAndGifPlugin, markdownColor,
+ miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor,
spoilerBackgroundColor, null);
CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(this,
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 5d31f2f0..cd2f9526 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java
@@ -53,6 +53,7 @@ import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutMan
import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
+import ml.docilealligator.infinityforreddit.markdown.EmotePlugin;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
@@ -100,6 +101,7 @@ public class WikiActivity extends BaseActivity {
private String wikiMarkdown;
private String mSubredditName;
private EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor;
+ private EmotePlugin emotePlugin;
private ImageAndGifPlugin imageAndGifPlugin;
private Markwon markwon;
private MarkwonAdapter markwonAdapter;
@@ -184,9 +186,10 @@ public class WikiActivity extends BaseActivity {
return true;
};
emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
+ emotePlugin = EmotePlugin.create(this);
imageAndGifPlugin = new ImageAndGifPlugin();
markwon = MarkdownUtils.createFullRedditMarkwon(this,
- miscPlugin, emoteCloseBracketInlineProcessor, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener);
+ miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener);
markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(this,
mGlide, mediaMetadata -> {
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 f9a445dd..ce979f78 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
@@ -52,13 +52,14 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSh
import ml.docilealligator.infinityforreddit.comment.Comment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView;
-import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter;
+import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager;
import ml.docilealligator.infinityforreddit.databinding.ItemCommentBinding;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
+import ml.docilealligator.infinityforreddit.markdown.EmotePlugin;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
@@ -86,6 +87,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private Retrofit mOauthRetrofit;
private Locale mLocale;
private EmoteCloseBracketInlineProcessor mEmoteCloseBracketInlineProcessor;
+ private EmotePlugin mEmotePlugin;
private ImageAndGifPlugin mImageAndGifPlugin;
private Markwon mMarkwon;
private ImageAndGifEntry mImageAndGifEntry;
@@ -175,14 +177,15 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
BetterLinkMovementMethod.OnLinkLongClickListener onLinkLongClickListener = (textView, url) -> {
if (!activity.isDestroyed() && !activity.isFinishing()) {
UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = UrlMenuBottomSheetFragment.newInstance(url);
- urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), null);
+ urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag());
}
return true;
};
mEmoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
+ mEmotePlugin = EmotePlugin.create(activity);
mImageAndGifPlugin = new ImageAndGifPlugin();
mMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
- miscPlugin, mEmoteCloseBracketInlineProcessor, mImageAndGifPlugin, mCommentColor,
+ miscPlugin, mEmoteCloseBracketInlineProcessor, mEmotePlugin, mImageAndGifPlugin, mCommentColor,
commentSpoilerBackgroundColor, onLinkLongClickListener);
mImageAndGifEntry = new ImageAndGifEntry(activity, Glide.with(activity), new ImageAndGifEntry.OnItemClickListener() {
@Override
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 85e03845..454d5398 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
@@ -61,7 +61,7 @@ import ml.docilealligator.infinityforreddit.comment.Comment;
import ml.docilealligator.infinityforreddit.comment.FetchComment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView;
-import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter;
+import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface;
@@ -69,6 +69,7 @@ import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutMan
import ml.docilealligator.infinityforreddit.databinding.ItemCommentBinding;
import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
+import ml.docilealligator.infinityforreddit.markdown.EmotePlugin;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
@@ -98,6 +99,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private Retrofit mRetrofit;
private Retrofit mOauthRetrofit;
private EmoteCloseBracketInlineProcessor mEmoteCloseBracketInlineProcessor;
+ private EmotePlugin mEmotePlugin;
private ImageAndGifPlugin mImageAndGifPlugin;
private Markwon mCommentMarkwon;
private ImageAndGifEntry mImageAndGifEntry;
@@ -213,9 +215,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
return true;
};
mEmoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
+ mEmotePlugin = EmotePlugin.create(activity);
mImageAndGifPlugin = new ImageAndGifPlugin();
mCommentMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
- miscPlugin, mEmoteCloseBracketInlineProcessor, mImageAndGifPlugin, mCommentTextColor,
+ miscPlugin, mEmoteCloseBracketInlineProcessor, mEmotePlugin, mImageAndGifPlugin, mCommentTextColor,
commentSpoilerBackgroundColor, onLinkLongClickListener);
boolean needBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true);
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 8a43d74f..5e5e8760 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -90,7 +90,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottom
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView;
-import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter;
+import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager;
@@ -104,6 +104,7 @@ import ml.docilealligator.infinityforreddit.databinding.ItemPostDetailVideoAutop
import ml.docilealligator.infinityforreddit.databinding.ItemPostDetailVideoAutoplayLegacyControllerBinding;
import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
+import ml.docilealligator.infinityforreddit.markdown.EmotePlugin;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
@@ -146,6 +147,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private RequestManager mGlide;
private SaveMemoryCenterInisdeDownsampleStrategy mSaveMemoryCenterInsideDownsampleStrategy;
private EmoteCloseBracketInlineProcessor mEmoteCloseBracketInlineProcessor;
+ private EmotePlugin mEmotePlugin;
private ImageAndGifPlugin mImageAndGifPlugin;
private Markwon mPostDetailMarkwon;
private ImageAndGifEntry mImageAndGifEntry;
@@ -386,12 +388,13 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
return true;
};
mEmoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
+ mEmotePlugin = EmotePlugin.create(activity);
mImageAndGifPlugin = new ImageAndGifPlugin();
mPostDetailMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
- miscPlugin, mEmoteCloseBracketInlineProcessor, mImageAndGifPlugin, markdownColor,
+ miscPlugin, mEmoteCloseBracketInlineProcessor, mEmotePlugin, mImageAndGifPlugin, markdownColor,
postSpoilerBackgroundColor, onLinkLongClickListener);
mImageAndGifEntry = new ImageAndGifEntry(activity,
- mGlide, mDataSavingMode,
+ mGlide, 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 ed55fe62..9c6457ec 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java
@@ -36,6 +36,7 @@ import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager;
import ml.docilealligator.infinityforreddit.customviews.slidr.widget.SliderPanel;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
+import ml.docilealligator.infinityforreddit.markdown.EmotePlugin;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
@@ -43,6 +44,7 @@ import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecyclerViewAdapter.RuleViewHolder> {
private BaseActivity activity;
private EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor;
+ private EmotePlugin emotePlugin;
private ImageAndGifPlugin imageAndGifPlugin;
private Markwon markwon;
@Nullable
@@ -92,9 +94,10 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
return true;
};
emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
+ emotePlugin = EmotePlugin.create(activity);
imageAndGifPlugin = new ImageAndGifPlugin();
markwon = MarkdownUtils.createFullRedditMarkwon(activity,
- miscPlugin, emoteCloseBracketInlineProcessor, imageAndGifPlugin, mPrimaryTextColor,
+ miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, mPrimaryTextColor,
spoilerBackgroundColor, onLinkLongClickListener);
}
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 84d3bf5d..6d171a3a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
@@ -34,7 +34,6 @@ import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.MediaMetadata;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
@@ -44,9 +43,10 @@ import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter;
+import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
+import ml.docilealligator.infinityforreddit.markdown.EmotePlugin;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
@@ -149,9 +149,10 @@ public class SidebarFragment extends Fragment {
return true;
};
EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
+ EmotePlugin emotePlugin = EmotePlugin.create(activity);
ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin();
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(activity,
- miscPlugin, emoteCloseBracketInlineProcessor, imageAndGifPlugin, markdownColor,
+ miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor,
spoilerBackgroundColor, onLinkLongClickListener);
CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(activity,
Glide.with(this),
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomMarkwonAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java
index 10ed5719..25e63d2c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomMarkwonAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java
@@ -1,4 +1,4 @@
-package ml.docilealligator.infinityforreddit.customviews;
+package ml.docilealligator.infinityforreddit.markdown;
import android.util.SparseArray;
import android.view.LayoutInflater;
@@ -23,7 +23,7 @@ import io.noties.markwon.MarkwonReducer;
import io.noties.markwon.recycler.MarkwonAdapter;
import io.noties.markwon.recycler.SimpleEntry;
import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.markdown.ImageAndGifBlock;
+import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView;
public class CustomMarkwonAdapter extends MarkwonAdapter {
private final SparseArray<Entry<Node, Holder>> entries;
@@ -152,8 +152,24 @@ public class CustomMarkwonAdapter extends MarkwonAdapter {
if (node instanceof ImageAndGifBlock) {
if (!holder.itemView.hasOnClickListeners()) {
holder.itemView.setOnClickListener(onClickListener);
+ holder.itemView.setOnLongClickListener(onLongClickListener);
+ }
+
+ if (holder instanceof ImageAndGifEntry.Holder) {
+ if (!((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.hasOnClickListeners()) {
+ ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.setOnClickListener(view -> {
+ if (((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionStart() == -1 && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionEnd() == -1) {
+ onClickListener.onClick(view);
+ }
+ });
+ ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.setOnLongClickListener(view -> {
+ if (((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionStart() == -1 && ((ImageAndGifEntry.Holder) holder).binding.captionTextViewMarkdownImageAndGifBlock.getSelectionEnd() == -1) {
+ return onLongClickListener.onLongClick(view);
+ }
+ return false;
+ });
+ }
}
- holder.itemView.setOnLongClickListener(onLongClickListener);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java
index 2bb81bf9..05675498 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java
@@ -28,14 +28,16 @@ import io.noties.markwon.MarkwonSpansFactory;
import io.noties.markwon.MarkwonVisitor;
import io.noties.markwon.RenderProps;
import io.noties.markwon.SpanFactory;
+import io.noties.markwon.core.CoreProps;
import io.noties.markwon.image.AsyncDrawable;
import io.noties.markwon.image.AsyncDrawableLoader;
import io.noties.markwon.image.AsyncDrawableScheduler;
import io.noties.markwon.image.DrawableUtils;
import io.noties.markwon.image.ImageProps;
-import ml.docilealligator.infinityforreddit.MediaMetadata;
public class EmotePlugin extends AbstractMarkwonPlugin {
+ private boolean disableImagePreview = true;
+
public interface GlideStore {
@NonNull
@@ -93,6 +95,18 @@ public class EmotePlugin extends AbstractMarkwonPlugin {
@Override
public void configureVisitor(@NonNull MarkwonVisitor.Builder builder) {
builder.on(Emote.class, (visitor, emote) -> {
+ if (disableImagePreview) {
+ Link link = new Link(emote.getMediaMetadata().original.url, emote.getTitle());
+
+ final int length = visitor.length();
+ visitor.visitChildren(emote);
+
+ final String destination = link.getDestination();
+ CoreProps.LINK_DESTINATION.set(visitor.renderProps(), destination);
+ visitor.setSpansForNodeOptional(link, length);
+ return;
+ }
+
// if there is no image spanFactory, ignore
final SpanFactory spanFactory = visitor.configuration().spansFactory().get(Emote.class);
if (spanFactory == null) {
@@ -141,8 +155,8 @@ public class EmotePlugin extends AbstractMarkwonPlugin {
AsyncDrawableScheduler.schedule(textView);
}
- public void setMediaMetadataMap(Map<String, MediaMetadata> mediaMetadataMap) {
-
+ public void setDisableImagePreview(boolean disableImagePreview) {
+ this.disableImagePreview = disableImagePreview;
}
private static class GlideAsyncDrawableLoader extends AsyncDrawableLoader {
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 4f42acc1..12e62632 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java
@@ -1,8 +1,13 @@
package ml.docilealligator.infinityforreddit.markdown;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.style.URLSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
@@ -26,9 +31,12 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.recycler.MarkwonAdapter;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
+import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.MediaMetadata;
import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
+import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.databinding.MarkdownImageAndGifBlockBinding;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
@@ -39,10 +47,12 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
private SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInsideDownsampleStrategy;
private OnItemClickListener onItemClickListener;
private boolean dataSavingMode;
+ private boolean disableImagePreview;
private boolean blurImage;
private int colorAccent;
private int primaryTextColor;
private int postContentColor;
+ private int linkColor;
public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide,
OnItemClickListener onItemClickListener) {
@@ -55,6 +65,7 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
colorAccent = baseActivity.getCustomThemeWrapper().getColorAccent();
primaryTextColor = baseActivity.getCustomThemeWrapper().getPrimaryTextColor();
postContentColor = baseActivity.getCustomThemeWrapper().getPostContentColor();
+ linkColor = baseActivity.getCustomThemeWrapper().getLinkColor();
String dataSavingModeString = sharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) {
@@ -62,6 +73,7 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
} else if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
dataSavingMode = Utils.getConnectedNetwork(baseActivity) == Utils.NETWORK_TYPE_CELLULAR;
}
+ disableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
}
public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, boolean blurImage,
@@ -70,11 +82,13 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
this.blurImage = blurImage;
}
- public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, boolean dataSavingMode, boolean blurImage,
+ public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, boolean dataSavingMode,
+ boolean disableImagePreview, boolean blurImage,
OnItemClickListener onItemClickListener) {
this.baseActivity = baseActivity;
this.glide = glide;
this.dataSavingMode = dataSavingMode;
+ this.disableImagePreview = disableImagePreview;
this.blurImage = blurImage;
SharedPreferences sharedPreferences = baseActivity.getDefaultSharedPreferences();
this.saveMemoryCenterInsideDownsampleStrategy = new SaveMemoryCenterInisdeDownsampleStrategy(
@@ -83,6 +97,7 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
colorAccent = baseActivity.getCustomThemeWrapper().getColorAccent();
primaryTextColor = baseActivity.getCustomThemeWrapper().getPrimaryTextColor();
postContentColor = baseActivity.getCustomThemeWrapper().getPostContentColor();
+ linkColor = baseActivity.getCustomThemeWrapper().getLinkColor();
}
@NonNull
@@ -110,8 +125,18 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
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);
+ if (disableImagePreview) {
+ holder.binding.imageWrapperRelativeLayoutMarkdownImageAndGifBlock.setVisibility(View.GONE);
+ holder.binding.captionTextViewMarkdownImageAndGifBlock.setVisibility(View.VISIBLE);
+ holder.binding.captionTextViewMarkdownImageAndGifBlock.setGravity(Gravity.NO_GRAVITY);
+ SpannableString spannableString = new SpannableString(node.mediaMetadata.caption == null ? node.mediaMetadata.original.url : node.mediaMetadata.caption);
+ spannableString.setSpan(new URLSpan(node.mediaMetadata.original.url), 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ holder.binding.captionTextViewMarkdownImageAndGifBlock.setText(spannableString);
+ return;
+ } else {
+ 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);
@@ -143,6 +168,7 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
@Override
public void onViewRecycled(@NonNull Holder holder) {
super.onViewRecycled(holder);
+ holder.binding.imageWrapperRelativeLayoutMarkdownImageAndGifBlock.setVisibility(View.VISIBLE);
ViewGroup.LayoutParams params = holder.binding.imageViewMarkdownImageAndGifBlock.getLayoutParams();
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
holder.binding.imageViewMarkdownImageAndGifBlock.setLayoutParams(params);
@@ -156,6 +182,7 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
holder.binding.progressBarMarkdownImageAndGifBlock.setVisibility(View.GONE);
holder.binding.loadImageErrorTextViewMarkdownImageAndGifBlock.setVisibility(View.GONE);
holder.binding.captionTextViewMarkdownImageAndGifBlock.setVisibility(View.GONE);
+ holder.binding.captionTextViewMarkdownImageAndGifBlock.setGravity(Gravity.CENTER_HORIZONTAL);
}
public class Holder extends MarkwonAdapter.Holder {
@@ -170,6 +197,7 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
binding.progressBarMarkdownImageAndGifBlock.setIndeterminateTintList(ColorStateList.valueOf(colorAccent));
binding.loadImageErrorTextViewMarkdownImageAndGifBlock.setTextColor(primaryTextColor);
binding.captionTextViewMarkdownImageAndGifBlock.setTextColor(postContentColor);
+ binding.captionTextViewMarkdownImageAndGifBlock.setLinkTextColor(linkColor);
if (baseActivity.typeface != null) {
binding.loadImageErrorTextViewMarkdownImageAndGifBlock.setTypeface(baseActivity.typeface);
@@ -198,6 +226,20 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
onItemClickListener.onItemClick(imageAndGifBlock.mediaMetadata);
}
});
+
+ binding.captionTextViewMarkdownImageAndGifBlock.setMovementMethod(
+ BetterLinkMovementMethod.newInstance()
+ .setOnLinkClickListener((textView, url) -> {
+ Intent intent = new Intent(baseActivity, LinkResolverActivity.class);
+ intent.setData(Uri.parse(url));
+ baseActivity.startActivity(intent);
+ return true;
+ })
+ .setOnLinkLongClickListener((textView, url) -> {
+ UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = UrlMenuBottomSheetFragment.newInstance(url);
+ urlMenuBottomSheetFragment.show(baseActivity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag());
+ return true;
+ }));
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java
index da867443..45e6f384 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java
@@ -21,7 +21,6 @@ import io.noties.markwon.recycler.table.TableEntry;
import io.noties.markwon.recycler.table.TableEntryPlugin;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter;
public class MarkdownUtils {
/**
@@ -32,6 +31,7 @@ public class MarkdownUtils {
public static Markwon createFullRedditMarkwon(@NonNull Context context,
@NonNull MarkwonPlugin miscPlugin,
@NonNull EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor,
+ @NonNull EmotePlugin emotePlugin,
@NonNull ImageAndGifPlugin imageAndGifPlugin,
int markdownColor,
int spoilerBackgroundColor,
@@ -53,7 +53,7 @@ public class MarkdownUtils {
.setOnLinkLongClickListener(onLinkLongClickListener)))
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(imageAndGifPlugin)
- .usePlugin(EmotePlugin.create(context))
+ .usePlugin(emotePlugin)
.usePlugin(TableEntryPlugin.create(context))
.build();
}