Only care about the main process when not expanded

This commit is contained in:
vvb2060 2020-10-08 00:32:19 +08:00 committed by John Wu
parent 6509e3d4f5
commit eeced2fb5b

View File

@ -39,14 +39,19 @@ class HideItem(
get() = state
set(value) = set(value, state, { state = it }, BR.hiddenState) {
if (value == true) {
processes.filterNot { it.isHidden }
processes
.filterNot { it.isHidden }
.filter { isExpanded || it.process.name == it.process.packageName }
} else {
processes
.filter { it.isHidden }
.filter { isExpanded || it.process.name == it.process.packageName }
}.forEach { it.toggle() }
}
init {
processes.forEach { it.addOnPropertyChangedCallback(BR.hidden) { recalculateChecked() } }
addOnPropertyChangedCallback(BR.expanded) { recalculateChecked() }
recalculateChecked()
}
@ -57,11 +62,15 @@ class HideItem(
private fun recalculateChecked() {
itemsChecked = processes.count { it.isHidden }
state = when (itemsChecked) {
state = if (isExpanded) {
when (itemsChecked) {
0 -> false
processes.size -> true
else -> null
}
} else {
processes.find { it.isHidden && it.process.name == it.process.packageName } != null
}
}
override fun compareTo(other: HideItem) = comparator.compare(this, other)