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