Add intent filter to deep link settings pages

This commit is contained in:
MM20 2024-08-13 16:54:50 +02:00
parent 2c07895386
commit 84a62ae8e0
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 30 additions and 5 deletions

View File

@ -65,6 +65,15 @@
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.mm20.launcher2.ui.launcher.LauncherActivity" />
<intent-filter android:autoVerify="true">
<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"/>
<data android:path="/in-app"/>
<data android:host="kvaesitso.mm20.de"/>
</intent-filter>
</activity>
<activity android:name=".launcher.sheets.BindAndConfigureAppWidgetActivity" />

View File

@ -83,16 +83,24 @@ class SettingsActivity : BaseActivity() {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
val newRoute = intent?.getStringExtra(EXTRA_ROUTE)
val newRoute = getStartRoute(intent)
route = newRoute
setContent {
val navController = rememberNavController()
LaunchedEffect(route) {
navController.navigate(route ?: "settings") {
popUpTo("settings") {
inclusive = true
try {
navController.navigate(route ?: "settings") {
popUpTo("settings") {
inclusive = true
}
}
} catch (e: IllegalArgumentException) {
navController.navigate("settings") {
popUpTo("settings") {
inclusive = true
}
}
}
}
@ -288,10 +296,18 @@ class SettingsActivity : BaseActivity() {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
val newRoute = intent.getStringExtra(EXTRA_ROUTE)
val newRoute = getStartRoute(intent)
route = newRoute
}
private fun getStartRoute(intent: Intent): String? {
if (intent.data?.host == "kvaesitso.mm20.de") {
return intent.data?.getQueryParameter("route")
} else {
return intent.getStringExtra(EXTRA_ROUTE)
}
}
companion object {
const val EXTRA_ROUTE = "de.mm20.launcher2.settings.ROUTE"
const val ROUTE_WEATHER_INTEGRATION = "settings/integrations/weather"