Skip to content

Commit

Permalink
perf: switch enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed May 29, 2024
1 parent d48ae8d commit de431cb
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import li.songe.gkd.util.RuleSortOption
import li.songe.gkd.util.appInfoCacheFlow
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.navigate
import li.songe.gkd.util.toast

@RootNavGraph
@Destination(style = ProfileTransitions::class)
Expand Down Expand Up @@ -171,13 +170,9 @@ fun AppConfigPage(appId: String) {
ExcludeData.parse(g.config?.exclude)
}
val checked = getChecked(excludeData, g.group, appId, appInfo)
AppGroupCard(g.group, checked ?: false, onClick = {
AppGroupCard(g.group, checked, onClick = {
navController.navigate(GlobalRulePageDestination(g.subsItem.id, g.group.key))
}) { newChecked ->
if (checked == null) {
toast("内置禁用,不可修改")
return@AppGroupCard
}
vm.viewModelScope.launchTry {
DbSet.subsConfigDao.insert(
(g.config ?: SubsConfig(
Expand Down Expand Up @@ -243,7 +238,7 @@ fun AppConfigPage(appId: String) {
@Composable
private fun AppGroupCard(
group: RawSubscription.RawGroupProps,
enable: Boolean,
checked: Boolean?,
onClick: () -> Unit,
onCheckedChange: ((Boolean) -> Unit)?,
) {
Expand Down Expand Up @@ -297,6 +292,14 @@ private fun AppGroupCard(
}
}
Spacer(modifier = Modifier.width(10.dp))
Switch(checked = enable, modifier = Modifier, onCheckedChange = onCheckedChange)
if (checked != null) {
Switch(checked = checked, onCheckedChange = onCheckedChange)
} else {
Switch(
checked = false,
enabled = false,
onCheckedChange = onCheckedChange
)
}
}
}

0 comments on commit de431cb

Please sign in to comment.