[Android] Paging: Fix refresh from paged lists
Geoffrey Métais
git at videolan.org
Fri Jun 21 09:29:10 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun 21 09:28:21 2019 +0200| [8743f87a509a809cb8af4fda3c49abf4b68f5b86] | committer: Geoffrey Métais
Paging: Fix refresh from paged lists
> https://code.videolan.org/videolan/vlc-android/commit/8743f87a509a809cb8af4fda3c49abf4b68f5b86
---
.../org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt | 2 +-
.../src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt | 1 -
.../src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt | 1 -
.../src/org/videolan/vlc/viewmodels/mobile/FoldersViewModel.kt | 4 ----
.../src/org/videolan/vlc/viewmodels/mobile/PlaylistViewModel.kt | 1 -
.../src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt | 4 ----
vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt | 4 ----
7 files changed, 1 insertion(+), 16 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt b/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
index 512b9ef59..58689283b 100644
--- a/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
@@ -88,7 +88,7 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
}
fun refresh(): Boolean {
- if (isRefreshing || !medialibrary.isStarted) return false
+ if (isRefreshing || !medialibrary.isStarted || !this::dataSource.isInitialized) return false
headers.clear()
if (!dataSource.isInvalid) {
loading.postValue(true)
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt
index c223976ba..8e5d388fb 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt
@@ -52,7 +52,6 @@ class AlbumSongsViewModel(context: Context, val parent: MediaLibraryItem) : Medi
is Album -> medialibrary.addAlbumsCb(this at AlbumSongsViewModel)
else -> medialibrary.addMediaCb(this at AlbumSongsViewModel)
}
- if (medialibrary.isStarted) refresh()
}
override fun onMediaAdded() { refresh() }
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
index 07994cfa2..221b75a95 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
@@ -59,7 +59,6 @@ class AudioBrowserViewModel(context: Context) : MedialibraryViewModel(context),
medialibrary.addAlbumsCb(this)
medialibrary.addGenreCb(this)
medialibrary.addMediaCb(this)
- if (medialibrary.isStarted) refresh()
}
override fun onCleared() {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/FoldersViewModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/FoldersViewModel.kt
index 97152ce2a..dcc294a72 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/FoldersViewModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/FoldersViewModel.kt
@@ -41,10 +41,6 @@ class FoldersViewModel(context: Context, val type : Int) : MedialibraryViewModel
val provider = FoldersProvider(context, this, type)
override val providers: Array<MedialibraryProvider<out MediaLibraryItem>> = arrayOf(provider)
- init {
- if (medialibrary.isStarted) refresh()
- }
-
suspend fun play(position: Int) {
val list = withContext(Dispatchers.IO) { provider.pagedList.value?.get(position)?.getAll()}
list?.let { MediaUtils.openList(context, it, 0) }
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistViewModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistViewModel.kt
index 955e46d80..fb561c67a 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistViewModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistViewModel.kt
@@ -51,7 +51,6 @@ class PlaylistViewModel(context: Context, val playlist: MediaLibraryItem) : Medi
is Album -> medialibrary.addAlbumsCb(this at PlaylistViewModel)
else -> medialibrary.addMediaCb(this at PlaylistViewModel)
}
- if (medialibrary.isStarted) refresh()
}
override fun onMediaAdded() { refresh() }
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
index 27c66f70b..f7681692f 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
@@ -38,10 +38,6 @@ class PlaylistsViewModel(context: Context) : MedialibraryViewModel(context) {
val provider = PlaylistsProvider(context, this)
override val providers : Array<MedialibraryProvider<out MediaLibraryItem>> = arrayOf(provider)
- init {
- if (medialibrary.isStarted) refresh()
- }
-
class Factory(val context: Context): ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
index c36c2c4c5..5248342d0 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
@@ -38,10 +38,6 @@ class VideosViewModel(context: Context, val folder: Folder?) : MedialibraryViewM
val provider = VideosProvider(folder, context, this)
override val providers: Array<MedialibraryProvider<out MediaLibraryItem>> = arrayOf(provider)
- init {
- if (medialibrary.isStarted) refresh()
- }
-
class Factory(val context: Context, val folder: Folder?): ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
More information about the Android
mailing list