From 6082a0bcd8faafa7880376bc91aeb7bdbe8b1eff Mon Sep 17 00:00:00 2001 From: Grishka Date: Wed, 30 Oct 2024 14:27:44 +0300 Subject: [PATCH] Provide URLs for the link button thing in system app switcher closes #632 --- .../java/org/joinmastodon/android/MainActivity.java | 9 +++++++++ .../fragments/AssistContentProviderFragment.java | 7 +++++++ .../joinmastodon/android/fragments/HomeFragment.java | 10 +++++++++- .../android/fragments/ProfileFragment.java | 10 +++++++++- .../joinmastodon/android/fragments/ThreadFragment.java | 9 ++++++++- 5 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 mastodon/src/main/java/org/joinmastodon/android/fragments/AssistContentProviderFragment.java diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java index 0fc11997..3afb33db 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java @@ -3,6 +3,7 @@ package org.joinmastodon.android; import android.Manifest; import android.app.Application; import android.app.Fragment; +import android.app.assist.AssistContent; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; @@ -16,6 +17,7 @@ import org.joinmastodon.android.api.ObjectValidationException; import org.joinmastodon.android.api.requests.search.GetSearchResults; import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; +import org.joinmastodon.android.fragments.AssistContentProviderFragment; import org.joinmastodon.android.fragments.ComposeFragment; import org.joinmastodon.android.fragments.HomeFragment; import org.joinmastodon.android.fragments.ProfileFragment; @@ -229,4 +231,11 @@ public class MainActivity extends FragmentStackActivity{ return null; return getFragmentManager().findFragmentById(fragmentContainers.get(fragmentContainers.size()-1).getId()); } + + @Override + public void onProvideAssistContent(AssistContent outContent){ + if(getTopmostFragment() instanceof AssistContentProviderFragment provider){ + provider.onProvideAssistContent(outContent); + } + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/AssistContentProviderFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/AssistContentProviderFragment.java new file mode 100644 index 00000000..d69c12d7 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/AssistContentProviderFragment.java @@ -0,0 +1,7 @@ +package org.joinmastodon.android.fragments; + +import android.app.assist.AssistContent; + +public interface AssistContentProviderFragment{ + void onProvideAssistContent(AssistContent content); +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java index 59b2f998..339909da 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java @@ -3,6 +3,7 @@ package org.joinmastodon.android.fragments; import android.annotation.SuppressLint; import android.app.Fragment; import android.app.NotificationManager; +import android.app.assist.AssistContent; import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; @@ -57,7 +58,7 @@ import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.FragmentRootLinearLayout; -public class HomeFragment extends AppKitFragment{ +public class HomeFragment extends AppKitFragment implements AssistContentProviderFragment{ private FragmentRootLinearLayout content; private HomeTimelineFragment homeTimelineFragment; private NotificationsListFragment notificationsFragment; @@ -379,4 +380,11 @@ public class HomeFragment extends AppKitFragment{ if(notificationsFragment.loaded) notificationsFragment.rebuildAllDisplayItems(); } + + @Override + public void onProvideAssistContent(AssistContent content){ + if(fragmentForTab(currentTab) instanceof AssistContentProviderFragment provider){ + provider.onProvideAssistContent(content); + } + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index 32ff80be..ef44a95f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -6,6 +6,7 @@ import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.app.Activity; import android.app.Fragment; +import android.app.assist.AssistContent; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Intent; @@ -108,7 +109,7 @@ import me.grishka.appkit.utils.CubicBezierInterpolator; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.FragmentRootLinearLayout; -public class ProfileFragment extends LoaderFragment implements ScrollableToTop{ +public class ProfileFragment extends LoaderFragment implements ScrollableToTop, AssistContentProviderFragment{ private static final int AVATAR_RESULT=722; private static final int COVER_RESULT=343; @@ -1218,6 +1219,13 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop{ return actionButton.getVisibility()==View.VISIBLE && actionButtonWrap.getTop()+actionButtonWrap.getHeight()>scrollView.getScrollY(); } + @Override + public void onProvideAssistContent(AssistContent content){ + if(account!=null){ + content.setWebUri(Uri.parse(account.url)); + } + } + private class ProfilePagerAdapter extends RecyclerView.Adapter{ @NonNull @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java index f1ef52f7..9a8d0645 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java @@ -1,8 +1,10 @@ package org.joinmastodon.android.fragments; +import android.app.assist.AssistContent; import android.content.res.ColorStateList; import android.graphics.Canvas; import android.graphics.Paint; +import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import android.view.View; @@ -46,7 +48,7 @@ import me.grishka.appkit.utils.MergeRecyclerAdapter; import me.grishka.appkit.utils.SingleViewRecyclerAdapter; import me.grishka.appkit.utils.V; -public class ThreadFragment extends StatusListFragment{ +public class ThreadFragment extends StatusListFragment implements AssistContentProviderFragment{ private Status mainStatus; private ImageView endMark; private FrameLayout replyContainer; @@ -260,6 +262,11 @@ public class ThreadFragment extends StatusListFragment{ return null; } + @Override + public void onProvideAssistContent(AssistContent content){ + content.setWebUri(Uri.parse(mainStatus.url)); + } + private class ReplyLinesItemDecoration extends RecyclerView.ItemDecoration{ private Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);