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

Fix loading state in paged viewmodels

parent 9038981c
package org.videolan.vlc.viewmodels.paged
import android.content.Context
import androidx.lifecycle.MutableLiveData
import androidx.paging.DataSource
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import androidx.paging.PositionalDataSource
import android.content.Context
import kotlinx.coroutines.experimental.launch
import org.videolan.medialibrary.Medialibrary
import org.videolan.medialibrary.media.MediaLibraryItem
......@@ -14,7 +14,7 @@ import org.videolan.vlc.viewmodels.SortableModel
abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableModel(context), Medialibrary.OnMedialibraryReadyListener {
protected val medialibrary = Medialibrary.getInstance()
protected var filter : String? = null
val loading = MutableLiveData<Boolean>().apply { value = true }
val loading = MutableLiveData<Boolean>().apply { value = false }
private val pagingConfig = PagedList.Config.Builder()
.setPageSize(100)
......@@ -71,8 +71,10 @@ abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableMo
}
override fun refresh(): Boolean {
loading.postValue(true)
pagedList.value?.dataSource?.invalidate()
if (pagedList.value?.dataSource?.isInvalid == false) {
loading.postValue(true)
pagedList.value?.dataSource?.invalidate()
}
return true
}
......
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