Skip to content

Commit

Permalink
Add Mastodon Redirect support
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharee committed Dec 26, 2023
1 parent d2cb74b commit f1941db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout|smallestScreenSize"
android:launchMode="singleTask"
android:exported="true">

<intent-filter>
Expand Down Expand Up @@ -100,6 +101,12 @@
<data android:mimeType="audio/*" />
</intent-filter>

<intent-filter>
<action android:name="dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<meta-data
android:name="android.service.chooser.chooser_target_service"
android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,17 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
if (redirectUrl != null) {
viewUrl(redirectUrl, PostLookupFallbackBehavior.DISPLAY_ERROR)
}

handleMastodonRedirectIntent(intent)
}
}

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)

handleMastodonRedirectIntent(intent)
}

private fun forwardToComposeActivity(intent: Intent) {
val composeOptions = IntentCompat.getParcelableExtra(intent, COMPOSE_OPTIONS, ComposeActivity.ComposeOptions::class.java)

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

override fun androidInjector() = androidInjector

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 {
private const val TAG = "MainActivity" // logging tag
private const val DRAWER_ITEM_ADD_ACCOUNT: Long = -13
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,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) {
Expand Down

0 comments on commit f1941db

Please sign in to comment.