perf: app item padding

This commit is contained in:
lisonge 2024-05-29 21:39:46 +08:00
parent 747a20ac3c
commit d48ae8d251
4 changed files with 35 additions and 27 deletions

View File

@ -70,7 +70,7 @@ import li.songe.gkd.data.stringify
import li.songe.gkd.db.DbSet
import li.songe.gkd.service.launcherAppId
import li.songe.gkd.ui.component.AppBarTextField
import li.songe.gkd.ui.style.itemPadding
import li.songe.gkd.ui.style.appItemPadding
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.ProfileTransitions
import li.songe.gkd.util.SortTypeOption
@ -247,7 +247,7 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) {
Row(
modifier = Modifier
.height(IntrinsicSize.Min)
.itemPadding(),
.appItemPadding(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
@ -314,29 +314,33 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) {
if (group != null) {
val checked = getChecked(excludeData, group, appInfo.id, appInfo)
Switch(
checked = checked ?: false,
onCheckedChange = {
if (checked == null) {
toast("内置禁用,不可修改")
return@Switch
}
vm.viewModelScope.launchTry {
val subsConfig = (vm.subsConfigFlow.value ?: SubsConfig(
type = SubsConfig.GlobalGroupType,
subsItemId = subsItemId,
groupKey = groupKey,
)).copy(
exclude = excludeData.copy(
appIds = excludeData.appIds.toMutableMap().apply {
set(appInfo.id, !it)
})
.stringify()
)
DbSet.subsConfigDao.insert(subsConfig)
}
},
)
if (checked != null) {
Switch(
checked = checked,
onCheckedChange = {
vm.viewModelScope.launchTry {
val subsConfig = (vm.subsConfigFlow.value ?: SubsConfig(
type = SubsConfig.GlobalGroupType,
subsItemId = subsItemId,
groupKey = groupKey,
)).copy(
exclude = excludeData.copy(
appIds = excludeData.appIds.toMutableMap().apply {
set(appInfo.id, !it)
})
.stringify()
)
DbSet.subsConfigDao.insert(subsConfig)
}
},
)
} else {
Switch(
enabled = false,
checked = false,
onCheckedChange = {},
)
}
}
}
}

View File

@ -40,6 +40,7 @@ import com.google.accompanist.drawablepainter.rememberDrawablePainter
import li.songe.gkd.data.AppInfo
import li.songe.gkd.data.RawSubscription
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.ui.style.appItemPadding
import li.songe.gkd.util.encodeToJson5String
import li.songe.gkd.util.json
import li.songe.gkd.util.toast
@ -63,7 +64,7 @@ fun SubsAppCard(
onClick?.invoke()
}
.height(IntrinsicSize.Min)
.padding(10.dp, 6.dp),
.appItemPadding(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {

View File

@ -69,6 +69,7 @@ import li.songe.gkd.permission.canQueryPkgState
import li.songe.gkd.permission.checkOrRequestPermission
import li.songe.gkd.ui.component.AppBarTextField
import li.songe.gkd.ui.destinations.AppConfigPageDestination
import li.songe.gkd.ui.style.appItemPadding
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.SortTypeOption
import li.songe.gkd.util.appRefreshingFlow
@ -285,7 +286,7 @@ fun useAppListPage(): ScaffoldExt {
navController.navigate(AppConfigPageDestination(appInfo.id))
}
.height(IntrinsicSize.Min)
.padding(10.dp, 6.dp),
.appItemPadding(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {

View File

@ -5,3 +5,5 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
fun Modifier.itemPadding() = this then padding(16.dp, 12.dp)
fun Modifier.appItemPadding() = this then padding(10.dp, 8.dp)