From dcb87a4bf7a55b9f5e9032969e1cf7090aa419fd Mon Sep 17 00:00:00 2001 From: Zachary Wander Date: Wed, 17 Jan 2024 23:21:43 -0500 Subject: [PATCH] Add Mastodon Redirect support and "Open Link" share target --- app/src/main/AndroidManifest.xml | 35 +++++++++++++++---- .../com/keylesspalace/tusky/MainActivity.kt | 16 +++++++++ .../tusky/components/view/ViewLinkActivity.kt | 26 ++++++++++++++ .../keylesspalace/tusky/util/LinkHelper.kt | 4 +++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/values/styles.xml | 13 +++++++ 6 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/keylesspalace/tusky/components/view/ViewLinkActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d2c9bc4404..7954d2376b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -40,56 +40,62 @@ - - + + - + - + - + - + - + + + + + + + + + + + + + + + + + (COMPOSE_OPTIONS) @@ -1201,6 +1209,14 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider { override fun getActionButton() = binding.composeButton + private fun handleMastodonRedirectIntent(intent: Intent?) { + if (intent?.action == "dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK") { + intent.dataString?.let { url -> + viewUrl(url, PostLookupFallbackBehavior.OPEN_IN_BROWSER) + } + } + } + companion object { const val OPEN_WITH_EXPLODE_ANIMATION = "explode" diff --git a/app/src/main/java/com/keylesspalace/tusky/components/view/ViewLinkActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/view/ViewLinkActivity.kt new file mode 100644 index 0000000000..c5fed7030d --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/components/view/ViewLinkActivity.kt @@ -0,0 +1,26 @@ +package com.keylesspalace.tusky.components.view + +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import com.keylesspalace.tusky.BaseActivity +import com.keylesspalace.tusky.MainActivity +import dagger.hilt.android.AndroidEntryPoint + +@AndroidEntryPoint +class ViewLinkActivity : BaseActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + if (intent?.action == Intent.ACTION_SEND) { + val link = intent.getStringExtra(Intent.EXTRA_TEXT) + + val launchIntent = Intent(this, MainActivity::class.java) + launchIntent.action = "dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK" + launchIntent.data = link?.let { Uri.parse(it) } + + startActivity(launchIntent) + finish() + } + } +} diff --git a/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt b/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt index 50d3ccfa77..eb4d637225 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt @@ -311,6 +311,10 @@ fun Context.openLink(url: String) { */ private fun openLinkInBrowser(uri: Uri?, context: Context) { val intent = Intent(Intent.ACTION_VIEW, uri) + + // Makes sure the Intent opens in the browser instead of something like Mastodon Redirect. + intent.selector = Intent(Intent.ACTION_VIEW, Uri.parse("https://")) + try { context.startActivity(intent) } catch (e: ActivityNotFoundException) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b648bc00e2..30a5288c20 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -853,5 +853,7 @@ Any followed user Show replies to + Open Link + Unknown notification type diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 8b061dcb97..2c947933f9 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -177,4 +177,17 @@ 20dp 20dp + +