[Android] Fix loading states for Video, playlist and Artist tab

Nicolas Pomepuy git at videolan.org
Thu May 7 15:18:03 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed May  6 08:38:40 2020 +0200| [624353da1a346643ed37acfbb4b784e924ca47cc] | committer: Geoffrey Métais

Fix loading states for Video, playlist and Artist tab

Fixes #1328

> https://code.videolan.org/videolan/vlc-android/commit/624353da1a346643ed37acfbb4b784e924ca47cc
---

 .../vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt       | 7 +++----
 .../src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt     | 2 +-
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt            | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
index faf13e6d2..cef8004ac 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
@@ -103,11 +103,10 @@ class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLay
         super.onActivityCreated(savedInstanceState)
         viewModel.provider.pagedList.observe(requireActivity(), Observer {
             playlistAdapter.submitList(it as PagedList<MediaLibraryItem>)
+            binding.empty.visibility = if (it.isEmpty())View.VISIBLE else View.GONE
         })
-        viewModel.provider.loading.observe(requireActivity(), Observer<Boolean> { loading ->
-            setRefreshing(loading) { refresh ->
-                if (!refresh) binding.empty.visibility = if (empty) View.VISIBLE else View.GONE
-            }
+        viewModel.provider.loading.observe(requireActivity(), Observer { loading ->
+            setRefreshing(loading) {  }
         })
 
         fastScroller.setRecyclerView(getCurrentRV(), viewModel.provider)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
index 0fa79c379..912e98b60 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
@@ -133,6 +133,7 @@ class AudioAlbumsSongsFragment : BaseAudioBrowser<AlbumSongsViewModel>(), SwipeR
         viewModel.albumsProvider.pagedList.observe(requireActivity(), Observer { albums ->
             @Suppress("UNCHECKED_CAST")
             (albums as? PagedList<MediaLibraryItem>)?.let { albumsAdapter.submitList(it) }
+            if (viewModel.albumsProvider.loading.value == false && empty && !viewModel.isFiltering()) currentTab = 1
         })
         viewModel.tracksProvider.pagedList.observe(requireActivity(), Observer { tracks ->
             @Suppress("UNCHECKED_CAST")
@@ -141,7 +142,6 @@ class AudioAlbumsSongsFragment : BaseAudioBrowser<AlbumSongsViewModel>(), SwipeR
         for (i in 0..1) setupLayoutManager(viewModel.providersInCard[i], lists[i], viewModel.providers[i] as MedialibraryProvider<MediaLibraryItem>, adapters[i], spacing)
         viewModel.albumsProvider.loading.observe(requireActivity(), Observer { loading ->
             if (!loading) {
-                if (empty && !viewModel.isFiltering()) currentTab = 1
                 fastScroller.setRecyclerView(getCurrentRV(), viewModel.providers[currentTab])
             }
             setRefreshing(loading)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index 26b66df1c..2d8ce82ad 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -295,7 +295,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
     private fun updateEmptyView() {
         if (!::binding.isInitialized) return
         val empty = viewModel.isEmpty() && videoListAdapter.currentList.isNullOrEmpty()
-        val working = mediaLibrary.isWorking
+        val working = viewModel.provider.loading.value != false
         binding.emptyLoading.state = when {
             empty && working -> EmptyLoadingState.LOADING
             empty && !working -> EmptyLoadingState.EMPTY



More information about the Android mailing list