Skip to content

Commit b076361

Browse files
committed
Add Mastodon Redirect support and "Open Link" share target
1 parent 45d36a6 commit b076361

File tree

6 files changed

+89
-7
lines changed

6 files changed

+89
-7
lines changed

app/src/main/AndroidManifest.xml

+28-7
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,62 @@
4040
<activity
4141
android:name=".MainActivity"
4242
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout|smallestScreenSize"
43+
android:launchMode="singleTask"
4344
android:exported="true"
4445
android:theme="@style/SplashTheme">
45-
4646
<intent-filter>
4747
<action android:name="android.intent.action.MAIN" />
4848

4949
<category android:name="android.intent.category.LAUNCHER" />
5050
</intent-filter>
51-
<intent-filter>
51+
52+
<intent-filter android:label="@string/action_compose">
5253
<action android:name="android.intent.action.SEND" />
5354

5455
<category android:name="android.intent.category.DEFAULT" />
5556

5657
<data android:mimeType="text/plain" />
5758
</intent-filter>
58-
<intent-filter>
59+
<intent-filter android:label="@string/action_compose">
5960
<action android:name="android.intent.action.SEND" />
6061

6162
<category android:name="android.intent.category.DEFAULT" />
6263

6364
<data android:mimeType="image/*" />
6465
</intent-filter>
65-
<intent-filter>
66+
<intent-filter android:label="@string/action_compose">
6667
<action android:name="android.intent.action.SEND" />
6768

6869
<category android:name="android.intent.category.DEFAULT" />
6970

7071
<data android:mimeType="video/*" />
7172
</intent-filter>
72-
<intent-filter>
73+
<intent-filter android:label="@string/action_compose">
7374
<action android:name="android.intent.action.SEND_MULTIPLE" />
7475

7576
<category android:name="android.intent.category.DEFAULT" />
7677

7778
<data android:mimeType="image/*" />
7879
</intent-filter>
79-
<intent-filter>
80+
<intent-filter android:label="@string/action_compose">
8081
<action android:name="android.intent.action.SEND_MULTIPLE" />
8182

8283
<category android:name="android.intent.category.DEFAULT" />
8384

8485
<data android:mimeType="video/*" />
8586
</intent-filter>
86-
<intent-filter>
87+
<intent-filter android:label="@string/action_compose">
8788
<action android:name="android.intent.action.SEND" />
8889

8990
<category android:name="android.intent.category.DEFAULT" />
9091

9192
<data android:mimeType="audio/*" />
9293
</intent-filter>
94+
<intent-filter>
95+
<action android:name="dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK" />
96+
97+
<category android:name="android.intent.category.DEFAULT" />
98+
</intent-filter>
9399

94100
<meta-data
95101
android:name="android.app.shortcuts"
@@ -98,6 +104,21 @@
98104
android:name="android.service.chooser.chooser_target_service"
99105
android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
100106

107+
</activity>
108+
<activity
109+
android:name=".components.view.ViewLinkActivity"
110+
android:excludeFromRecents="true"
111+
android:exported="true"
112+
android:theme="@style/NullTheme">
113+
114+
<intent-filter android:label="@string/open_link">
115+
<action android:name="android.intent.action.SEND" />
116+
117+
<category android:name="android.intent.category.DEFAULT" />
118+
119+
<data android:mimeType="text/plain" />
120+
</intent-filter>
121+
101122
</activity>
102123
<activity
103124
android:name=".components.compose.ComposeActivity"

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

+16
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,17 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
531531
if (redirectUrl != null) {
532532
viewUrl(redirectUrl, PostLookupFallbackBehavior.DISPLAY_ERROR)
533533
}
534+
535+
handleMastodonRedirectIntent(intent)
534536
}
535537
}
536538

539+
override fun onNewIntent(intent: Intent?) {
540+
super.onNewIntent(intent)
541+
542+
handleMastodonRedirectIntent(intent)
543+
}
544+
537545
private fun forwardToComposeActivity(intent: Intent) {
538546
val composeOptions =
539547
intent.getParcelableExtraCompat<ComposeActivity.ComposeOptions>(COMPOSE_OPTIONS)
@@ -1201,6 +1209,14 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
12011209

12021210
override fun getActionButton() = binding.composeButton
12031211

1212+
private fun handleMastodonRedirectIntent(intent: Intent?) {
1213+
if (intent?.action == "dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK") {
1214+
intent.dataString?.let { url ->
1215+
viewUrl(url, PostLookupFallbackBehavior.OPEN_IN_BROWSER)
1216+
}
1217+
}
1218+
}
1219+
12041220
companion object {
12051221
const val OPEN_WITH_EXPLODE_ANIMATION = "explode"
12061222

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.keylesspalace.tusky.components.view
2+
3+
import android.content.Intent
4+
import android.net.Uri
5+
import android.os.Bundle
6+
import com.keylesspalace.tusky.BaseActivity
7+
import com.keylesspalace.tusky.MainActivity
8+
import dagger.hilt.android.AndroidEntryPoint
9+
10+
@AndroidEntryPoint
11+
class ViewLinkActivity : BaseActivity() {
12+
override fun onCreate(savedInstanceState: Bundle?) {
13+
super.onCreate(savedInstanceState)
14+
15+
if (intent?.action == Intent.ACTION_SEND) {
16+
val link = intent.getStringExtra(Intent.EXTRA_TEXT)
17+
18+
val launchIntent = Intent(this, MainActivity::class.java)
19+
launchIntent.action = "dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK"
20+
launchIntent.data = link?.let { Uri.parse(it) }
21+
22+
startActivity(launchIntent)
23+
finish()
24+
}
25+
}
26+
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ fun Context.openLink(url: String) {
311311
*/
312312
private fun openLinkInBrowser(uri: Uri?, context: Context) {
313313
val intent = Intent(Intent.ACTION_VIEW, uri)
314+
315+
// Makes sure the Intent opens in the browser instead of something like Mastodon Redirect.
316+
intent.selector = Intent(Intent.ACTION_VIEW, Uri.parse("https://"))
317+
314318
try {
315319
context.startActivity(intent)
316320
} catch (e: ActivityNotFoundException) {

app/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -853,5 +853,7 @@
853853
<string name="list_reply_policy_followed">Any followed user</string>
854854
<string name="list_reply_policy_label">Show replies to</string>
855855

856+
<string name="open_link">Open Link</string>
857+
856858
<string name="unknown_notification_type">Unknown notification type</string>
857859
</resources>

app/src/main/res/values/styles.xml

+13
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,17 @@
177177
<item name="android:layout_marginLeft">20dp</item>
178178
<item name="android:layout_marginRight">20dp</item>
179179
</style>
180+
181+
<style name="NullTheme" parent="Theme.Material3.DynamicColors.DayNight">
182+
<item name="android:windowIsTranslucent">true</item>
183+
<item name="android:windowBackground">@android:color/transparent</item>
184+
<item name="android:windowContentOverlay">@null</item>
185+
<item name="android:windowNoTitle">true</item>
186+
<item name="android:windowIsFloating">true</item>
187+
<item name="android:backgroundDimEnabled">false</item>
188+
<item name="android:windowEnterAnimation">@null</item>
189+
<item name="android:windowExitAnimation">@null</item>
190+
<item name="android:windowNoDisplay">true</item>
191+
<item name="android:windowActionBar">false</item>
192+
</style>
180193
</resources>

0 commit comments

Comments
 (0)