From eb381eb3f4b2eb90cd3953fdca85902966228b1c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 4 Jan 2021 14:34:10 +0800 Subject: [PATCH] Long click a url link in comments to see options. --- .../CommentAndPostRecyclerViewAdapter.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index e42058b5..8fa48204 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -18,7 +18,6 @@ import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.text.style.SuperscriptSpan; import android.text.util.Linkify; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -445,6 +444,16 @@ public class CommentAndPostRecyclerViewAdapter 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(SimpleExtPlugin.create(plugin -> plugin.addExtension(1, '^', (configuration, props) -> { @@ -3722,9 +3731,16 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter expandComments(); - commentMarkdownView.setOnLongClickListener(expandsCommentsOnLongClickListener); - itemView.setOnLongClickListener(expandsCommentsOnLongClickListener); + commentMarkdownView.setOnLongClickListener(view -> { + if (commentMarkdownView.getSelectionStart() == -1 && commentMarkdownView.getSelectionEnd() == -1) { + expandComments(); + } + return true; + }); + itemView.setOnLongClickListener(view -> { + expandComments(); + return true; + }); } commentMarkdownView.setMovementMethod(LinkMovementMethod.getInstance()); commentMarkdownView.setHighlightColor(Color.TRANSPARENT);