[Android] Improve refresh process

Geoffrey Métais git at videolan.org
Fri Apr 10 13:35:10 CEST 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr  9 15:42:24 2020 +0200| [e9461bfd339c5fb269dc6650214fe82db7f4411e] | committer: Nicolas Pomepuy

Improve refresh process

Loading view was briefly appearing for quick actions like media deletion

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

 .../vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt  |  5 +++--
 .../src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt    | 11 ++++++-----
 .../src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt  |  3 ++-
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt       | 11 ++++++-----
 4 files changed, 17 insertions(+), 13 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 2dd0c89b5..07a052f26 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
@@ -105,8 +105,9 @@ class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLay
             playlistAdapter.submitList(it as PagedList<MediaLibraryItem>)
         })
         viewModel.provider.loading.observe(requireActivity(), Observer<Boolean> { loading ->
-            setRefreshing(loading)
-            if (!loading) binding.empty.visibility = if (empty) View.VISIBLE else View.GONE
+            setRefreshing(loading) { refresh ->
+                if (!refresh) binding.empty.visibility = if (empty) View.VISIBLE else View.GONE
+            }
         })
 
         fastScroller.setRecyclerView(getCurrentRV(), viewModel.provider)
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 bd0632a01..09f11b333 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
@@ -226,11 +226,12 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
         })
         provider.loading.observe(viewLifecycleOwner, Observer { loading ->
             if (loading == null || currentTab != index) return at Observer
-            setRefreshing(loading)
-            if (loading) empty_loading.state = EmptyLoadingState.LOADING
-            else {
-                swipeRefreshLayout.isEnabled = (getCurrentRV().layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() <= 0
-                songs_fast_scroller.setRecyclerView(getCurrentRV(), viewModel.providers[currentTab])
+            setRefreshing(loading) { refresh ->
+                if (refresh) empty_loading.state = EmptyLoadingState.LOADING
+                else {
+                    swipeRefreshLayout.isEnabled = (getCurrentRV().layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() <= 0
+                    songs_fast_scroller.setRecyclerView(getCurrentRV(), viewModel.providers[currentTab])
+                }
             }
         })
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
index 06e573195..3736cb8ea 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
@@ -340,11 +340,12 @@ abstract class MediaBrowserFragment<T : SortableModel> : Fragment(), ActionMode.
 
     override fun allowedToExpand() = true
 
-    protected fun setRefreshing(refreshing: Boolean) {
+    protected fun setRefreshing(refreshing: Boolean, action: ((loading: Boolean) -> Unit)? = null) {
         refreshJob = lifecycleScope.launchWhenStarted {
             if (refreshing) delay(300L)
             swipeRefreshLayout.isRefreshing = refreshing
             (activity as? MainActivity)?.refreshing = refreshing
+            action?.invoke(refreshing)
         }
     }
 }
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 c8550d600..7d36ae73b 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
@@ -115,11 +115,12 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
         })
 
         viewModel.provider.loading.observe(this, Observer { loading ->
-            setRefreshing(loading)
-            if (!loading) {
-                setFabPlayVisibility(true)
-                menu?.let { UiTools.updateSortTitles(it, viewModel.provider) }
-                restoreMultiSelectHelper()
+            setRefreshing(loading) { refresh ->
+                if (!refresh) {
+                    setFabPlayVisibility(true)
+                    menu?.let { UiTools.updateSortTitles(it, viewModel.provider) }
+                    restoreMultiSelectHelper()
+                }
             }
         })
         videoListAdapter.showFilename.set(viewModel.groupingType == VideoGroupingType.NONE && viewModel.provider.sort == Medialibrary.SORT_FILENAME)



More information about the Android mailing list