Commit 821a1b04 authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Geoffrey Métais
Browse files

Livedataset: Add sorted insertion

parent 002b35d0
...@@ -56,6 +56,15 @@ class LiveDataset<T> : MutableLiveData<MutableList<T>>() { ...@@ -56,6 +56,15 @@ class LiveDataset<T> : MutableLiveData<MutableList<T>>() {
value = internalList.apply { add(item) } 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) { fun add(position: Int, item: T) {
value = internalList.apply { add(position, item) } value = internalList.apply { add(position, item) }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment