aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-05-04 05:22:07 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-05-04 05:22:07 +0000
commita288a638b5d08b77e16a6679fa2de5653e434a13 (patch)
tree0c839db1c0d6af4b7ffb117d2e2d370a49008651 /app/src/main
parentd046e51a95f44f523657206d2999f42a0f7de3dd (diff)
downloadinfinity-for-reddit-a288a638b5d08b77e16a6679fa2de5653e434a13.tar
infinity-for-reddit-a288a638b5d08b77e16a6679fa2de5653e434a13.tar.gz
infinity-for-reddit-a288a638b5d08b77e16a6679fa2de5653e434a13.tar.bz2
infinity-for-reddit-a288a638b5d08b77e16a6679fa2de5653e434a13.tar.lz
infinity-for-reddit-a288a638b5d08b77e16a6679fa2de5653e434a13.tar.xz
infinity-for-reddit-a288a638b5d08b77e16a6679fa2de5653e434a13.tar.zst
infinity-for-reddit-a288a638b5d08b77e16a6679fa2de5653e434a13.zip
Markdown in subreddit and user descriptions.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java19
3 files changed, 34 insertions, 4 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
index 1c4e340e..5203c567 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
@@ -9,6 +9,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
+import android.text.util.Linkify;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
@@ -64,6 +65,13 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
+import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
+import io.noties.markwon.inlineparser.BangInlineProcessor;
+import io.noties.markwon.inlineparser.HtmlInlineProcessor;
+import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
+import io.noties.markwon.linkify.LinkifyPlugin;
+import io.noties.markwon.movement.MovementMethodPlugin;
+import io.noties.markwon.recycler.table.TableEntryPlugin;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
@@ -99,6 +107,10 @@ import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
import ml.docilealligator.infinityforreddit.fragments.SidebarFragment;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
+import ml.docilealligator.infinityforreddit.markdown.RedditHeadingPlugin;
+import ml.docilealligator.infinityforreddit.markdown.SpoilerAwareMovementMethod;
+import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin;
+import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin;
import ml.docilealligator.infinityforreddit.message.ReadMessage;
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
import ml.docilealligator.infinityforreddit.post.Post;
@@ -387,8 +399,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
urlMenuBottomSheetFragment.show(getSupportFragmentManager(), null);
return true;
};
- Markwon markwon = MarkdownUtils.createLinksOnlyMarkwon(this,
- miscPlugin, onLinkLongClickListener);
+
+ Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener);
descriptionTextView.setOnLongClickListener(view -> {
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
index 84eb24ff..a9a2068c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
@@ -389,8 +389,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
urlMenuBottomSheetFragment.show(getSupportFragmentManager(), null);
return true;
};
- Markwon markwon = MarkdownUtils.createLinksOnlyMarkwon(this,
- miscPlugin, onLinkLongClickListener);
+ Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener);
descriptionTextView.setOnLongClickListener(view -> {
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
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 678e5a38..2c56fc9c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java
@@ -51,6 +51,25 @@ public class MarkdownUtils {
.build();
}
+ @NonNull
+ public static Markwon createDescriptionMarkwon(Context context, MarkwonPlugin miscPlugin,
+ BetterLinkMovementMethod.OnLinkLongClickListener onLinkLongClickListener) {
+ return Markwon.builder(context)
+ .usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
+ plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
+ plugin.excludeInlineProcessor(BangInlineProcessor.class);
+ }))
+ .usePlugin(miscPlugin)
+ .usePlugin(SuperscriptPlugin.create())
+ .usePlugin(RedditHeadingPlugin.create())
+ .usePlugin(StrikethroughPlugin.create())
+ .usePlugin(MovementMethodPlugin.create(new SpoilerAwareMovementMethod()
+ .setOnLinkLongClickListener(onLinkLongClickListener)))
+ .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
+ .usePlugin(TableEntryPlugin.create(context))
+ .build();
+ }
+
/**
* Creates a Markwon instance that processes only the links.
* @return configured Markwon instance