perf: 优化文案显示

This commit is contained in:
lisonge 2023-12-25 14:44:33 +08:00
parent ecb5018477
commit 06e37e375c
6 changed files with 52 additions and 33 deletions

View File

@ -57,8 +57,27 @@ data class RawSubscription(
}
@IgnoredOnParcel
val allGroupSize by lazy {
globalGroups.size + appGroups.size
val numText by lazy {
val appsSize = apps.size
val appGroupsSize = appGroups.size
val globalGroupSize = globalGroups.size
if (appGroupsSize + globalGroupSize > 0) {
if (globalGroupSize > 0) {
"${globalGroupSize}全局" + if (appGroupsSize > 0) {
"/"
} else {
""
}
} else {
""
} + if (appGroupsSize > 0) {
"${appsSize}应用/${appGroupsSize}规则组"
} else {
""
}
} else {
"暂无规则"
}
}
@Serializable

View File

@ -33,15 +33,11 @@ class ManageService : CompositionService({
) { allRules, clickCount, enableService, abRunning ->
if (!abRunning) return@combine "无障碍未授权"
if (!enableService) return@combine "服务已暂停"
(if (allRules.allGroupSize > 0) {
if (allRules.appSize > 0) {
"${allRules.appSize}应用/${allRules.allGroupSize}规则组"
allRules.numText + if (clickCount > 0) {
"/${clickCount}点击"
} else {
"${allRules.allGroupSize}规则组"
""
}
} else {
"暂无规则"
}) + if (clickCount > 0) "/${clickCount}点击" else ""
}.stateIn(scope, SharingStarted.Eagerly, "").collect { text ->
createNotif(
context, defaultChannel.id, abNotif.copy(

View File

@ -38,15 +38,11 @@ class ControlVm @Inject constructor() : ViewModel() {
}.stateIn(viewModelScope, SharingStarted.Eagerly, null)
val subsStatusFlow = combine(allRulesFlow, clickCountFlow) { allRules, clickCount ->
(if (allRules.allGroupSize > 0) {
if (allRules.appSize > 0) {
"${allRules.appSize}应用/${allRules.allGroupSize}规则组"
allRules.numText + if (clickCount > 0) {
"/${clickCount}点击"
} else {
"${allRules.allGroupSize}规则组"
""
}
} else {
"暂无规则"
}) + if (clickCount > 0) "/${clickCount}点击" else ""
}.stateIn(viewModelScope, SharingStarted.Eagerly, "")
}

View File

@ -113,7 +113,7 @@ fun SettingsPage() {
Divider()
TextSwitch(name = "前台悬浮窗",
desc = "添加前台透明悬浮窗,关闭可能导致不点击/点击缓慢",
desc = "添加透明悬浮窗,关闭可能导致不点击/点击缓慢",
checked = store.enableAbFloatWindow,
onCheckedChange = {
updateStorage(

View File

@ -76,19 +76,9 @@ fun SubsItemCard(
)
Spacer(modifier = Modifier.width(10.dp))
}
val apps = rawSubscription.apps
val groupsSize = rawSubscription.allGroupSize
val ruleNumText = if (groupsSize > 0) {
if (apps.isNotEmpty()) {
"${apps.size}应用/${groupsSize}规则组"
} else {
"${groupsSize}规则组"
}
} else {
"暂无规则"
}
Text(
text = ruleNumText,
text = rawSubscription.numText,
fontSize = 14.sp
)
}

View File

@ -97,8 +97,26 @@ data class AllRules(
val appIdToRules: Map<String, List<AppRule>> = emptyMap(),
val appIdToGroups: Map<String, List<RawSubscription.RawAppGroup>> = emptyMap(),
) {
val appSize = appIdToRules.keys.size
val allGroupSize = globalGroups.size + appIdToGroups.values.sumOf { s -> s.size }
private val appSize = appIdToRules.keys.size
private val appGroupSize = appIdToGroups.values.sumOf { s -> s.size }
val numText = if (globalGroups.size + appGroupSize > 0) {
if (globalGroups.isNotEmpty()) {
"${globalGroups.size}全局" + if (appGroupSize > 0) {
"/"
} else {
""
}
} else {
""
} + if (appGroupSize > 0) {
"${appSize}应用/${appGroupSize}规则组"
} else {
""
}
} else {
"暂无规则"
}
}
val allRulesFlow by lazy {