[Android] Fix loading states for Audio and Browse tabs

Nicolas Pomepuy git at videolan.org
Thu May 7 15:37:19 CEST 2020


vlc-android | branch: refs/tags/3.3.0-beta02 | Nicolas Pomepuy <nicolas at videolabs.io> | Thu May  7 11:27:33 2020 +0200| [817d19ad217860175935be9d37914d865838fb33] | committer: Geoffrey Métais

Fix loading states for Audio and Browse tabs

> https://code.videolan.org/videolan/vlc-android/commit/817d19ad217860175935be9d37914d865838fb33
---

 .../org/videolan/vlc/gui/audio/AudioBrowserFragment.kt  |  2 +-
 .../org/videolan/vlc/gui/browser/MainBrowserFragment.kt | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
index 3d91ecfe7..0f36d8f5d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
@@ -277,7 +277,7 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
     override fun enableSearchOption() = true
 
     private fun updateEmptyView() {
-        empty_loading.state = if (empty) EmptyLoadingState.EMPTY else EmptyLoadingState.NONE
+        empty_loading.state = if (viewModel.providers[currentTab].loading.value == true) EmptyLoadingState.LOADING else  if (empty) EmptyLoadingState.EMPTY else EmptyLoadingState.NONE
         setFabPlayShuffleAllVisibility()
     }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/MainBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/MainBrowserFragment.kt
index 13ea136dc..96b044254 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/MainBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/MainBrowserFragment.kt
@@ -134,7 +134,11 @@ class MainBrowserFragment : BaseFragment(), View.OnClickListener, CtxActionRecei
         localViewModel.dataset.observe(viewLifecycleOwner, Observer<List<MediaLibraryItem>> { list ->
             list?.let {
                 storageBrowserAdapter.update(it)
-                localEntry.loading.state = if (list.isEmpty()) EmptyLoadingState.EMPTY else EmptyLoadingState.NONE
+                localEntry.loading.state = when {
+                    list.isNotEmpty() -> EmptyLoadingState.NONE
+                    localViewModel.loading.value == true -> EmptyLoadingState.LOADING
+                    else -> EmptyLoadingState.EMPTY
+                }
             }
         })
         localViewModel.loading.observe(viewLifecycleOwner, Observer {
@@ -154,12 +158,19 @@ class MainBrowserFragment : BaseFragment(), View.OnClickListener, CtxActionRecei
         favoritesViewModel = BrowserFavoritesModel(requireContext())
         containerAdapterAssociation[favoritesBrowserContainer] = Pair(favoritesAdapter, favoritesViewModel)
         favoritesViewModel.favorites.observe(viewLifecycleOwner, Observer { list ->
-            list?.let {
+            list.let {
                 if (list.isEmpty()) favoritesEntry.setGone() else   favoritesEntry.setVisible()
                 favoritesAdapter.update(it)
-                favoritesEntry.loading.state = if (list.isEmpty()) EmptyLoadingState.EMPTY else EmptyLoadingState.NONE
+                favoritesEntry.loading.state = when {
+                    list.isNotEmpty() -> EmptyLoadingState.NONE
+                    localViewModel.loading.value == true -> EmptyLoadingState.LOADING
+                    else -> EmptyLoadingState.EMPTY
+                }
             }
         })
+        favoritesViewModel.provider.loading.observe(viewLifecycleOwner, Observer {
+            if (it) localEntry.loading.state = EmptyLoadingState.LOADING
+        })
         favoritesViewModel.provider.descriptionUpdate.observe(viewLifecycleOwner, Observer { pair ->
             if (pair != null) favoritesAdapter.notifyItemChanged(pair.first, pair.second)
         })



More information about the Android mailing list