Skip to content

Commit 0287d66

Browse files
authored
Merge pull request #1626 from DimensionDev/feature/deeplink_enhance
deeplink enhance
2 parents da5e98d + ee9daaa commit 0287d66

File tree

5 files changed

+214
-36
lines changed

5 files changed

+214
-36
lines changed

app/build.gradle.kts

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ android {
3737
applicationId = "dev.dimension.flare"
3838
minSdk = libs.versions.minSdk.get().toInt()
3939
targetSdk = libs.versions.compileSdk.get().toInt()
40-
versionCode = System.getenv("BUILD_NUMBER")?.toIntOrNull() ?: fdroidProp.getProperty("versionCode")?.toIntOrNull() ?: 1
41-
versionName = System.getenv("BUILD_VERSION")?.toString() ?: fdroidProp.getProperty("versionName")?.toString() ?: "0.0.0"
40+
versionCode =
41+
System.getenv("BUILD_NUMBER")?.toIntOrNull() ?: fdroidProp.getProperty("versionCode")
42+
?.toIntOrNull() ?: 1
43+
versionName =
44+
System.getenv("BUILD_VERSION")?.toString() ?: fdroidProp.getProperty("versionName")
45+
?.toString() ?: "0.0.0"
4246

4347
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
4448
vectorDrawables {
@@ -188,3 +192,57 @@ if (project.file("google-services.json").exists()) {
188192
uploadCrashlyticsMappingFileRelease.dependsOn(processDebugGoogleServices)
189193
}
190194
}
195+
196+
197+
abstract class GenerateDeepLinkManifestTask : DefaultTask() {
198+
@get:InputFile
199+
@get:PathSensitive(PathSensitivity.RELATIVE)
200+
abstract val hostsFile: RegularFileProperty
201+
@get:OutputFile
202+
abstract val manifest: RegularFileProperty
203+
204+
@TaskAction
205+
fun run() {
206+
val hosts = hostsFile.get().asFile.readLines()
207+
.map { it.trim() }
208+
.filter { it.isNotEmpty() && !it.startsWith("#") }
209+
.distinct()
210+
val dataTags = hosts.joinToString("\n") { host ->
211+
"""<data android:host="$host" />"""
212+
}
213+
214+
manifest.get().asFile.writeText(
215+
"""
216+
<?xml version="1.0" encoding="utf-8"?>
217+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
218+
<application>
219+
<activity android:name="dev.dimension.flare.MainActivity" android:exported="true">
220+
<intent-filter android:autoVerify="false">
221+
<action android:name="android.intent.action.VIEW"/>
222+
<category android:name="android.intent.category.DEFAULT"/>
223+
<category android:name="android.intent.category.BROWSABLE"/>
224+
<data android:scheme="https" />
225+
$dataTags
226+
</intent-filter>
227+
</activity>
228+
</application>
229+
</manifest>
230+
""".trimIndent()
231+
)
232+
}
233+
}
234+
235+
extensions.getByType(com.android.build.api.variant.AndroidComponentsExtension::class.java)
236+
.onVariants { variant: com.android.build.api.variant.Variant ->
237+
val t = tasks.register(
238+
"generate${variant.name.replaceFirstChar { it.uppercase() }}DeepLinkManifest",
239+
GenerateDeepLinkManifestTask::class.java
240+
) {
241+
hostsFile = project.layout.projectDirectory.file("deeplink.txt")
242+
}
243+
244+
variant.sources.manifests.addGeneratedManifestFile(
245+
t,
246+
GenerateDeepLinkManifestTask::manifest
247+
)
248+
}

app/deeplink.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
x.com
2+
twitter.com
3+
bsky.app
4+
pawoo.net
5+
mastodon.social
6+
misskey.io
7+
next.misskey.io
8+
mstdn.jp
9+
mstdn.social
10+
mastodon.world
11+
mastodon.sdf.org
12+
universeodon.com
13+
techhub.social
14+
mastodonapp.uk
15+
mastodon.uno
16+
m.cmx.im
17+
mstdn.party
18+
infosec.exchange
19+
hachyderm.io
20+
sfba.social
21+
misskey.design
22+
ohai.social
23+
mastodon.nl
24+
troet.cafe

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<activity
2828
android:windowSoftInputMode="adjustResize"
2929
android:launchMode="singleTask"
30-
android:name=".MainActivity"
30+
android:name="dev.dimension.flare.MainActivity"
3131
android:exported="true"
3232
android:theme="@style/Theme.Flare.Starting">
3333
<intent-filter>
@@ -41,17 +41,6 @@
4141
<category android:name="android.intent.category.DEFAULT" />
4242
<category android:name="android.intent.category.BROWSABLE" />
4343
</intent-filter>
44-
<intent-filter android:autoVerify="false">
45-
<action android:name="android.intent.action.VIEW" />
46-
<data android:scheme="https" />
47-
<data android:host="x.com" />
48-
<data android:host="twitter.com" />
49-
<data android:host="www.x.com" />
50-
<data android:host="www.twitter.com" />
51-
52-
<category android:name="android.intent.category.DEFAULT" />
53-
<category android:name="android.intent.category.BROWSABLE" />
54-
</intent-filter>
5544
<meta-data android:name="android.app.shortcuts"
5645
android:resource="@xml/shortcuts" />
5746
</activity>

shared/src/commonMain/kotlin/dev/dimension/flare/common/deeplink/DeepLinkMapping.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ internal object DeepLinkMapping {
5050
statusKey = MicroBlogKey(id, accountKey.host),
5151
)
5252
}
53+
54+
@Serializable
55+
data class PostMedia(
56+
val handle: String,
57+
val id: String,
58+
val index: Int,
59+
) : Type {
60+
override fun deepLink(accountKey: MicroBlogKey): DeeplinkRoute =
61+
DeeplinkRoute.Media.StatusMedia(
62+
accountType = AccountType.Specific(accountKey),
63+
statusKey = MicroBlogKey(id, accountKey.host),
64+
index = index,
65+
preview = null,
66+
)
67+
}
5368
}
5469

5570
fun generatePattern(
@@ -111,6 +126,13 @@ internal object DeepLinkMapping {
111126
"https://www.$xqtHost/{handle}/status/{id}",
112127
"https://www.$xqtOldHost/{handle}/",
113128
)
129+
val media =
130+
listOf(
131+
"https://$xqtHost/{handle}/status/{id}/photo/{index}",
132+
"https://$xqtOldHost/{handle}/status/{id}/photo/{index}",
133+
"https://www.$xqtHost/{handle}/status/{id}/photo/{index}",
134+
"https://www.$xqtOldHost/{handle}/status/{id}/photo/{index}",
135+
)
114136
profile.map {
115137
DeepLinkPattern(
116138
Type.Profile.serializer(),
@@ -122,6 +144,12 @@ internal object DeepLinkMapping {
122144
Type.Post.serializer(),
123145
Url(it),
124146
)
147+
} +
148+
media.map {
149+
DeepLinkPattern(
150+
Type.PostMedia.serializer(),
151+
Url(it),
152+
)
125153
}
126154
}
127155

0 commit comments

Comments
 (0)