mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +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) {
|
||||
mutex.withLock {
|
||||
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(
|
||||
shownUnitGroups.value.indexOfFirst { it == to.key },
|
||||
removeAt(shownUnitGroups.value.indexOfFirst { it == from.key })
|
||||
removeAt(initialIndex)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user