mirror of
https://github.com/PhilKes/NotallyX.git
synced 2025-06-28 12:19:55 +00:00
Merge pull request #550 from PhilKes/fix/keyboard-api-24
Fix ListItem deletion order and repair broken parent check state
This commit is contained in:
commit
adb981d76c
1 changed files with 14 additions and 1 deletions
|
@ -5,6 +5,8 @@ import com.philkes.notallyx.data.model.ListItem
|
||||||
import com.philkes.notallyx.data.model.deepCopy
|
import com.philkes.notallyx.data.model.deepCopy
|
||||||
import com.philkes.notallyx.data.model.findChild
|
import com.philkes.notallyx.data.model.findChild
|
||||||
import com.philkes.notallyx.data.model.plus
|
import com.philkes.notallyx.data.model.plus
|
||||||
|
import com.philkes.notallyx.data.model.shouldParentBeChecked
|
||||||
|
import com.philkes.notallyx.data.model.shouldParentBeUnchecked
|
||||||
import com.philkes.notallyx.utils.filter
|
import com.philkes.notallyx.utils.filter
|
||||||
import com.philkes.notallyx.utils.forEach
|
import com.philkes.notallyx.utils.forEach
|
||||||
import com.philkes.notallyx.utils.indices
|
import com.philkes.notallyx.utils.indices
|
||||||
|
@ -149,9 +151,20 @@ fun <R> List<R>.getOrNull(index: Int) = if (lastIndex >= index) this[index] else
|
||||||
fun Collection<ListItem>.init(resetIds: Boolean = true): List<ListItem> {
|
fun Collection<ListItem>.init(resetIds: Boolean = true): List<ListItem> {
|
||||||
val initializedItems = deepCopy()
|
val initializedItems = deepCopy()
|
||||||
initList(initializedItems, resetIds)
|
initList(initializedItems, resetIds)
|
||||||
|
checkBrokenList(initializedItems)
|
||||||
return initializedItems
|
return initializedItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkBrokenList(list: List<ListItem>) {
|
||||||
|
list.forEach { listItem ->
|
||||||
|
if (listItem.shouldParentBeChecked()) {
|
||||||
|
listItem.checked = true
|
||||||
|
} else if (listItem.shouldParentBeUnchecked()) {
|
||||||
|
listItem.checked = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun initList(list: List<ListItem>, resetIds: Boolean) {
|
private fun initList(list: List<ListItem>, resetIds: Boolean) {
|
||||||
if (resetIds) {
|
if (resetIds) {
|
||||||
list.forEachIndexed { index, item -> item.id = index }
|
list.forEachIndexed { index, item -> item.id = index }
|
||||||
|
@ -250,7 +263,7 @@ fun SortedList<ListItem>.findParentsByChecked(checked: Boolean): List<ListItem>
|
||||||
fun SortedList<ListItem>.deleteCheckedItems() {
|
fun SortedList<ListItem>.deleteCheckedItems() {
|
||||||
mapIndexed { index, listItem -> Pair(index, listItem) }
|
mapIndexed { index, listItem -> Pair(index, listItem) }
|
||||||
.filter { it.second.checked }
|
.filter { it.second.checked }
|
||||||
.sortedBy { it.second.isChild }
|
.sortedBy { !it.second.isChild }
|
||||||
.forEach { remove(it.second) }
|
.forEach { remove(it.second) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue