mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 08:45:27 +02:00
Fixed crashes when removing draggable item
This commit is contained in:
parent
a3a5d9ec27
commit
92ac089b2b
@ -96,9 +96,16 @@ class UnitGroupsRepository @Inject constructor() {
|
|||||||
suspend fun moveShownUnitGroups(from: ItemPosition, to: ItemPosition) {
|
suspend fun moveShownUnitGroups(from: ItemPosition, to: ItemPosition) {
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
shownUnitGroups.value = shownUnitGroups.value.toMutableList().apply {
|
shownUnitGroups.value = shownUnitGroups.value.toMutableList().apply {
|
||||||
|
val initialIndex = shownUnitGroups.value.indexOfFirst { it == from.key }
|
||||||
|
/**
|
||||||
|
* No such item. Happens when dragging item and clicking "remove" while item is
|
||||||
|
* still being dragged.
|
||||||
|
*/
|
||||||
|
if (initialIndex == -1) return
|
||||||
|
|
||||||
add(
|
add(
|
||||||
shownUnitGroups.value.indexOfFirst { it == to.key },
|
shownUnitGroups.value.indexOfFirst { it == to.key },
|
||||||
removeAt(shownUnitGroups.value.indexOfFirst { it == from.key })
|
removeAt(initialIndex)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user