Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ android {
applicationId = "dev.dimension.flare"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.compileSdk.get().toInt()
versionCode = System.getenv("BUILD_NUMBER")?.toIntOrNull() ?: fdroidProp.getProperty("versionCode")?.toIntOrNull() ?: 1
versionName = System.getenv("BUILD_VERSION")?.toString() ?: fdroidProp.getProperty("versionName")?.toString() ?: "0.0.0"
versionCode =
System.getenv("BUILD_NUMBER")?.toIntOrNull() ?: fdroidProp.getProperty("versionCode")
?.toIntOrNull() ?: 1
versionName =
System.getenv("BUILD_VERSION")?.toString() ?: fdroidProp.getProperty("versionName")
?.toString() ?: "0.0.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -188,3 +192,57 @@ if (project.file("google-services.json").exists()) {
uploadCrashlyticsMappingFileRelease.dependsOn(processDebugGoogleServices)
}
}


abstract class GenerateDeepLinkManifestTask : DefaultTask() {
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val hostsFile: RegularFileProperty
@get:OutputFile
abstract val manifest: RegularFileProperty

@TaskAction
fun run() {
val hosts = hostsFile.get().asFile.readLines()
.map { it.trim() }
.filter { it.isNotEmpty() && !it.startsWith("#") }
.distinct()
val dataTags = hosts.joinToString("\n") { host ->
"""<data android:host="$host" />"""
}

manifest.get().asFile.writeText(
"""
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity android:name="dev.dimension.flare.MainActivity" android:exported="true">
<intent-filter android:autoVerify="false">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https" />
$dataTags
</intent-filter>
</activity>
</application>
</manifest>
""".trimIndent()
)
}
}

extensions.getByType(com.android.build.api.variant.AndroidComponentsExtension::class.java)
.onVariants { variant: com.android.build.api.variant.Variant ->
val t = tasks.register(
"generate${variant.name.replaceFirstChar { it.uppercase() }}DeepLinkManifest",
GenerateDeepLinkManifestTask::class.java
) {
hostsFile = project.layout.projectDirectory.file("deeplink.txt")
}

variant.sources.manifests.addGeneratedManifestFile(
t,
GenerateDeepLinkManifestTask::manifest
)
}
24 changes: 24 additions & 0 deletions app/deeplink.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
x.com
twitter.com
bsky.app
pawoo.net
mastodon.social
misskey.io
next.misskey.io
mstdn.jp
mstdn.social
mastodon.world
mastodon.sdf.org
universeodon.com
techhub.social
mastodonapp.uk
mastodon.uno
m.cmx.im
mstdn.party
infosec.exchange
hachyderm.io
sfba.social
misskey.design
ohai.social
mastodon.nl
troet.cafe
13 changes: 1 addition & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<activity
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask"
android:name=".MainActivity"
android:name="dev.dimension.flare.MainActivity"
android:exported="true"
android:theme="@style/Theme.Flare.Starting">
<intent-filter>
Expand All @@ -41,17 +41,6 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<intent-filter android:autoVerify="false">
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
<data android:host="x.com" />
<data android:host="twitter.com" />
<data android:host="www.x.com" />
<data android:host="www.twitter.com" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ internal object DeepLinkMapping {
statusKey = MicroBlogKey(id, accountKey.host),
)
}

@Serializable
data class PostMedia(
val handle: String,
val id: String,
val index: Int,
) : Type {
override fun deepLink(accountKey: MicroBlogKey): DeeplinkRoute =
DeeplinkRoute.Media.StatusMedia(
accountType = AccountType.Specific(accountKey),
statusKey = MicroBlogKey(id, accountKey.host),
index = index,
preview = null,
)
}
}

fun generatePattern(
Expand Down Expand Up @@ -111,6 +126,13 @@ internal object DeepLinkMapping {
"https://www.$xqtHost/{handle}/status/{id}",
"https://www.$xqtOldHost/{handle}/",
)
val media =
listOf(
"https://$xqtHost/{handle}/status/{id}/photo/{index}",
"https://$xqtOldHost/{handle}/status/{id}/photo/{index}",
"https://www.$xqtHost/{handle}/status/{id}/photo/{index}",
"https://www.$xqtOldHost/{handle}/status/{id}/photo/{index}",
)
profile.map {
DeepLinkPattern(
Type.Profile.serializer(),
Expand All @@ -122,6 +144,12 @@ internal object DeepLinkMapping {
Type.Post.serializer(),
Url(it),
)
} +
media.map {
DeepLinkPattern(
Type.PostMedia.serializer(),
Url(it),
)
}
}

Expand Down
Loading
Loading