[Android] Livedataset: Add sorted insertion
Geoffrey Métais
git at videolan.org
Thu May 14 14:57:31 CEST 2020
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May 5 17:20:12 2020 +0200| [821a1b04976b42523527ed772cec4d932348c2cb] | committer: Geoffrey Métais
Livedataset: Add sorted insertion
> https://code.videolan.org/videolan/vlc-android/commit/821a1b04976b42523527ed772cec4d932348c2cb
---
.../src/main/java/org/videolan/tools/livedata/LiveDataset.kt | 9 +++++++++
1 file changed, 9 insertions(+)
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 13d1615f6..350a3dd04 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
@@ -56,6 +56,15 @@ class LiveDataset<T> : MutableLiveData<MutableList<T>>() {
value = internalList.apply { add(item) }
}
+ fun add(item: T, comparator: Comparator<T>) {
+ var position = 0
+ for (media in internalList) {
+ if (comparator.compare(item, media) > 0) position++
+ else break
+ }
+ value = internalList.apply { this.add(position, item) }
+ }
+
fun add(position: Int, item: T) {
value = internalList.apply { add(position, item) }
}
More information about the Android
mailing list