Commit fe9ceedd authored by Geoffrey Métais's avatar Geoffrey Métais

Fix crash during headers update

parent bf3823c5
......@@ -127,7 +127,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
}
fun computeHeaders(value: MutableList<MediaLibraryItem>) {
headers.clear()
privateHeaders.clear()
for ((position, item) in value.withIndex()) {
val previous = when {
position > 0 -> value[position - 1]
......@@ -135,11 +135,11 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
}
ModelsHelper.getHeader(context, AbstractMedialibrary.SORT_ALPHA, item, previous)?.let {
launch {
headers.put(position, it)
(liveHeaders as MutableLiveData<HeadersIndex>).value = headers
privateHeaders.put(position, it)
}
}
}
(liveHeaders as MutableLiveData).postValue(privateHeaders.clone())
}
internal open fun parseSubDirectories() {
......
......@@ -8,9 +8,13 @@ import androidx.lifecycle.MutableLiveData
typealias HeadersIndex = SparseArrayCompat<String>
open class HeaderProvider {
val headers = HeadersIndex()
val liveHeaders: LiveData<HeadersIndex> = MutableLiveData()
protected val privateHeaders = HeadersIndex()
var headers = HeadersIndex()
init {
liveHeaders.observeForever { headers = it }
}
@MainThread
fun getSectionforPosition(position: Int): String {
......
......@@ -32,7 +32,6 @@ import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.providers.HeaderProvider
import org.videolan.vlc.providers.HeadersIndex
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.SortableModel
import kotlin.properties.Delegates
......@@ -82,7 +81,7 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
fun refresh(): Boolean {
if (isRefreshing || !medialibrary.isStarted || !this::dataSource.isInitialized) return false
headers.clear()
privateHeaders.clear()
if (!dataSource.isInvalid) {
isRefreshing = true
dataSource.invalidate()
......@@ -100,10 +99,10 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
else -> null
}
ModelsHelper.getHeader(context, sort, item, previous)?.let {
headers.put(startposition + position, it)
(liveHeaders as MutableLiveData<HeadersIndex>).postValue(headers)
privateHeaders.put(startposition + position, it)
}
}
(liveHeaders as MutableLiveData).postValue(privateHeaders.clone())
}
inner class MLDataSource : PositionalDataSource<T>() {
......
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