From 9830db0303928f0a873da0d6c59616e22912b15d Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 4 Jan 2021 14:55:42 +0800 Subject: Long press a url to see options in RulesRecyclerViewAdapter. --- .../adapters/RulesRecyclerViewAdapter.java | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'app/src/main/java') 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 { private Markwon markwon; @@ -35,16 +39,16 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { - 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 { + 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 -> -- cgit v1.2.3