Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Commit f1941db

Browse files
committed
Add Mastodon Redirect support
1 parent d2cb74b commit f1941db

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<activity
5656
android:name=".MainActivity"
5757
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout|smallestScreenSize"
58+
android:launchMode="singleTask"
5859
android:exported="true">
5960

6061
<intent-filter>
@@ -100,6 +101,12 @@
100101
<data android:mimeType="audio/*" />
101102
</intent-filter>
102103

104+
<intent-filter>
105+
<action android:name="dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK" />
106+
107+
<category android:name="android.intent.category.DEFAULT" />
108+
</intent-filter>
109+
103110
<meta-data
104111
android:name="android.service.chooser.chooser_target_service"
105112
android:value="androidx.sharetarget.ChooserTargetServiceCompat" />

app/src/main/java/com/keylesspalace/tusky/MainActivity.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,17 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
499499
if (redirectUrl != null) {
500500
viewUrl(redirectUrl, PostLookupFallbackBehavior.DISPLAY_ERROR)
501501
}
502+
503+
handleMastodonRedirectIntent(intent)
502504
}
503505
}
504506

507+
override fun onNewIntent(intent: Intent?) {
508+
super.onNewIntent(intent)
509+
510+
handleMastodonRedirectIntent(intent)
511+
}
512+
505513
private fun forwardToComposeActivity(intent: Intent) {
506514
val composeOptions = IntentCompat.getParcelableExtra(intent, COMPOSE_OPTIONS, ComposeActivity.ComposeOptions::class.java)
507515

@@ -1139,6 +1147,14 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
11391147

11401148
override fun androidInjector() = androidInjector
11411149

1150+
private fun handleMastodonRedirectIntent(intent: Intent?) {
1151+
if (intent?.action == "dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK") {
1152+
intent.dataString?.let { url ->
1153+
viewUrl(url, PostLookupFallbackBehavior.OPEN_IN_BROWSER)
1154+
}
1155+
}
1156+
}
1157+
11421158
companion object {
11431159
private const val TAG = "MainActivity" // logging tag
11441160
private const val DRAWER_ITEM_ADD_ACCOUNT: Long = -13

app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ fun Context.openLink(url: String) {
281281
*/
282282
private fun openLinkInBrowser(uri: Uri?, context: Context) {
283283
val intent = Intent(Intent.ACTION_VIEW, uri)
284+
285+
// Makes sure the Intent opens in the browser instead of something like Mastodon Redirect.
286+
intent.selector = Intent(Intent.ACTION_VIEW, Uri.parse("https://"))
287+
284288
try {
285289
context.startActivity(intent)
286290
} catch (e: ActivityNotFoundException) {

0 commit comments

Comments
 (0)