[Android] Fix loading state in paged viewmodels
Geoffrey Métais
git at videolan.org
Fri Oct 19 10:35:28 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Oct 19 10:34:49 2018 +0200| [bef126e8250bac4976e78fc8535ea6f251a18f57] | committer: Geoffrey Métais
Fix loading state in paged viewmodels
> https://code.videolan.org/videolan/vlc-android/commit/bef126e8250bac4976e78fc8535ea6f251a18f57
---
.../src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
index 8fa94bead..5ebf739e4 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
@@ -1,11 +1,11 @@
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
}
More information about the Android
mailing list