From d31940a290b0975d1c7d8c023545caddeba5f6bd Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Sun, 8 Mar 2020 13:19:03 +0300 Subject: [PATCH] Pull from origin (linkify compat) --- CHANGELOG.md | 4 ++++ .../io/noties/markwon/linkify/LinkifyPlugin.java | 4 ++++ .../markwon/sample/images/ImagesActivity.java | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc89ffae..c2711cc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,11 +19,15 @@ * add `option` abstraction for `sample` module allowing switching of multiple cases in runtime via menu * non-empty bounds for `AsyncDrawable` when no dimensions are not yet available ([#189]) * `JLatexMathPlugin` add text color customization ([#207]) +* `linkify` - option to use `LinkifyCompat` in `LinkifyPlugin` ([#201]) +
Thanks to [@drakeet] [#189]: https://github.com/noties/Markwon/issues/189 [#75]: https://github.com/noties/Markwon/issues/75 [#204]: https://github.com/noties/Markwon/issues/204 [#207]: https://github.com/noties/Markwon/issues/207 +[#201]: https://github.com/noties/Markwon/issues/201 +[@drakeet]: https://github.com/drakeet # 4.2.2 diff --git a/markwon-linkify/src/main/java/io/noties/markwon/linkify/LinkifyPlugin.java b/markwon-linkify/src/main/java/io/noties/markwon/linkify/LinkifyPlugin.java index a910d970..ec087741 100644 --- a/markwon-linkify/src/main/java/io/noties/markwon/linkify/LinkifyPlugin.java +++ b/markwon-linkify/src/main/java/io/noties/markwon/linkify/LinkifyPlugin.java @@ -42,6 +42,7 @@ public class LinkifyPlugin extends AbstractMarkwonPlugin { * @param useCompat If true, use {@link LinkifyCompat} to handle links. * Note that the {@link LinkifyCompat} depends on androidx.core:core, * the dependency must be added on a client side explicitly. + * @since 4.3.0-SNAPSHOT `useCompat` argument */ @NonNull public static LinkifyPlugin create(boolean useCompat) { @@ -57,6 +58,7 @@ public class LinkifyPlugin extends AbstractMarkwonPlugin { * @param useCompat If true, use {@link LinkifyCompat} to handle links. * Note that the {@link LinkifyCompat} depends on androidx.core:core, * the dependency must be added on a client side explicitly. + * @since 4.3.0-SNAPSHOT `useCompat` argument */ @NonNull public static LinkifyPlugin create(@LinkifyMask int mask, boolean useCompat) { @@ -78,6 +80,7 @@ public class LinkifyPlugin extends AbstractMarkwonPlugin { @Override public void apply(@NonNull CorePlugin corePlugin) { final LinkifyTextAddedListener listener; + // @since 4.3.0-SNAPSHOT if (useCompat) { listener = new LinkifyCompatTextAddedListener(mask); } else { @@ -137,6 +140,7 @@ public class LinkifyPlugin extends AbstractMarkwonPlugin { } } + // @since 4.3.0-SNAPSHOT private static class LinkifyCompatTextAddedListener extends LinkifyTextAddedListener { LinkifyCompatTextAddedListener(int mask) { diff --git a/sample/src/main/java/io/noties/markwon/sample/images/ImagesActivity.java b/sample/src/main/java/io/noties/markwon/sample/images/ImagesActivity.java index dd4a44dc..6206a2c4 100644 --- a/sample/src/main/java/io/noties/markwon/sample/images/ImagesActivity.java +++ b/sample/src/main/java/io/noties/markwon/sample/images/ImagesActivity.java @@ -3,6 +3,7 @@ package io.noties.markwon.sample.images; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.text.method.LinkMovementMethod; import android.widget.TextView; import androidx.annotation.NonNull; @@ -14,6 +15,7 @@ import com.bumptech.glide.request.target.Target; import io.noties.markwon.Markwon; import io.noties.markwon.image.AsyncDrawable; +import io.noties.markwon.image.ImagesPlugin; import io.noties.markwon.image.glide.GlideImagesPlugin; import io.noties.markwon.sample.ActivityWithMenuOptions; import io.noties.markwon.sample.MenuOptions; @@ -29,7 +31,8 @@ public class ImagesActivity extends ActivityWithMenuOptions { // todo: same for other plugins return MenuOptions.create() .add("glide-singleImage", this::glideSingleImage) - .add("glide-singleImageWithPlaceholder", this::glideSingleImageWithPlaceholder); + .add("glide-singleImageWithPlaceholder", this::glideSingleImageWithPlaceholder) + .add("click", this::click); } @Override @@ -82,4 +85,15 @@ public class ImagesActivity extends ActivityWithMenuOptions { markwon.setMarkdown(textView, md); } + + private void click() { + + textView.setMovementMethod(LinkMovementMethod.getInstance()); + + final String md = "[![markdown](https://www.mdeditor.com/images/logos/markdown.png \"markdown\")](https://www.mdeditor.com/images/logos/markdown.png)"; + final Markwon markwon = Markwon.builder(this) + .usePlugin(ImagesPlugin.create()) + .build(); + markwon.setMarkdown(textView, md); + } }