From e8a28bc7c8e94e9c4055dad5d4b6a78b739b6e19 Mon Sep 17 00:00:00 2001 From: Zachary Wander Date: Tue, 26 Dec 2023 11:24:48 -0500 Subject: [PATCH] Add Mastodon Redirect support and "Open Link" share target --- app/src/main/AndroidManifest.xml | 34 +++++++++++++++---- .../com/keylesspalace/tusky/MainActivity.kt | 16 +++++++++ .../tusky/components/view/ViewLinkActivity.kt | 25 ++++++++++++++ .../tusky/di/ActivitiesModule.kt | 4 +++ .../keylesspalace/tusky/util/LinkHelper.kt | 4 +++ .../tusky/view/ClickableSpanTextView.kt | 6 ++-- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/values/styles.xml | 13 +++++++ 8 files changed, 95 insertions(+), 9 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 8c03d7a9b4..0e59a16a29 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -55,44 +55,45 @@ - + - + - + - + - + - + @@ -100,10 +101,31 @@ + + + + + + + + + + + + + + + + + + viewUrl(url, PostLookupFallbackBehavior.OPEN_IN_BROWSER) + } + } + } + companion object { private const val TAG = "MainActivity" // logging tag private const val DRAWER_ITEM_ADD_ACCOUNT: Long = -13 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..bce0a9a04b --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/components/view/ViewLinkActivity.kt @@ -0,0 +1,25 @@ +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 com.keylesspalace.tusky.di.Injectable + +class ViewLinkActivity : BaseActivity(), Injectable { + 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/di/ActivitiesModule.kt b/app/src/main/java/com/keylesspalace/tusky/di/ActivitiesModule.kt index a8fe4b9b61..23889222d6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/di/ActivitiesModule.kt +++ b/app/src/main/java/com/keylesspalace/tusky/di/ActivitiesModule.kt @@ -41,6 +41,7 @@ import com.keylesspalace.tusky.components.report.ReportActivity import com.keylesspalace.tusky.components.scheduled.ScheduledStatusActivity import com.keylesspalace.tusky.components.search.SearchActivity import com.keylesspalace.tusky.components.trending.TrendingActivity +import com.keylesspalace.tusky.components.view.ViewLinkActivity import com.keylesspalace.tusky.components.viewthread.ViewThreadActivity import dagger.Module import dagger.android.ContributesAndroidInjector @@ -132,4 +133,7 @@ abstract class ActivitiesModule { @ContributesAndroidInjector abstract fun contributesEditFilterActivity(): EditFilterActivity + + @ContributesAndroidInjector + abstract fun contributesViewLinkActivity(): ViewLinkActivity } 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 ed38db1d11..672c9fb3fa 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt @@ -313,6 +313,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/java/com/keylesspalace/tusky/view/ClickableSpanTextView.kt b/app/src/main/java/com/keylesspalace/tusky/view/ClickableSpanTextView.kt index a5d65716ff..bf59c1e0ff 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/ClickableSpanTextView.kt +++ b/app/src/main/java/com/keylesspalace/tusky/view/ClickableSpanTextView.kt @@ -399,10 +399,10 @@ class ClickableSpanTextView @JvmOverloads constructor( /** * A [Path] that records the contents of all the [addRect] calls it receives. * - * @param rects list to record the received [RectF] + * @param recorded list to record the received [RectF] */ -private class RectRecordingPath(private val rects: MutableList) : Path() { +private class RectRecordingPath(private val recorded: MutableList) : Path() { override fun addRect(left: Float, top: Float, right: Float, bottom: Float, dir: Direction) { - rects.add(RectF(left, top, right, bottom)) + recorded.add(RectF(left, top, right, bottom)) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a78ad7ad2e..0e439953c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -862,4 +862,6 @@ Members of the list Any followed user Show replies to + + Open Link diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5115cb15da..a683ad68c5 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -185,4 +185,17 @@ 20dp 20dp + +