Skip to content

Commit ea45715

Browse files
committed
feat: AppConfigPage showDisabledRule (#1319)
1 parent 2e4b058 commit ea45715

File tree

4 files changed

+117
-4
lines changed

4 files changed

+117
-4
lines changed

app/src/main/kotlin/li/songe/gkd/store/SettingsStore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ data class SettingsStore(
5757
val a11yAppGroupType: Int = appGroupType,
5858
val a11yScopeAppGroupType: Int = appGroupType,
5959
val subsExcludeAppGroupType: Int = appGroupType,
60+
val showDisabledRule: Boolean = true,
6061
) {
6162
val useA11y get() = automatorMode == AutomatorModeOption.A11yMode.value
6263
val useAutomation get() = automatorMode == AutomatorModeOption.AutomationMode.value

app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import li.songe.gkd.ui.component.AppNameText
5050
import li.songe.gkd.ui.component.BatchActionButtonGroup
5151
import li.songe.gkd.ui.component.EmptyText
5252
import li.songe.gkd.ui.component.MenuGroupCard
53+
import li.songe.gkd.ui.component.MenuItemCheckbox
5354
import li.songe.gkd.ui.component.MenuItemRadioButton
5455
import li.songe.gkd.ui.component.PerfIcon
5556
import li.songe.gkd.ui.component.PerfIconButton
@@ -94,7 +95,6 @@ fun AppConfigPage(route: AppConfigRoute) {
9495
val (scrollBehavior, listState) = useListScrollState(
9596
resetKey,
9697
groupSize > 0,
97-
ruleSortType.value
9898
)
9999
if (focusLog != null && groupSize > 0) {
100100
LaunchedEffect(null) {
@@ -247,6 +247,12 @@ fun AppConfigPage(route: AppConfigRoute) {
247247
)
248248
}
249249
}
250+
MenuGroupCard(title = "筛选") {
251+
MenuItemCheckbox(
252+
text = "未启用",
253+
stateFlow = vm.showDisabledRuleFlow,
254+
)
255+
}
250256
}
251257
}
252258
}

app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@ import kotlinx.coroutines.flow.combine
66
import kotlinx.coroutines.flow.flattenConcat
77
import kotlinx.coroutines.flow.flowOf
88
import kotlinx.coroutines.flow.map
9+
import kotlinx.coroutines.flow.update
910
import kotlinx.coroutines.launch
11+
import li.songe.gkd.data.RawSubscription
1012
import li.songe.gkd.data.SubsConfig
1113
import li.songe.gkd.db.DbSet
1214
import li.songe.gkd.store.storeFlow
1315
import li.songe.gkd.ui.component.ShowGroupState
16+
import li.songe.gkd.ui.component.getActualGroupChecked
1417
import li.songe.gkd.ui.component.toGroupState
1518
import li.songe.gkd.ui.share.BaseViewModel
19+
import li.songe.gkd.ui.share.asMutableStateFlow
1620
import li.songe.gkd.util.LogUtils
1721
import li.songe.gkd.util.RuleSortOption
22+
import li.songe.gkd.util.UsedSubsEntry
1823
import li.songe.gkd.util.collator
1924
import li.songe.gkd.util.findOption
2025
import li.songe.gkd.util.subsItemsFlow
@@ -25,6 +30,12 @@ class AppConfigVm(val route: AppConfigRoute) : BaseViewModel() {
2530
val ruleSortTypeFlow = storeFlow.mapNew {
2631
RuleSortOption.objects.findOption(it.appRuleSort)
2732
}
33+
val showDisabledRuleFlow = storeFlow.asMutableStateFlow(
34+
getter = { it.showDisabledRule },
35+
setter = {
36+
storeFlow.value.copy(showDisabledRule = it)
37+
}
38+
)
2839

2940
private val usedSubsIdsFlow = subsItemsFlow.mapNew { list ->
3041
list.filter { it.enable }.map { it.id }.sorted()
@@ -76,8 +87,77 @@ class AppConfigVm(val route: AppConfigRoute) : BaseViewModel() {
7687
}.filter { it.second.isNotEmpty() }
7788
}.stateInit(emptyList())
7889

79-
val subsPairsFlow = combine(
90+
private val checkedGroupSetFlow = combine(
8091
temp1ListFlow,
92+
globalSubsConfigsFlow,
93+
categoryConfigsFlow,
94+
appSubsConfigsFlow,
95+
) { list, globalSubsConfigs, categoryConfigs, appSubsConfigs ->
96+
val checkedSet = mutableSetOf<Triple<Long, Int, Int>>()
97+
list.forEach { (entry, groups) ->
98+
groups.forEach { group ->
99+
val subsConfig = when (group) {
100+
is RawSubscription.RawAppGroup -> appSubsConfigs
101+
is RawSubscription.RawGlobalGroup -> globalSubsConfigs
102+
}.find { it.subsId == entry.subsItem.id && it.groupKey == group.key }
103+
val category = when (group) {
104+
is RawSubscription.RawAppGroup -> entry.subscription.getCategory(group.name)
105+
is RawSubscription.RawGlobalGroup -> null
106+
}
107+
val categoryConfig = if (category != null) {
108+
categoryConfigs.find { it.subsId == entry.subsItem.id && it.categoryKey == category.key }
109+
} else {
110+
null
111+
}
112+
val checked = getActualGroupChecked(
113+
subs = entry.subscription,
114+
group = group,
115+
appId = route.appId,
116+
subsConfig = subsConfig,
117+
categoryConfig = categoryConfig,
118+
)
119+
if (checked) {
120+
checkedSet.add(Triple(entry.subsItem.id, group.groupType, group.key))
121+
}
122+
}
123+
}
124+
checkedSet
125+
}.stateInit(emptySet())
126+
127+
private val actualCheckedGroupSetFlow = MutableStateFlow(checkedGroupSetFlow.value)
128+
129+
init {
130+
showDisabledRuleFlow.launchOnChange {
131+
actualCheckedGroupSetFlow.value = checkedGroupSetFlow.value
132+
}
133+
checkedGroupSetFlow.launchOnChange { a ->
134+
actualCheckedGroupSetFlow.update { b -> a + b }
135+
}
136+
}
137+
138+
private val temp2ListFlow = combine(
139+
temp1ListFlow,
140+
showDisabledRuleFlow,
141+
actualCheckedGroupSetFlow,
142+
) { list, showDisabledRule, checkedSet ->
143+
if (showDisabledRule) {
144+
list
145+
} else {
146+
val newList = mutableListOf<Pair<UsedSubsEntry, List<RawSubscription.RawGroupProps>>>()
147+
list.forEach { (entry, groups) ->
148+
val newGroups = groups.filter { g ->
149+
checkedSet.contains(Triple(entry.subsItem.id, g.groupType, g.key))
150+
}
151+
if (newGroups.isNotEmpty()) {
152+
newList.add(entry to newGroups)
153+
}
154+
}
155+
newList
156+
}
157+
}.stateInit(emptyList())
158+
159+
val subsPairsFlow = combine(
160+
temp2ListFlow,
81161
latestLogsFlow,
82162
ruleSortTypeFlow
83163
) { list, logs, sortType ->
@@ -115,11 +195,11 @@ class AppConfigVm(val route: AppConfigRoute) : BaseViewModel() {
115195
val isSelectedModeFlow = MutableStateFlow(false)
116196
val selectedDataSetFlow = MutableStateFlow(emptySet<ShowGroupState>())
117197

118-
private fun getAllSelectedDataSet() = subsPairsFlow.value.map { e ->
198+
private fun getAllSelectedDataSet() = subsPairsFlow.value.flatMap { e ->
119199
e.second.map { g ->
120200
g.toGroupState(subsId = e.first.subsItem.id, appId = route.appId)
121201
}
122-
}.flatten().toSet()
202+
}.toSet()
123203

124204
fun selectAll() {
125205
selectedDataSetFlow.value = getAllSelectedDataSet()

app/src/main/kotlin/li/songe/gkd/ui/component/RuleGroupCard.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,32 @@ fun RuleGroupCard(
283283
}
284284
}
285285

286+
fun getActualGroupChecked(
287+
subs: RawSubscription,
288+
group: RawSubscription.RawGroupProps,
289+
appId: String?,
290+
subsConfig: SubsConfig?,
291+
categoryConfig: CategoryConfig?,
292+
): Boolean {
293+
if (!group.valid) return false
294+
val inGlobalAppPage = appId != null && group is RawSubscription.RawGlobalGroup
295+
return if (inGlobalAppPage) {
296+
getGlobalGroupChecked(
297+
subs,
298+
ExcludeData.parse(subsConfig?.exclude),
299+
group,
300+
appId,
301+
)
302+
} else {
303+
getGroupEnable(
304+
group,
305+
subsConfig,
306+
subs.getCategory(group.name),
307+
categoryConfig,
308+
)
309+
} ?: false
310+
}
311+
286312

287313
@Composable
288314
fun BatchActionButtonGroup(vm: ViewModel, selectedDataSet: Set<ShowGroupState>) {

0 commit comments

Comments
 (0)