diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 10dd591a1..1c6694f2b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag import java.io.ByteArrayOutputStream fun String.runCommand(currentWorkingDir: File = file("./")): String { @@ -175,7 +174,7 @@ configurations.configureEach { } composeCompiler { - featureFlags.addAll(ComposeFeatureFlag.StrongSkipping) +// featureFlags.addAll(ComposeFeatureFlag.StrongSkipping) // default StrongSkipping reportsDestination = layout.buildDirectory.dir("compose_compiler") stabilityConfigurationFile = rootProject.layout.projectDirectory.file("stability_config.conf") } diff --git a/app/src/main/kotlin/li/songe/gkd/MainActivity.kt b/app/src/main/kotlin/li/songe/gkd/MainActivity.kt index 494555e27..4f1620863 100644 --- a/app/src/main/kotlin/li/songe/gkd/MainActivity.kt +++ b/app/src/main/kotlin/li/songe/gkd/MainActivity.kt @@ -27,6 +27,7 @@ import com.blankj.utilcode.util.ServiceUtils import com.dylanc.activityresult.launcher.PickContentLauncher import com.dylanc.activityresult.launcher.StartActivityLauncher import com.ramcosta.composedestinations.DestinationsNavHost +import com.ramcosta.composedestinations.generated.NavGraphs import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update @@ -40,7 +41,6 @@ import li.songe.gkd.service.GkdAbService import li.songe.gkd.service.ManageService import li.songe.gkd.service.fixRestartService import li.songe.gkd.service.updateLauncherAppId -import li.songe.gkd.ui.NavGraphs import li.songe.gkd.ui.component.BuildDialog import li.songe.gkd.ui.theme.AppTheme import li.songe.gkd.util.LocalNavController @@ -86,8 +86,8 @@ class MainActivity : ComponentActivity() { LocalNavController provides navController ) { DestinationsNavHost( - navGraph = NavGraphs.root, - navController = navController + navController = navController, + navGraph = NavGraphs.root ) ShizukuErrorDialog(mainVm.shizukuErrorFlow) AuthDialog(mainVm.authReasonFlow) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AboutPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AboutPage.kt index 2485db09c..fd014f46c 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AboutPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AboutPage.kt @@ -22,7 +22,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph +import com.ramcosta.composedestinations.annotation.RootGraph import li.songe.gkd.META import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding @@ -32,8 +32,7 @@ import li.songe.gkd.util.REPOSITORY_URL import li.songe.gkd.util.format import li.songe.gkd.util.openUri -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun AboutPage() { val navController = LocalNavController.current diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt index 053befed3..490e28b9b 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt @@ -33,7 +33,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemKey import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph +import com.ramcosta.composedestinations.annotation.RootGraph import li.songe.gkd.MainActivity import li.songe.gkd.db.DbSet import li.songe.gkd.ui.component.EmptyText @@ -46,8 +46,7 @@ import li.songe.gkd.util.appInfoCacheFlow import li.songe.gkd.util.launchAsFn import li.songe.gkd.util.throttle -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun ActivityLogPage() { val context = LocalContext.current as MainActivity diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AdvancedPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AdvancedPage.kt index 25bfbc043..c8d6faeed 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AdvancedPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AdvancedPage.kt @@ -59,8 +59,10 @@ import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.LogUtils import com.dylanc.activityresult.launcher.launchForResult import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.annotation.RootGraph +import com.ramcosta.composedestinations.generated.destinations.ActivityLogPageDestination +import com.ramcosta.composedestinations.generated.destinations.SnapshotPageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.update import li.songe.gkd.MainActivity @@ -80,8 +82,6 @@ import li.songe.gkd.ui.component.AuthCard import li.songe.gkd.ui.component.SettingItem import li.songe.gkd.ui.component.TextSwitch import li.songe.gkd.ui.component.updateDialogOptions -import li.songe.gkd.ui.destinations.ActivityLogPageDestination -import li.songe.gkd.ui.destinations.SnapshotPageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding import li.songe.gkd.ui.style.titleItemPadding @@ -100,8 +100,7 @@ import li.songe.gkd.util.throttle import li.songe.gkd.util.toast import rikka.shizuku.Shizuku -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun AdvancedPage() { val context = LocalContext.current as MainActivity @@ -420,7 +419,7 @@ fun AdvancedPage() { SettingItem( title = "快照记录" + (if (snapshotCount > 0) "-$snapshotCount" else ""), onClick = { - navController.navigate(SnapshotPageDestination) + navController.toDestinationsNavigator().navigate(SnapshotPageDestination) } ) @@ -543,7 +542,7 @@ fun AdvancedPage() { SettingItem( title = "界面记录", onClick = { - navController.navigate(ActivityLogPageDestination) + navController.toDestinationsNavigator().navigate(ActivityLogPageDestination) } ) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt index 303805990..0a2cfdab4 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt @@ -49,8 +49,10 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.annotation.RootGraph +import com.ramcosta.composedestinations.generated.destinations.AppItemPageDestination +import com.ramcosta.composedestinations.generated.destinations.GlobalRulePageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import kotlinx.coroutines.flow.update import li.songe.gkd.MainActivity import li.songe.gkd.data.ExcludeData @@ -60,8 +62,6 @@ import li.songe.gkd.data.stringify import li.songe.gkd.db.DbSet import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.updateDialogOptions -import li.songe.gkd.ui.destinations.AppItemPageDestination -import li.songe.gkd.ui.destinations.GlobalRulePageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding import li.songe.gkd.ui.style.itemVerticalPadding @@ -76,8 +76,7 @@ import li.songe.gkd.util.appInfoCacheFlow import li.songe.gkd.util.launchTry import li.songe.gkd.util.throttle -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun AppConfigPage(appId: String) { val navController = LocalNavController.current @@ -165,7 +164,7 @@ fun AppConfigPage(appId: String) { floatingActionButton = { FloatingActionButton( onClick = throttle { - navController.navigate(AppItemPageDestination(LOCAL_SUBS_ID, appId)) + navController.toDestinationsNavigator().navigate(AppItemPageDestination(LOCAL_SUBS_ID, appId)) }, content = { Icon( @@ -190,7 +189,7 @@ fun AppConfigPage(appId: String) { group = g.group, checked = checked, onClick = throttle { - navController.navigate( + navController.toDestinationsNavigator().navigate( GlobalRulePageDestination( g.subsItem.id, g.group.key @@ -229,7 +228,7 @@ fun AppConfigPage(appId: String) { group = g.group, checked = g.enable, onClick = { - navController.navigate( + navController.toDestinationsNavigator().navigate( AppItemPageDestination( g.subsItem.id, appId, diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt index c9355d998..d32d1d616 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt @@ -3,6 +3,7 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ramcosta.composedestinations.generated.destinations.AppConfigPageDestination import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine @@ -11,7 +12,6 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import li.songe.gkd.data.SubsConfig import li.songe.gkd.db.DbSet -import li.songe.gkd.ui.destinations.AppConfigPageDestination import li.songe.gkd.util.ResolvedAppGroup import li.songe.gkd.util.ResolvedGlobalGroup import li.songe.gkd.util.RuleSortOption diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt index 40727ec2e..18647cb0b 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt @@ -56,8 +56,9 @@ import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.ClipboardUtils import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.annotation.RootGraph +import com.ramcosta.composedestinations.generated.destinations.ImagePreviewPageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import kotlinx.coroutines.Dispatchers import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.jsonObject @@ -70,7 +71,6 @@ import li.songe.gkd.db.DbSet import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.TowLineText import li.songe.gkd.ui.component.waitResult -import li.songe.gkd.ui.destinations.GroupImagePageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding import li.songe.gkd.util.LocalNavController @@ -86,8 +86,7 @@ import li.songe.gkd.util.updateSubscription import li.songe.json5.Json5 import li.songe.json5.encodeToJson5String -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun AppItemPage( subsItemId: Long, @@ -371,11 +370,10 @@ fun AppItemPage( if (showGroupItemVal.allExampleUrls.isNotEmpty()) { TextButton(onClick = throttle { setShowGroupItem(null) - navController.navigate( - GroupImagePageDestination( - subsInt = subsItemId, - groupKey = showGroupItemVal.key, - appId = appId, + navController.toDestinationsNavigator().navigate( + ImagePreviewPageDestination( + title = showGroupItemVal.name, + uris = showGroupItemVal.allExampleUrls.toTypedArray() ) ) }) { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppItemVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppItemVm.kt index 40fc54f98..b648ca5e9 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppItemVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppItemVm.kt @@ -3,12 +3,12 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ramcosta.composedestinations.generated.destinations.AppItemPageDestination import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import li.songe.gkd.data.RawSubscription import li.songe.gkd.db.DbSet -import li.songe.gkd.ui.destinations.AppItemPageDestination import li.songe.gkd.util.map import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsItemsFlow diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AuthA11yPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AuthA11yPage.kt index 39bc77fe4..92f5cabf5 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AuthA11yPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AuthA11yPage.kt @@ -39,7 +39,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.ClipboardUtils import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph +import com.ramcosta.composedestinations.annotation.RootGraph import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import li.songe.gkd.META @@ -58,8 +58,7 @@ import li.songe.gkd.util.toast import rikka.shizuku.Shizuku import java.io.DataOutputStream -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun AuthA11yPage() { val context = LocalContext.current as MainActivity diff --git a/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt index 5916c5f9f..d85c452ba 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt @@ -45,7 +45,7 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph +import com.ramcosta.composedestinations.annotation.RootGraph import kotlinx.coroutines.Dispatchers import li.songe.gkd.MainActivity import li.songe.gkd.data.CategoryConfig @@ -66,8 +66,7 @@ import li.songe.gkd.util.throttle import li.songe.gkd.util.toast import li.songe.gkd.util.updateSubscription -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun CategoryPage(subsItemId: Long) { val context = LocalContext.current as MainActivity diff --git a/app/src/main/kotlin/li/songe/gkd/ui/CategoryVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/CategoryVm.kt index 831d7ab88..4de27089e 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/CategoryVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/CategoryVm.kt @@ -3,10 +3,10 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ramcosta.composedestinations.generated.destinations.CategoryPageDestination import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.stateIn import li.songe.gkd.db.DbSet -import li.songe.gkd.ui.destinations.CategoryPageDestination import li.songe.gkd.util.map import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsItemsFlow diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt index 8474df259..316c0046b 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt @@ -42,8 +42,10 @@ import androidx.lifecycle.viewmodel.compose.viewModel import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemKey import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.annotation.RootGraph +import com.ramcosta.composedestinations.generated.destinations.AppItemPageDestination +import com.ramcosta.composedestinations.generated.destinations.GlobalRulePageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted @@ -60,8 +62,6 @@ import li.songe.gkd.db.DbSet import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.StartEllipsisText import li.songe.gkd.ui.component.waitResult -import li.songe.gkd.ui.destinations.AppItemPageDestination -import li.songe.gkd.ui.destinations.GlobalRulePageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions @@ -71,8 +71,7 @@ import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.throttle import li.songe.gkd.util.toast -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun ClickLogPage() { val context = LocalContext.current as MainActivity @@ -221,13 +220,13 @@ fun ClickLogPage() { .clickable(onClick = throttle { clickLog.appId ?: return@throttle if (clickLog.groupType == SubsConfig.AppGroupType) { - navController.navigate( + navController.toDestinationsNavigator().navigate( AppItemPageDestination( clickLog.subsId, clickLog.appId, clickLog.groupKey ) ) } else if (clickLog.groupType == SubsConfig.GlobalGroupType) { - navController.navigate( + navController.toDestinationsNavigator().navigate( GlobalRulePageDestination( clickLog.subsId, clickLog.groupKey ) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt index 9b811073e..9e0bffca1 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt @@ -60,7 +60,7 @@ import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel import com.google.accompanist.drawablepainter.rememberDrawablePainter import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph +import com.ramcosta.composedestinations.annotation.RootGraph import li.songe.gkd.data.AppInfo import li.songe.gkd.data.ExcludeData import li.songe.gkd.data.RawSubscription @@ -81,8 +81,7 @@ import li.songe.gkd.util.SortTypeOption import li.songe.gkd.util.launchTry import li.songe.gkd.util.toast -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) { val navController = LocalNavController.current diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludeVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludeVm.kt index 3a39b903e..e8f42413c 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludeVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludeVm.kt @@ -3,6 +3,7 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ramcosta.composedestinations.generated.destinations.GlobalRuleExcludePageDestination import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine @@ -11,7 +12,6 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import li.songe.gkd.data.ExcludeData import li.songe.gkd.db.DbSet -import li.songe.gkd.ui.destinations.GlobalRuleExcludePageDestination import li.songe.gkd.util.SortTypeOption import li.songe.gkd.util.map import li.songe.gkd.util.orderedAppInfosFlow diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt index 9da98a04b..16c6d5566 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt @@ -57,8 +57,10 @@ import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.ClipboardUtils import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.annotation.RootGraph +import com.ramcosta.composedestinations.generated.destinations.GlobalRuleExcludePageDestination +import com.ramcosta.composedestinations.generated.destinations.ImagePreviewPageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import kotlinx.coroutines.Dispatchers import li.songe.gkd.MainActivity import li.songe.gkd.data.RawSubscription @@ -67,8 +69,6 @@ import li.songe.gkd.db.DbSet import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.TowLineText import li.songe.gkd.ui.component.waitResult -import li.songe.gkd.ui.destinations.GlobalRuleExcludePageDestination -import li.songe.gkd.ui.destinations.GroupImagePageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding import li.songe.gkd.util.LocalNavController @@ -81,8 +81,7 @@ import li.songe.gkd.util.toast import li.songe.gkd.util.updateSubscription import li.songe.json5.encodeToJson5String -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { val context = LocalContext.current as MainActivity @@ -239,7 +238,7 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { }, onClick = throttle { expanded = false - navController.navigate( + navController.toDestinationsNavigator().navigate( GlobalRuleExcludePageDestination( subsItemId, group.key @@ -472,10 +471,10 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { if (showGroupItem.allExampleUrls.isNotEmpty()) { TextButton(onClick = throttle { setShowGroupItem(null) - navController.navigate( - GroupImagePageDestination( - subsInt = subsItemId, - groupKey = showGroupItem.key + navController.toDestinationsNavigator().navigate( + ImagePreviewPageDestination( + title = showGroupItem.name, + uris = showGroupItem.allExampleUrls.toTypedArray() ) ) }) { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleVm.kt index d6c18b026..6d0f8e8a7 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleVm.kt @@ -3,10 +3,10 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ramcosta.composedestinations.generated.destinations.GlobalRulePageDestination import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.stateIn import li.songe.gkd.db.DbSet -import li.songe.gkd.ui.destinations.GlobalRulePageDestination import li.songe.gkd.util.map import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsItemsFlow diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GroupImagePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GroupImagePage.kt deleted file mode 100644 index b74008660..000000000 --- a/app/src/main/kotlin/li/songe/gkd/ui/GroupImagePage.kt +++ /dev/null @@ -1,119 +0,0 @@ -package li.songe.gkd.ui - -import androidx.compose.animation.core.AnimationConstants.DefaultDurationMillis -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.pager.HorizontalPager -import androidx.compose.foundation.pager.rememberPagerState -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.automirrored.filled.ArrowBack -import androidx.compose.material3.CircularProgressIndicator -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.runtime.Composable -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex -import coil.compose.SubcomposeAsyncImage -import coil.request.ImageRequest -import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph -import li.songe.gkd.data.RawSubscription -import li.songe.gkd.ui.component.TowLineText -import li.songe.gkd.util.LocalNavController -import li.songe.gkd.util.ProfileTransitions -import li.songe.gkd.util.imageLoader -import li.songe.gkd.util.subsIdToRawFlow - - -// TODO 在 app debug 模式下存在严重绘制错误问题 -@RootNavGraph -@Destination(style = ProfileTransitions::class) -@Composable -fun GroupImagePage(subsInt: Long, groupKey: Int, appId: String? = null) { - val context = LocalContext.current - val navController = LocalNavController.current - val subsIdToRaw by subsIdToRawFlow.collectAsState() - val rawSubs = subsIdToRaw[subsInt] - val rawApp = rawSubs?.apps?.first { a -> a.id == appId } - val group = if (appId == null) { - rawSubs?.globalGroups?.find { g -> g.key == groupKey } - } else { - rawApp?.groups?.find { g -> g.key == groupKey } - } - val allExampleUrls = when (group) { - is RawSubscription.RawAppGroup -> group.allExampleUrls - is RawSubscription.RawGlobalGroup -> group.allExampleUrls - else -> emptyList() - } - Box(modifier = Modifier.fillMaxSize()) { - TopAppBar( - navigationIcon = { - IconButton(onClick = { - navController.popBackStack() - }) { - Icon( - imageVector = Icons.AutoMirrored.Filled.ArrowBack, - contentDescription = null, - ) - } - }, - title = { - if (group != null) { - TowLineText( - title = rawSubs?.name ?: subsInt.toString(), - subTitle = group.name - ) - } - }, - modifier = Modifier.zIndex(1f), - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme.background.copy(alpha = 0.5f) - ) - ) - if (group != null) { - val state = rememberPagerState { allExampleUrls.size } - HorizontalPager( - modifier = Modifier.fillMaxSize(), state = state - ) { p -> - val url = allExampleUrls.getOrNull(p) - if (url != null) { - SubcomposeAsyncImage( - model = ImageRequest.Builder(context).data(url) - .crossfade(DefaultDurationMillis).build(), - contentDescription = null, - modifier = Modifier.fillMaxWidth(), - loading = { - Column( - horizontalAlignment = Alignment.CenterHorizontally, - modifier = Modifier.fillMaxWidth() - ) { - CircularProgressIndicator(modifier = Modifier.size(50.dp)) - } - }, - error = { - Column( - horizontalAlignment = Alignment.CenterHorizontally, - modifier = Modifier.fillMaxWidth() - ) { - Text(text = "加载失败", color = MaterialTheme.colorScheme.error) - } - }, - imageLoader = imageLoader - ) - } - } - } - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ImagePreviewPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/ImagePreviewPage.kt index 4dbf12471..08f695828 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ImagePreviewPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ImagePreviewPage.kt @@ -1,13 +1,19 @@ package li.songe.gkd.ui +import androidx.compose.animation.core.AnimationConstants.DefaultDurationMillis +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.pager.HorizontalPager +import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme @@ -15,24 +21,37 @@ import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex -import coil.compose.AsyncImage +import coil.compose.SubcomposeAsyncImage +import coil.request.ImageRequest import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph +import com.ramcosta.composedestinations.annotation.RootGraph import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions +import li.songe.gkd.util.imageLoader -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun ImagePreviewPage( - filePath: String, title: String? = null, + uri: String? = null, + uris: Array = emptyArray(), ) { val navController = LocalNavController.current - Box(modifier = Modifier.fillMaxSize()) { + Box( + modifier = Modifier + .background(MaterialTheme.colorScheme.background) + .fillMaxSize() + ) { TopAppBar( + modifier = Modifier + .zIndex(1f) + .fillMaxWidth(), navigationIcon = { IconButton(onClick = { navController.popBackStack() @@ -48,22 +67,73 @@ fun ImagePreviewPage( Text(text = title) } }, - actions = {}, - modifier = Modifier.zIndex(1f), colors = TopAppBarDefaults.topAppBarColors( containerColor = MaterialTheme.colorScheme.background.copy(alpha = 0.5f) ) ) - - Column( - modifier = Modifier - .fillMaxSize() - .verticalScroll(rememberScrollState()) - ) { - AsyncImage( - model = filePath, contentDescription = null, modifier = Modifier.fillMaxWidth() - ) + val showUri = uri ?: if (uris.size == 1) uris.first() else null + if (showUri != null) { + UriImage(showUri) + } else if (uris.isNotEmpty()) { + val state = rememberPagerState { uris.size } + Box( + modifier = Modifier.fillMaxSize() + ) { + HorizontalPager( + modifier = Modifier.fillMaxSize(), + state = state, + pageContent = { UriImage(uris[it]) } + ) + Box( + Modifier + .align(Alignment.BottomCenter) + .fillMaxWidth() + .padding(bottom = 150.dp), + contentAlignment = Alignment.BottomCenter + ) { + Text( + text = "${state.currentPage + 1}/${uris.size}", + style = MaterialTheme.typography.titleLarge + ) + } + } } } +} -} \ No newline at end of file +@Composable +private fun UriImage(uri: String) { + val context = LocalContext.current + val model = remember(uri) { + ImageRequest.Builder(context).data(uri) + .crossfade(DefaultDurationMillis).build() + } + SubcomposeAsyncImage( + modifier = Modifier.fillMaxWidth(), + model = model, + contentDescription = null, + loading = { + Column( + modifier = Modifier.fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + ) { + CircularProgressIndicator(modifier = Modifier.size(40.dp)) + } + }, + error = { + Column( + modifier = Modifier.fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + ) { + Text( + text = "加载失败", + color = MaterialTheme.colorScheme.error, + style = MaterialTheme.typography.bodyMedium + ) + } + }, + imageLoader = imageLoader + ) +} diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt index 49fa766bb..b356e4427 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt @@ -29,13 +29,13 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextOverflow import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.annotation.RootGraph +import com.ramcosta.composedestinations.generated.destinations.AppItemPageDestination +import com.ramcosta.composedestinations.generated.destinations.GlobalRulePageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import li.songe.gkd.MainActivity import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.updateDialogOptions -import li.songe.gkd.ui.destinations.AppItemPageDestination -import li.songe.gkd.ui.destinations.GlobalRulePageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding import li.songe.gkd.util.LocalNavController @@ -44,8 +44,7 @@ import li.songe.gkd.util.appInfoCacheFlow import li.songe.gkd.util.ruleSummaryFlow import li.songe.gkd.util.throttle -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun SlowGroupPage() { val context = LocalContext.current as MainActivity @@ -91,7 +90,7 @@ fun SlowGroupPage() { SlowGroupCard( modifier = Modifier .clickable(onClick = throttle { - navController.navigate( + navController.toDestinationsNavigator().navigate( GlobalRulePageDestination( rule.subsItem.id, group.key @@ -110,7 +109,7 @@ fun SlowGroupPage() { SlowGroupCard( modifier = Modifier .clickable(onClick = throttle { - navController.navigate( + navController.toDestinationsNavigator().navigate( AppItemPageDestination( rule.subsItem.id, rule.app.id, diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt index b66e31203..34e5be252 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt @@ -43,8 +43,9 @@ import com.blankj.utilcode.util.ClipboardUtils import com.blankj.utilcode.util.ImageUtils import com.blankj.utilcode.util.UriUtils import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.annotation.RootGraph +import com.ramcosta.composedestinations.generated.destinations.ImagePreviewPageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import li.songe.gkd.MainActivity @@ -57,7 +58,6 @@ import li.songe.gkd.permission.requiredPermission import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.StartEllipsisText import li.songe.gkd.ui.component.waitResult -import li.songe.gkd.ui.destinations.ImagePreviewPageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.util.IMPORT_SHORT_URL import li.songe.gkd.util.LocalNavController @@ -69,8 +69,7 @@ import li.songe.gkd.util.snapshotZipDir import li.songe.gkd.util.throttle import li.songe.gkd.util.toast -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun SnapshotPage() { val context = LocalContext.current as MainActivity @@ -189,12 +188,14 @@ fun SnapshotPage() { Text( text = "查看", modifier = Modifier .clickable(onClick = throttle(fn = vm.viewModelScope.launchAsFn { - navController.navigate( - ImagePreviewPageDestination( - filePath = snapshotVal.screenshotFile.absolutePath, - title = snapshotVal.appName, + navController + .toDestinationsNavigator() + .navigate( + ImagePreviewPageDestination( + title = snapshotVal.appName, + uri = snapshotVal.screenshotFile.absolutePath, + ) ) - ) selectedSnapshot = null })) .then(modifier) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt index 4959d0dc0..4735812f8 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt @@ -48,8 +48,9 @@ import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.annotation.RootGraph +import com.ramcosta.composedestinations.generated.destinations.AppItemPageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import li.songe.gkd.MainActivity import li.songe.gkd.data.RawSubscription import li.songe.gkd.data.SubsConfig @@ -60,7 +61,6 @@ import li.songe.gkd.ui.component.QueryPkgAuthCard import li.songe.gkd.ui.component.SubsAppCard import li.songe.gkd.ui.component.TowLineText import li.songe.gkd.ui.component.waitResult -import li.songe.gkd.ui.destinations.AppItemPageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.menuPadding import li.songe.gkd.util.LocalNavController @@ -76,8 +76,7 @@ import li.songe.gkd.util.updateSubscription import li.songe.json5.encodeToJson5String -@RootNavGraph -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class) @Composable fun SubsPage( subsItemId: Long, @@ -253,7 +252,7 @@ fun SubsPage( subsConfig = subsConfig, enableSize = enableSize, onClick = throttle { - navController.navigate(AppItemPageDestination(subsItemId, appRaw.id)) + navController.toDestinationsNavigator().navigate(AppItemPageDestination(subsItemId, appRaw.id)) }, onValueChange = throttle(fn = vm.viewModelScope.launchAsFn { enable -> val newItem = subsConfig?.copy( diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt index d634070af..4e3ae643b 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt @@ -3,6 +3,7 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ramcosta.composedestinations.generated.destinations.SubsPageDestination import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine @@ -13,7 +14,6 @@ import li.songe.gkd.data.RawSubscription import li.songe.gkd.data.SubsConfig import li.songe.gkd.data.Tuple3 import li.songe.gkd.db.DbSet -import li.songe.gkd.ui.destinations.SubsPageDestination import li.songe.gkd.util.SortTypeOption import li.songe.gkd.util.appInfoCacheFlow import li.songe.gkd.util.collator diff --git a/app/src/main/kotlin/li/songe/gkd/ui/component/SubsItemCard.kt b/app/src/main/kotlin/li/songe/gkd/ui/component/SubsItemCard.kt index 57bea958f..3e057eeec 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/component/SubsItemCard.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/component/SubsItemCard.kt @@ -37,15 +37,15 @@ import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.dp import androidx.lifecycle.viewModelScope import com.blankj.utilcode.util.ClipboardUtils -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.generated.destinations.CategoryPageDestination +import com.ramcosta.composedestinations.generated.destinations.GlobalRulePageDestination +import com.ramcosta.composedestinations.generated.destinations.SubsPageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import kotlinx.coroutines.Dispatchers import li.songe.gkd.MainActivity import li.songe.gkd.data.RawSubscription import li.songe.gkd.data.SubsItem import li.songe.gkd.data.deleteSubscription -import li.songe.gkd.ui.destinations.CategoryPageDestination -import li.songe.gkd.ui.destinations.GlobalRulePageDestination -import li.songe.gkd.ui.destinations.SubsPageDestination import li.songe.gkd.ui.home.HomeVm import li.songe.gkd.util.LOCAL_SUBS_ID import li.songe.gkd.util.LocalNavController @@ -237,7 +237,7 @@ private fun SubsMenuItem( }, onClick = throttle { onExpandedChange(false) - navController.navigate(SubsPageDestination(subItem.id)) + navController.toDestinationsNavigator().navigate(SubsPageDestination(subItem.id)) } ) } @@ -248,7 +248,7 @@ private fun SubsMenuItem( }, onClick = throttle { onExpandedChange(false) - navController.navigate(CategoryPageDestination(subItem.id)) + navController.toDestinationsNavigator().navigate(CategoryPageDestination(subItem.id)) } ) } @@ -259,7 +259,7 @@ private fun SubsMenuItem( }, onClick = throttle { onExpandedChange(false) - navController.navigate(GlobalRulePageDestination(subItem.id)) + navController.toDestinationsNavigator().navigate(GlobalRulePageDestination(subItem.id)) } ) } diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt index 710b04f9c..426b8852a 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt @@ -57,13 +57,13 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.KeyboardUtils import com.google.accompanist.drawablepainter.rememberDrawablePainter -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.generated.destinations.AppConfigPageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import kotlinx.coroutines.flow.update import li.songe.gkd.MainActivity import li.songe.gkd.ui.component.AppBarTextField import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.QueryPkgAuthCard -import li.songe.gkd.ui.destinations.AppConfigPageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.appItemPadding import li.songe.gkd.ui.style.menuPadding @@ -265,7 +265,7 @@ fun useAppListPage(): ScaffoldExt { Row( modifier = Modifier .clickable(onClick = throttle { - navController.navigate(AppConfigPageDestination(appInfo.id)) + navController.toDestinationsNavigator().navigate(AppConfigPageDestination(appInfo.id)) }) .height(IntrinsicSize.Min) .appItemPadding(), diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/ControlPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/ControlPage.kt index 3cb0220dd..520371592 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/ControlPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/ControlPage.kt @@ -26,7 +26,11 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextOverflow import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.generated.destinations.ActivityLogPageDestination +import com.ramcosta.composedestinations.generated.destinations.AuthA11YPageDestination +import com.ramcosta.composedestinations.generated.destinations.ClickLogPageDestination +import com.ramcosta.composedestinations.generated.destinations.SlowGroupPageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import li.songe.gkd.MainActivity import li.songe.gkd.a11yServiceEnabledFlow import li.songe.gkd.permission.notificationState @@ -38,10 +42,6 @@ import li.songe.gkd.service.switchA11yService import li.songe.gkd.ui.component.AuthCard import li.songe.gkd.ui.component.SettingItem import li.songe.gkd.ui.component.TextSwitch -import li.songe.gkd.ui.destinations.ActivityLogPageDestination -import li.songe.gkd.ui.destinations.AuthA11yPageDestination -import li.songe.gkd.ui.destinations.ClickLogPageDestination -import li.songe.gkd.ui.destinations.SlowGroupPageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding import li.songe.gkd.util.HOME_PAGE_URL @@ -110,7 +110,7 @@ fun useControlPage(): ScaffoldExt { title = "无障碍授权", desc = if (a11yBroken) "服务故障,请重新授权" else "授权使无障碍服务运行", onAuthClick = { - navController.navigate(AuthA11yPageDestination) + navController.toDestinationsNavigator().navigate(AuthA11YPageDestination) }) } @@ -137,7 +137,7 @@ fun useControlPage(): ScaffoldExt { title = "触发记录", subtitle = "如误触可在此快速定位关闭规则", onClick = { - navController.navigate(ClickLogPageDestination) + navController.toDestinationsNavigator().navigate(ClickLogPageDestination) } ) @@ -146,7 +146,7 @@ fun useControlPage(): ScaffoldExt { title = "界面记录", subtitle = "记录打开的应用及界面", onClick = { - navController.navigate(ActivityLogPageDestination) + navController.toDestinationsNavigator().navigate(ActivityLogPageDestination) } ) } @@ -156,7 +156,7 @@ fun useControlPage(): ScaffoldExt { title = "耗时查询-${ruleSummary.slowGroupCount}", subtitle = "可能导致触发缓慢或更多耗电", onClick = { - navController.navigate(SlowGroupPageDestination) + navController.toDestinationsNavigator().navigate(SlowGroupPageDestination) } ) } diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt index 8bdf8d2a9..ca35312c4 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt @@ -16,7 +16,7 @@ import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootNavGraph +import com.ramcosta.composedestinations.annotation.RootGraph import kotlinx.coroutines.Dispatchers import li.songe.gkd.MainActivity import li.songe.gkd.OpenFileActivity @@ -31,8 +31,7 @@ data class BottomNavItem( val icon: ImageVector, ) -@RootNavGraph(start = true) -@Destination(style = ProfileTransitions::class) +@Destination(style = ProfileTransitions::class, start = true) @Composable fun HomePage() { val context = LocalContext.current as MainActivity diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt index e76b293f1..bc6081c60 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt @@ -35,7 +35,9 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextAlign import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel -import com.ramcosta.composedestinations.navigation.navigate +import com.ramcosta.composedestinations.generated.destinations.AboutPageDestination +import com.ramcosta.composedestinations.generated.destinations.AdvancedPageDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import kotlinx.coroutines.flow.update import li.songe.gkd.META import li.songe.gkd.MainActivity @@ -45,8 +47,6 @@ import li.songe.gkd.ui.component.TextMenu import li.songe.gkd.ui.component.TextSwitch import li.songe.gkd.ui.component.updateDialogOptions import li.songe.gkd.ui.component.waitResult -import li.songe.gkd.ui.destinations.AboutPageDestination -import li.songe.gkd.ui.destinations.AdvancedPageDestination import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding import li.songe.gkd.ui.style.titleItemPadding @@ -365,11 +365,11 @@ fun useSettingsPage(): ScaffoldExt { ) SettingItem(title = "高级设置", onClick = { - navController.navigate(AdvancedPageDestination) + navController.toDestinationsNavigator().navigate(AdvancedPageDestination) }) SettingItem(title = "关于", onClick = { - navController.navigate(AboutPageDestination) + navController.toDestinationsNavigator().navigate(AboutPageDestination) }) Spacer(modifier = Modifier.height(EmptyHeight)) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/style/Padding.kt b/app/src/main/kotlin/li/songe/gkd/ui/style/Padding.kt index f95f9aa23..cdcfae611 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/style/Padding.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/style/Padding.kt @@ -9,17 +9,17 @@ val itemHorizontalPadding = 16.dp val itemVerticalPadding = 12.dp val EmptyHeight = 40.dp -fun Modifier.itemPadding() = this then padding(itemHorizontalPadding, itemVerticalPadding) +fun Modifier.itemPadding() = this.padding(itemHorizontalPadding, itemVerticalPadding) -fun Modifier.titleItemPadding() = - this then padding( - itemHorizontalPadding, - itemVerticalPadding + itemVerticalPadding / 2, - itemHorizontalPadding, - itemVerticalPadding - itemVerticalPadding / 2 - ) +fun Modifier.titleItemPadding() = this.padding( + itemHorizontalPadding, + itemVerticalPadding + itemVerticalPadding / 2, + itemHorizontalPadding, + itemVerticalPadding - itemVerticalPadding / 2 +) -fun Modifier.appItemPadding() = this then padding(10.dp, 10.dp) +fun Modifier.appItemPadding() = this.padding(10.dp, 10.dp) -fun Modifier.menuPadding() = - this then padding(MenuDefaults.DropdownMenuItemContentPadding).padding(vertical = 8.dp) +fun Modifier.menuPadding() = this + .padding(MenuDefaults.DropdownMenuItemContentPadding) + .padding(vertical = 8.dp) diff --git a/app/src/main/kotlin/li/songe/gkd/util/ProfileTransitions.kt b/app/src/main/kotlin/li/songe/gkd/util/ProfileTransitions.kt index b9723e0ea..839625eb2 100644 --- a/app/src/main/kotlin/li/songe/gkd/util/ProfileTransitions.kt +++ b/app/src/main/kotlin/li/songe/gkd/util/ProfileTransitions.kt @@ -10,20 +10,23 @@ import androidx.compose.animation.slideOutHorizontally import androidx.navigation.NavBackStackEntry import com.ramcosta.composedestinations.spec.DestinationStyle -object ProfileTransitions : DestinationStyle.Animated { - override fun AnimatedContentTransitionScope.enterTransition(): EnterTransition? { - return slideInHorizontally(tween()) { it } +typealias EnterTransitionType = AnimatedContentTransitionScope.() -> EnterTransition? +typealias ExitTransitionType = AnimatedContentTransitionScope.() -> ExitTransition? + +object ProfileTransitions : DestinationStyle.Animated() { + override val enterTransition: EnterTransitionType = { + slideInHorizontally(tween()) { it } } - override fun AnimatedContentTransitionScope.exitTransition(): ExitTransition? { - return slideOutHorizontally(tween()) { -it } + fadeOut(tween()) + override val exitTransition: ExitTransitionType = { + slideOutHorizontally(tween()) { -it } + fadeOut(tween()) } - override fun AnimatedContentTransitionScope.popEnterTransition(): EnterTransition? { - return slideInHorizontally(tween()) { -it } + override val popEnterTransition: EnterTransitionType = { + slideInHorizontally(tween()) { -it } } - override fun AnimatedContentTransitionScope.popExitTransition(): ExitTransition? { - return slideOutHorizontally(tween()) { it } + override val popExitTransition: ExitTransitionType = { + slideOutHorizontally(tween()) { it } } } \ No newline at end of file diff --git a/app/src/main/kotlin/li/songe/gkd/util/Singleton.kt b/app/src/main/kotlin/li/songe/gkd/util/Singleton.kt index 8b4e11576..519f1435c 100644 --- a/app/src/main/kotlin/li/songe/gkd/util/Singleton.kt +++ b/app/src/main/kotlin/li/songe/gkd/util/Singleton.kt @@ -15,8 +15,9 @@ import kotlinx.serialization.json.Json import li.songe.gkd.app import okhttp3.OkHttpClient import java.text.Collator -import java.time.Duration import java.util.Locale +import kotlin.time.Duration.Companion.seconds +import kotlin.time.toJavaDuration val kv by lazy { MMKV.mmkvWithID("kv") } @@ -50,9 +51,9 @@ val imageLoader by lazy { ImageLoader.Builder(app) .okHttpClient( OkHttpClient.Builder() - .connectTimeout(Duration.ofSeconds(30)) - .readTimeout(Duration.ofSeconds(30)) - .writeTimeout(Duration.ofSeconds(30)) + .connectTimeout(30.seconds.toJavaDuration()) + .readTimeout(30.seconds.toJavaDuration()) + .writeTimeout(30.seconds.toJavaDuration()) .build() ) .components { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d1092acf3..d4af76275 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,12 +2,12 @@ kotlin = "2.0.20" ksp = "2.0.20-1.0.25" android = "8.6.0" -compose = "1.6.8" +compose = "1.7.1" rikka = "4.4.0" room = "2.6.1" paging = "3.3.2" ktor = "2.3.12" -destinations = "1.10.2" +destinations = "2.1.0-beta12" coil = "2.7.0" shizuku = "13.1.5" @@ -45,7 +45,7 @@ androidx_room_paging = { module = "androidx.room:room-paging", version.ref = "ro androidx_splashscreen = { module = "androidx.core:core-splashscreen", version = "1.0.1" } androidx_paging_runtime = { module = "androidx.paging:paging-runtime", version.ref = "paging" } androidx_paging_compose = { module = "androidx.paging:paging-compose", version.ref = "paging" } -google_accompanist_drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version = "0.34.0" } +google_accompanist_drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version = "0.36.0" } junit = { module = "junit:junit", version = "4.13.2" } ktor_server_core = { module = "io.ktor:ktor-server-core", version.ref = "ktor" } ktor_server_cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor" }