From 53bd8024de3f5378375d8dc4840f9a6eb89b1283 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 15 May 2022 10:00:46 +0200 Subject: [PATCH] Fix issues with long press --- .../fedilab/android/helper/CrossActionHelper.java | 4 ++-- .../app/fedilab/android/helper/SpannableHelper.java | 12 +++++++++--- .../fragment/timeline/FragmentMastodonTimeline.java | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/helper/CrossActionHelper.java b/app/src/main/java/app/fedilab/android/helper/CrossActionHelper.java index 4c6e3be1..560e72c6 100644 --- a/app/src/main/java/app/fedilab/android/helper/CrossActionHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/CrossActionHelper.java @@ -263,10 +263,10 @@ public class CrossActionHelper { /** * Fetch and federate the remote status */ - public static void fetchRemoteStatus(@NonNull Context context, @NonNull Account ownerAccount, Status targetedStatus, Callback callback) { + public static void fetchRemoteStatus(@NonNull Context context, @NonNull Account ownerAccount, String url, Callback callback) { MastodonSearchService mastodonSearchService = init(context, MainActivity.currentInstance); new Thread(() -> { - Call resultsCall = mastodonSearchService.search(ownerAccount.token, targetedStatus.url, null, "statuses", false, true, false, 0, null, null, 1); + Call resultsCall = mastodonSearchService.search(ownerAccount.token, url, null, "statuses", false, true, false, 0, null, null, 1); Results results = null; if (resultsCall != null) { try { diff --git a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java index d70ec631..d6e3942a 100644 --- a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java @@ -229,13 +229,17 @@ public class SpannableHelper { sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); sendIntent.putExtra(Intent.EXTRA_TEXT, url); sendIntent.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); + sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + Intent intentChooser = Intent.createChooser(sendIntent, context.getString(R.string.share_with)); + intentChooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intentChooser); alertDialog.dismiss(); }); popupLinksBinding.openOtherApp.setOnClickListener(v -> { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { context.startActivity(intent); } catch (Exception e) { @@ -289,7 +293,7 @@ public class SpannableHelper { Handler mainHandler = new Handler(context.getMainLooper()); String finalRedirect = redirect; Runnable myRunnable = () -> { - AlertDialog.Builder builder1 = new AlertDialog.Builder(context, Helper.dialogStyle()); + AlertDialog.Builder builder1 = new AlertDialog.Builder(view.getContext(), Helper.dialogStyle()); if (finalRedirect != null) { builder1.setMessage(context.getString(R.string.redirect_detected, url, finalRedirect)); builder1.setNegativeButton(R.string.copy_link, (dialog, which) -> { @@ -339,11 +343,12 @@ public class SpannableHelper { Matcher matcherLink = link.matcher(url); if (matcherLink.find() && !url.contains("medium.com")) { if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot - CrossActionHelper.fetchRemoteStatus(context, MainActivity.accountWeakReference.get(), status, new CrossActionHelper.Callback() { + CrossActionHelper.fetchRemoteStatus(context, MainActivity.accountWeakReference.get(), url, new CrossActionHelper.Callback() { @Override public void federatedStatus(Status status) { Intent intent = new Intent(context, ContextActivity.class); intent.putExtra(Helper.ARG_STATUS, status); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } @@ -365,6 +370,7 @@ public class SpannableHelper { Bundle b = new Bundle(); b.putSerializable(Helper.ARG_ACCOUNT, account); intent.putExtras(b); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } }); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 44f2dc0e..bfbe70cb 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -211,7 +211,9 @@ public class FragmentMastodonTimeline extends Fragment { } public void scrollToTop() { - binding.recyclerView.scrollToPosition(0); + if (binding != null) { + binding.recyclerView.scrollToPosition(0); + } } @Override