[Android] Fix the move operation on a LiveDataset
Nicolas Pomepuy
git at videolan.org
Mon Mar 23 15:29:16 CET 2020
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Mar 23 14:43:54 2020 +0100| [3027e6fae1e9db76d97132d893ffbe481c45b4b8] | committer: Nicolas Pomepuy
Fix the move operation on a LiveDataset
> https://code.videolan.org/videolan/vlc-android/commit/3027e6fae1e9db76d97132d893ffbe481c45b4b8
---
.../main/java/org/videolan/tools/livedata/LiveDataset.kt | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/application/tools/src/main/java/org/videolan/tools/livedata/LiveDataset.kt b/application/tools/src/main/java/org/videolan/tools/livedata/LiveDataset.kt
index ca0789edd..13d1615f6 100644
--- a/application/tools/src/main/java/org/videolan/tools/livedata/LiveDataset.kt
+++ b/application/tools/src/main/java/org/videolan/tools/livedata/LiveDataset.kt
@@ -72,11 +72,18 @@ class LiveDataset<T> : MutableLiveData<MutableList<T>>() {
value = internalList.apply { removeAt(position) }
}
- fun move(from: Int, to: Int) {
- value = internalList.apply { move(from, to) }
+ fun move(item: T, newIndex: Int) {
+ move(internalList.indexOf(item), newIndex)
}
- fun move (item: T, position: Int) {
- value = internalList.apply { move(item, position) }
+ fun move(from: Int, to: Int) {
+ value = internalList.apply {
+ val item = this[from]
+ removeAt(from)
+ if (from > to)
+ add(to, item)
+ else
+ add(to - 1, item)
+ }
}
}
\ No newline at end of file
More information about the Android
mailing list