Skip to content

Commit

Permalink
perf: 优化文案显示
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Dec 25, 2023
1 parent ecb5018 commit 06e37e3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 33 deletions.
23 changes: 21 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/data/RawSubscription.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/kotlin/li/songe/gkd/service/ManageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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}规则组"
} else {
"${allRules.allGroupSize}规则组"
}
allRules.numText + if (clickCount > 0) {
"/${clickCount}点击"
} else {
"暂无规则"
}) + if (clickCount > 0) "/${clickCount}点击" else ""
""
}
}.stateIn(scope, SharingStarted.Eagerly, "").collect { text ->
createNotif(
context, defaultChannel.id, abNotif.copy(
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/kotlin/li/songe/gkd/ui/ControlVm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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}规则组"
} else {
"${allRules.allGroupSize}规则组"
}
allRules.numText + if (clickCount > 0) {
"/${clickCount}点击"
} else {
"暂无规则"
}) + if (clickCount > 0) "/${clickCount}点击" else ""
""
}
}.stateIn(viewModelScope, SharingStarted.Eagerly, "")

}
2 changes: 1 addition & 1 deletion app/src/main/kotlin/li/songe/gkd/ui/SettingsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fun SettingsPage() {
Divider()

TextSwitch(name = "前台悬浮窗",
desc = "添加前台透明悬浮窗,关闭可能导致不点击/点击缓慢",
desc = "添加透明悬浮窗,关闭可能导致不点击/点击缓慢",
checked = store.enableAbFloatWindow,
onCheckedChange = {
updateStorage(
Expand Down
14 changes: 2 additions & 12 deletions app/src/main/kotlin/li/songe/gkd/ui/component/SubsItemCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
22 changes: 20 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/util/SubsState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 06e37e3

Please sign in to comment.