[Android] Fix loading state toggling

Geoffrey Métais git at videolan.org
Thu May 7 15:18:02 CEST 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May  5 14:57:32 2020 +0200| [776ac287aeacd10fb73cd255f434b87d472aa1a8] | committer: Geoffrey Métais

Fix loading state toggling

> https://code.videolan.org/videolan/vlc-android/commit/776ac287aeacd10fb73cd255f434b87d472aa1a8
---

 .../org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt | 6 +++---
 .../src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
index fe2bc20ee..a409d1dae 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
@@ -44,7 +44,7 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
     private lateinit var dataSource : DataSource<Int, T>
     val loading = MutableLiveData<Boolean>().apply { value = true }
     private var refreshDeferred : CompletableDeferred<Unit>? = null
-    var isRefreshing = medialibrary.isWorking
+    var isRefreshing = true
         private set(value) {
             refreshDeferred = if (value) CompletableDeferred()
             else {
@@ -95,7 +95,7 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
     }
 
     fun refresh(): Boolean {
-        if (isRefreshing || !medialibrary.isStarted || !this::dataSource.isInitialized) return false
+        if (medialibrary.isWorking || !medialibrary.isStarted || !this::dataSource.isInitialized) return false
         privateHeaders.clear()
         if (!dataSource.isInvalid) {
             isRefreshing = true
@@ -128,7 +128,7 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
             try {
                 callback.onResult(page.toList(), params.requestedStartPosition, count)
             } catch (e: IllegalArgumentException) {}
-            isRefreshing = false
+            isRefreshing = !medialibrary.isStarted
         }
 
         override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<T>) {
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
index 58530efaf..f00a1ee6f 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
@@ -70,9 +70,9 @@ class AudioBrowserViewModel(context: Context) : MedialibraryViewModel(context) {
     override fun refresh() {
         artistsProvider.showAll = settings.getBoolean(KEY_ARTISTS_SHOW_ALL, false)
         viewModelScope.launch {
-            providers[currentTab].let { if (!it.isRefreshing) it.awaitRefresh() }
+            providers[currentTab].awaitRefresh()
             for ((index, provider) in providers.withIndex()) {
-                if (index != currentTab && provider.loading.hasObservers() && !provider.isRefreshing) provider.awaitRefresh()
+                if (index != currentTab && provider.loading.hasObservers()) provider.awaitRefresh()
             }
         }
     }



More information about the Android mailing list