diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-01-04 06:55:42 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-01-04 06:55:42 +0000 |
commit | 9830db0303928f0a873da0d6c59616e22912b15d (patch) | |
tree | 42beb94a764ab3382fa264598852272063de76cf /app/src/main/java/ml | |
parent | d1aa3df4a7ccf6d2131dbd80f95590913f32d2f0 (diff) | |
download | infinity-for-reddit-9830db0303928f0a873da0d6c59616e22912b15d.tar infinity-for-reddit-9830db0303928f0a873da0d6c59616e22912b15d.tar.gz infinity-for-reddit-9830db0303928f0a873da0d6c59616e22912b15d.tar.bz2 infinity-for-reddit-9830db0303928f0a873da0d6c59616e22912b15d.tar.lz infinity-for-reddit-9830db0303928f0a873da0d6c59616e22912b15d.tar.xz infinity-for-reddit-9830db0303928f0a873da0d6c59616e22912b15d.tar.zst infinity-for-reddit-9830db0303928f0a873da0d6c59616e22912b15d.zip |
Long press a url to see options in RulesRecyclerViewAdapter.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java | 28 |
1 files changed, 21 insertions, 7 deletions
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 337a15d6..5f7fd8e0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -1,8 +1,8 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.Bundle; import android.text.style.SuperscriptSpan; import android.text.util.Linkify; import android.view.LayoutInflater; @@ -11,6 +11,7 @@ import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; @@ -23,11 +24,14 @@ import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.linkify.LinkifyPlugin; +import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.simple.ext.SimpleExtPlugin; -import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Rule; +import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecyclerViewAdapter.RuleViewHolder> { private Markwon markwon; @@ -35,16 +39,16 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler private int mPrimaryTextColor; private int mSecondaryTextColor; - public RulesRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper) { - markwon = Markwon.builder(context) + public RulesRecyclerViewAdapter(AppCompatActivity activity, CustomThemeWrapper customThemeWrapper) { + markwon = Markwon.builder(activity) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { - Intent intent = new Intent(context, LinkResolverActivity.class); + Intent intent = new Intent(activity, LinkResolverActivity.class); Uri uri = Uri.parse(link); intent.setData(uri); - context.startActivity(intent); + activity.startActivity(intent); }); } @@ -53,6 +57,16 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler builder.linkColor(customThemeWrapper.getLinkColor()); } }) + .usePlugin(MovementMethodPlugin.create(BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, activity).setOnLinkLongClickListener((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; + }))) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(StrikethroughPlugin.create()) .usePlugin(SimpleExtPlugin.create(plugin -> |