fix deep link

This commit is contained in:
2026-08-08 08:52:18 +03:00
parent 64ee936aa6
commit 023395e09d
9 changed files with 74 additions and 71 deletions
@@ -30,6 +30,7 @@
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:supportsPictureInPicture="true">
<intent-filter>
@@ -56,10 +57,6 @@
android:host="box.shadowsparky.ru"
android:scheme="https" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<activity-alias
@@ -95,10 +92,6 @@
android:host="box.shadowsparky.ru"
android:scheme="https" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity-alias>
<receiver
@@ -4,6 +4,7 @@ import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
@@ -29,19 +30,14 @@ class MainActivity : ComponentActivity() {
edgeToEdge(false)
super.onCreate(savedInstanceState)
root = retainedComponent { componentContext ->
val routeFromIntent = obtainRouteOrNull(intent?.data)
val route = if (routeFromIntent == null) {
listOf(Route.default)
} else {
listOf(Route.default, routeFromIntent)
}
koin.get<RootFactory>().create(componentContext, route)
koin.get<RootFactory>().create(componentContext, listOf(Route.default))
}
if (openSavedIfNeeded(intent) || openUrlIfNeeded(intent.data)) {
intent = Intent(intent)
.setData(null)
.setAction(null)
}
log("onCreate $intent")
val isPiggyActivity = componentName?.className == PigReceiver.PIGGY_CLS
setContent {
if (isPiggyActivity) {
@@ -54,10 +50,9 @@ class MainActivity : ComponentActivity() {
edgeToEdge(isSystemInDarkTheme())
}
lifecycleScope.launch {
root.onFinish.collect {
finishAndRemoveTask()
}
root.onFinish.collect { finishAndRemoveTask() }
}
if (savedInstanceState == null) handleIntent(intent)
}
private fun edgeToEdge(isDarkTheme: Boolean) {
@@ -84,15 +79,42 @@ class MainActivity : ComponentActivity() {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (!openSavedIfNeeded(intent)) {
val uri = intent.data ?: return
val route = obtainRouteOrNull(uri)
if (route != null) {
root.nav(route, true)
} else {
openUrlIfNeeded(uri)
}
log("onNewIntent $intent")
setIntent(intent)
handleIntent(intent)
}
private fun handleIntent(intent: Intent?) {
intent ?: return
if (openSavedIfNeeded(intent)) {
clearIntent(intent)
return
}
val uri = intent.data ?: return
val route = obtainRouteOrNull(uri)
if (route != null) {
val currentRoute = root.childStack.value.active.configuration
if (currentRoute != route) {
root.nav(route, true)
}
} else {
openUrlIfNeeded(uri)
}
clearIntent(intent)
}
private fun clearIntent(intent: Intent) {
intent.data = null
intent.action = null
}
override fun onDestroy() {
super.onDestroy()
log("onDestroy")
}
private fun log(msg: String) {
Log.d("MainActivityDebug", msg)
}
private fun openUrlIfNeeded(uri: Uri?): Boolean {
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@drawable/baseline_saved_search_24"
android:shortcutId="saved_movies"
android:shortcutLongLabel="@string/saved_movies_long"
android:shortcutShortLabel="@string/saved_movies">
<intent
android:action="ru.shadowsparky.vbox.action.OPEN_SAVED_MOVIES"
android:targetClass="ru.shadowsparky.videobox.multiplatform.MainActivity"
android:targetPackage="ru.shadowsparky.videobox.multiplatform" />
</shortcut>
</shortcuts>
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts></shortcuts>