Skip to content

Commit 183fb7e

Browse files
committed
Add Mastodon Redirect support and "Open Link" share target
1 parent 5174c00 commit 183fb7e

File tree

7 files changed

+92
-6
lines changed

7 files changed

+92
-6
lines changed

app/src/main/AndroidManifest.xml

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

60-
<intent-filter>
61+
<intent-filter android:label="@string/action_compose">
6162
<action android:name="android.intent.action.SEND" />
6263

6364
<category android:name="android.intent.category.DEFAULT" />
6465

6566
<data android:mimeType="text/plain" />
6667
</intent-filter>
67-
<intent-filter>
68+
<intent-filter android:label="@string/action_compose">
6869
<action android:name="android.intent.action.SEND" />
6970

7071
<category android:name="android.intent.category.DEFAULT" />
7172

7273
<data android:mimeType="image/*" />
7374
</intent-filter>
74-
<intent-filter>
75+
<intent-filter android:label="@string/action_compose">
7576
<action android:name="android.intent.action.SEND" />
7677

7778
<category android:name="android.intent.category.DEFAULT" />
7879

7980
<data android:mimeType="video/*" />
8081
</intent-filter>
81-
<intent-filter>
82+
<intent-filter android:label="@string/action_compose">
8283
<action android:name="android.intent.action.SEND_MULTIPLE" />
8384

8485
<category android:name="android.intent.category.DEFAULT" />
8586

8687
<data android:mimeType="image/*" />
8788
</intent-filter>
88-
<intent-filter>
89+
<intent-filter android:label="@string/action_compose">
8990
<action android:name="android.intent.action.SEND_MULTIPLE" />
9091

9192
<category android:name="android.intent.category.DEFAULT" />
9293

9394
<data android:mimeType="video/*" />
9495
</intent-filter>
95-
<intent-filter>
96+
<intent-filter android:label="@string/action_compose">
9697
<action android:name="android.intent.action.SEND" />
9798

9899
<category android:name="android.intent.category.DEFAULT" />
99100

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" />
106113

114+
</activity>
115+
<activity
116+
android:name=".components.view.ViewLinkActivity"
117+
android:excludeFromRecents="true"
118+
android:exported="true"
119+
android:theme="@style/NullTheme">
120+
121+
<intent-filter android:label="@string/open_link">
122+
<action android:name="android.intent.action.SEND" />
123+
124+
<category android:name="android.intent.category.DEFAULT" />
125+
126+
<data android:mimeType="text/plain" />
127+
</intent-filter>
128+
107129
</activity>
108130
<activity
109131
android:name=".components.compose.ComposeActivity"

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

+16
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,17 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
516516
if (redirectUrl != null) {
517517
viewUrl(redirectUrl, PostLookupFallbackBehavior.DISPLAY_ERROR)
518518
}
519+
520+
handleMastodonRedirectIntent(intent)
519521
}
520522
}
521523

524+
override fun onNewIntent(intent: Intent?) {
525+
super.onNewIntent(intent)
526+
527+
handleMastodonRedirectIntent(intent)
528+
}
529+
522530
private fun forwardToComposeActivity(intent: Intent) {
523531
val composeOptions = IntentCompat.getParcelableExtra(
524532
intent,
@@ -1185,6 +1193,14 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
11851193

11861194
override fun androidInjector() = androidInjector
11871195

1196+
private fun handleMastodonRedirectIntent(intent: Intent?) {
1197+
if (intent?.action == "dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK") {
1198+
intent.dataString?.let { url ->
1199+
viewUrl(url, PostLookupFallbackBehavior.OPEN_IN_BROWSER)
1200+
}
1201+
}
1202+
}
1203+
11881204
companion object {
11891205
private const val TAG = "MainActivity" // logging tag
11901206
private const val DRAWER_ITEM_ADD_ACCOUNT: Long = -13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 com.keylesspalace.tusky.di.Injectable
9+
10+
class ViewLinkActivity : BaseActivity(), Injectable {
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
14+
if (intent?.action == Intent.ACTION_SEND) {
15+
val link = intent.getStringExtra(Intent.EXTRA_TEXT)
16+
17+
val launchIntent = Intent(this, MainActivity::class.java)
18+
launchIntent.action = "dev.zwander.mastodonredirect.intent.action.OPEN_FEDI_LINK"
19+
launchIntent.data = link?.let { Uri.parse(it) }
20+
21+
startActivity(launchIntent)
22+
finish()
23+
}
24+
}
25+
}

app/src/main/java/com/keylesspalace/tusky/di/ActivitiesModule.kt

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import com.keylesspalace.tusky.components.report.ReportActivity
4141
import com.keylesspalace.tusky.components.scheduled.ScheduledStatusActivity
4242
import com.keylesspalace.tusky.components.search.SearchActivity
4343
import com.keylesspalace.tusky.components.trending.TrendingActivity
44+
import com.keylesspalace.tusky.components.view.ViewLinkActivity
4445
import com.keylesspalace.tusky.components.viewthread.ViewThreadActivity
4546
import dagger.Module
4647
import dagger.android.ContributesAndroidInjector
@@ -132,4 +133,7 @@ abstract class ActivitiesModule {
132133

133134
@ContributesAndroidInjector
134135
abstract fun contributesEditFilterActivity(): EditFilterActivity
136+
137+
@ContributesAndroidInjector
138+
abstract fun contributesViewLinkActivity(): ViewLinkActivity
135139
}

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

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

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

+2
Original file line numberDiff line numberDiff line change
@@ -862,4 +862,6 @@
862862
<string name="list_reply_policy_list">Members of the list</string>
863863
<string name="list_reply_policy_followed">Any followed user</string>
864864
<string name="list_reply_policy_label">Show replies to</string>
865+
866+
<string name="open_link">Open Link</string>
865867
</resources>

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

+13
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,17 @@
185185
<item name="android:layout_marginLeft">20dp</item>
186186
<item name="android:layout_marginRight">20dp</item>
187187
</style>
188+
189+
<style name="NullTheme" parent="Theme.Material3.DynamicColors.DayNight">
190+
<item name="android:windowIsTranslucent">true</item>
191+
<item name="android:windowBackground">@android:color/transparent</item>
192+
<item name="android:windowContentOverlay">@null</item>
193+
<item name="android:windowNoTitle">true</item>
194+
<item name="android:windowIsFloating">true</item>
195+
<item name="android:backgroundDimEnabled">false</item>
196+
<item name="android:windowEnterAnimation">@null</item>
197+
<item name="android:windowExitAnimation">@null</item>
198+
<item name="android:windowNoDisplay">true</item>
199+
<item name="android:windowActionBar">false</item>
200+
</style>
188201
</resources>

0 commit comments

Comments
 (0)