Pull from origin (linkify compat)

This commit is contained in:
Dimitry Ivanov 2020-03-08 13:19:03 +03:00
parent 20d2bebd2b
commit d31940a290
3 changed files with 23 additions and 1 deletions

View File

@ -19,11 +19,15 @@
* add `option` abstraction for `sample` module allowing switching of multiple cases in runtime via menu * 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]) * non-empty bounds for `AsyncDrawable` when no dimensions are not yet available ([#189])
* `JLatexMathPlugin` add text color customization ([#207]) * `JLatexMathPlugin` add text color customization ([#207])
* `linkify` - option to use `LinkifyCompat` in `LinkifyPlugin` ([#201])
<br>Thanks to [@drakeet]
[#189]: https://github.com/noties/Markwon/issues/189 [#189]: https://github.com/noties/Markwon/issues/189
[#75]: https://github.com/noties/Markwon/issues/75 [#75]: https://github.com/noties/Markwon/issues/75
[#204]: https://github.com/noties/Markwon/issues/204 [#204]: https://github.com/noties/Markwon/issues/204
[#207]: https://github.com/noties/Markwon/issues/207 [#207]: https://github.com/noties/Markwon/issues/207
[#201]: https://github.com/noties/Markwon/issues/201
[@drakeet]: https://github.com/drakeet
# 4.2.2 # 4.2.2

View File

@ -42,6 +42,7 @@ public class LinkifyPlugin extends AbstractMarkwonPlugin {
* @param useCompat If true, use {@link LinkifyCompat} to handle links. * @param useCompat If true, use {@link LinkifyCompat} to handle links.
* Note that the {@link LinkifyCompat} depends on androidx.core:core, * Note that the {@link LinkifyCompat} depends on androidx.core:core,
* the dependency must be added on a client side explicitly. * the dependency must be added on a client side explicitly.
* @since 4.3.0-SNAPSHOT `useCompat` argument
*/ */
@NonNull @NonNull
public static LinkifyPlugin create(boolean useCompat) { 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. * @param useCompat If true, use {@link LinkifyCompat} to handle links.
* Note that the {@link LinkifyCompat} depends on androidx.core:core, * Note that the {@link LinkifyCompat} depends on androidx.core:core,
* the dependency must be added on a client side explicitly. * the dependency must be added on a client side explicitly.
* @since 4.3.0-SNAPSHOT `useCompat` argument
*/ */
@NonNull @NonNull
public static LinkifyPlugin create(@LinkifyMask int mask, boolean useCompat) { public static LinkifyPlugin create(@LinkifyMask int mask, boolean useCompat) {
@ -78,6 +80,7 @@ public class LinkifyPlugin extends AbstractMarkwonPlugin {
@Override @Override
public void apply(@NonNull CorePlugin corePlugin) { public void apply(@NonNull CorePlugin corePlugin) {
final LinkifyTextAddedListener listener; final LinkifyTextAddedListener listener;
// @since 4.3.0-SNAPSHOT
if (useCompat) { if (useCompat) {
listener = new LinkifyCompatTextAddedListener(mask); listener = new LinkifyCompatTextAddedListener(mask);
} else { } else {
@ -137,6 +140,7 @@ public class LinkifyPlugin extends AbstractMarkwonPlugin {
} }
} }
// @since 4.3.0-SNAPSHOT
private static class LinkifyCompatTextAddedListener extends LinkifyTextAddedListener { private static class LinkifyCompatTextAddedListener extends LinkifyTextAddedListener {
LinkifyCompatTextAddedListener(int mask) { LinkifyCompatTextAddedListener(int mask) {

View File

@ -3,6 +3,7 @@ package io.noties.markwon.sample.images;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -14,6 +15,7 @@ import com.bumptech.glide.request.target.Target;
import io.noties.markwon.Markwon; import io.noties.markwon.Markwon;
import io.noties.markwon.image.AsyncDrawable; import io.noties.markwon.image.AsyncDrawable;
import io.noties.markwon.image.ImagesPlugin;
import io.noties.markwon.image.glide.GlideImagesPlugin; import io.noties.markwon.image.glide.GlideImagesPlugin;
import io.noties.markwon.sample.ActivityWithMenuOptions; import io.noties.markwon.sample.ActivityWithMenuOptions;
import io.noties.markwon.sample.MenuOptions; import io.noties.markwon.sample.MenuOptions;
@ -29,7 +31,8 @@ public class ImagesActivity extends ActivityWithMenuOptions {
// todo: same for other plugins // todo: same for other plugins
return MenuOptions.create() return MenuOptions.create()
.add("glide-singleImage", this::glideSingleImage) .add("glide-singleImage", this::glideSingleImage)
.add("glide-singleImageWithPlaceholder", this::glideSingleImageWithPlaceholder); .add("glide-singleImageWithPlaceholder", this::glideSingleImageWithPlaceholder)
.add("click", this::click);
} }
@Override @Override
@ -82,4 +85,15 @@ public class ImagesActivity extends ActivityWithMenuOptions {
markwon.setMarkdown(textView, md); 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);
}
} }