[Android] Fix the audio screen loading delayed by medialibrary scan
Nicolas Pomepuy
git at videolan.org
Thu Oct 13 15:09:29 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Oct 13 15:05:06 2022 +0200| [cb196b9be1b98730f9fca942df341304dd5ae080] | committer: Nicolas Pomepuy
Fix the audio screen loading delayed by medialibrary scan
Fixes #2714
> https://code.videolan.org/videolan/vlc-android/commit/cb196b9be1b98730f9fca942df341304dd5ae080
---
.../videolan/vlc/gui/audio/AudioBrowserFragment.kt | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 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 2c244b1d4..eab4b2dc7 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
@@ -36,6 +36,7 @@ import androidx.viewpager.widget.ViewPager
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.tabs.TabLayout
+import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
@@ -192,15 +193,18 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
private fun setupProvider(index: Int = viewModel.currentTab) {
val provider = viewModel.providers[index.coerceIn(0, viewModel.providers.size - 1)]
if (provider.loading.hasObservers()) return
- provider.pagedList.observe(viewLifecycleOwner) { items ->
- @Suppress("UNCHECKED_CAST")
- if (items != null) adapters.getOrNull(index)?.submitList(items as PagedList<MediaLibraryItem>?)
- updateEmptyView()
- restorePositions.get(index)?.let {
- lists[index].scrollToPosition(it)
- restorePositions.delete(index)
+ lifecycleScope.launch {
+ waitForML()
+ provider.pagedList.observe(viewLifecycleOwner) { items ->
+ @Suppress("UNCHECKED_CAST")
+ if (items != null) adapters.getOrNull(index)?.submitList(items as PagedList<MediaLibraryItem>?)
+ updateEmptyView()
+ restorePositions.get(index)?.let {
+ lists[index].scrollToPosition(it)
+ restorePositions.delete(index)
+ }
+ setFabPlayShuffleAllVisibility(items.isNotEmpty())
}
- setFabPlayShuffleAllVisibility(items.isNotEmpty())
}
provider.loading.observe(viewLifecycleOwner) { loading ->
if (loading == null || currentTab != index) return at observe
More information about the Android
mailing list