[Android] getAll function for paged viewmodels

Geoffrey Métais git at videolan.org
Thu Sep 6 18:16:31 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep  6 18:08:20 2018 +0200| [3ee988cf0196425c41c92b65f4f37804922a760f] | committer: Geoffrey Métais

getAll function for paged viewmodels

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

 vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt   | 1 +
 .../src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt       | 6 ++++++
 .../src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt      | 2 ++
 .../src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt       | 2 ++
 .../src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt    | 2 ++
 .../src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt       | 2 ++
 6 files changed, 15 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
index a945dafd0..d9e075137 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
@@ -45,6 +45,7 @@ abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableMo
 
     abstract fun getTotalCount() : Int
     abstract fun getPage(loadSize: Int, startposition: Int) : Array<T>
+    abstract fun getAll() : Array<T>?
 
     override fun sort(sort: Int) {
         if (this.sort != sort) {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt
index 0f53603e6..ac62327b1 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt
@@ -28,6 +28,12 @@ class PagedAlbumsModel(context: Context, val parent: MediaLibraryItem? = null) :
         refresh()
     }
 
+    override fun getAll() = when (parent) {
+        is Artist -> parent.getAlbums(sort, desc)
+        is Genre -> parent.getAlbums(sort, desc)
+        else -> medialibrary.getAlbums(sort, desc)
+    }
+
     override fun getPage(loadSize: Int, startposition: Int) : Array<Album> = if (filter == null) when(parent) {
         is Artist -> parent.getPagedAlbums(sort, desc, loadSize, startposition)
         is Genre -> parent.getPagedAlbums(sort, desc, loadSize, startposition)
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt
index ca9f12c9e..2b22efe1a 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt
@@ -24,6 +24,8 @@ class PagedArtistsModel(context: Context, private var showAll: Boolean = false):
         showAll = show
     }
 
+    override fun getAll() = medialibrary.getArtists(showAll, sort, desc)
+
     override fun getPage(loadSize: Int, startposition: Int): Array<Artist> {
         return if (filter == null) medialibrary.getPagedArtists(showAll, sort, desc, loadSize, startposition)
         else medialibrary.searchArtist(filter, sort, desc, loadSize, startposition)
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt
index f403bd3cb..9c56440bb 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt
@@ -25,6 +25,8 @@ class PagedGenresModel(context: Context): MLPagedModel<Genre>(context), Medialib
         medialibrary.removeGenreCb(this)
     }
 
+    override fun getAll() = medialibrary.getGenres(sort, desc)
+
     override fun getPage(loadSize: Int, startposition: Int) = if (filter == null) medialibrary.getPagedGenres(sort, desc, loadSize, startposition)
     else medialibrary.searchGenre(filter, sort, desc, loadSize, startposition)
 
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt
index c02a18376..3187b4750 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt
@@ -20,6 +20,8 @@ class PagedPlaylistsModel(context: Context): MLPagedModel<Playlist>(context), Me
 
     override fun canSortByDuration() = true
 
+    override fun getAll() = medialibrary.getPlaylists(sort, desc)
+
     override fun getPage(loadSize: Int, startposition: Int) = if (filter == null) medialibrary.getPagedPlaylists(sort, desc, loadSize, startposition)
     else medialibrary.searchPlaylist(filter, sort, desc, loadSize, startposition)
 
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt
index 50382cc19..5771b95ae 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt
@@ -45,6 +45,8 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null):
         refresh()
     }
 
+    override fun getAll(): Array<MediaWrapper> = parent?.tracks ?: medialibrary.getAudio(sort, desc)
+
     override fun getPage(loadSize: Int, startposition: Int) : Array<MediaWrapper> = if (filter == null) when(parent) {
         is Artist -> parent.getPagedTracks(sort, desc, loadSize, startposition)
         is Album -> parent.getPagedTracks(sort, desc, loadSize, startposition)



More information about the Android mailing list