From d1aa3df4a7ccf6d2131dbd80f95590913f32d2f0 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 4 Jan 2021 14:42:04 +0800 Subject: Long press a url to see options in CommentsListingRecyclerViewAdapter. --- .../CommentAndPostRecyclerViewAdapter.java | 5 -- .../CommentsListingRecyclerViewAdapter.java | 69 ++++++++++++---------- .../fragments/CommentsListingFragment.java | 6 +- 3 files changed, 42 insertions(+), 38 deletions(-) (limited to 'app/src') 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 8fa48204..25f82e1e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -14,7 +14,6 @@ import android.os.Bundle; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextPaint; -import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.text.style.SuperscriptSpan; import android.text.util.Linkify; @@ -321,7 +320,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) { - // do your code here this will only call if its not a hyperlink Bundle bundle = new Bundle(); bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, mPost.getSelfTextPlain()); bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, mPost.getSelfText()); @@ -3705,8 +3703,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter hideToolbar(); @@ -3742,7 +3738,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { @@ -77,7 +78,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { - Intent intent = new Intent(mContext, LinkResolverActivity.class); + Intent intent = new Intent(mActivity, LinkResolverActivity.class); Uri uri = Uri.parse(link); intent.setData(uri); - mContext.startActivity(intent); + mActivity.startActivity(intent); }); } }) + .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 -> @@ -260,7 +271,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { int position = getAdapterPosition(); if (position < 0) { @@ -483,13 +492,13 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { if (mAccessToken == null) { - Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } @@ -570,7 +579,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { if (mAccessToken == null) { - Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } @@ -636,7 +645,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter