[Android] Fix paged models callback registration

Geoffrey Métais git at videolan.org
Thu Feb 14 15:59:44 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 14 15:57:07 2019 +0100| [d1c3dd8657e6fd54677f9ef42f145e46c59c81e5] | committer: Geoffrey Métais

Fix paged models callback registration

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

 .../src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt       | 6 +-----
 .../src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt      | 6 +-----
 .../src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt       | 6 +-----
 .../src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt    | 6 +-----
 4 files changed, 4 insertions(+), 20 deletions(-)

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 b281d1187..5b33949ae 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt
@@ -22,6 +22,7 @@ class PagedAlbumsModel(context: Context, val parent: MediaLibraryItem? = null) :
         sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
         desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
         if (sort == Medialibrary.SORT_ALPHA && parent is Artist) sort = Medialibrary.SORT_RELEASEDATE
+        medialibrary.addAlbumsCb(this)
         if (medialibrary.isStarted) refresh()
     }
 
@@ -58,11 +59,6 @@ class PagedAlbumsModel(context: Context, val parent: MediaLibraryItem? = null) :
         else -> medialibrary.getAlbumsCount(filterQuery)
     }
 
-    override fun onMedialibraryReady() {
-        super.onMedialibraryReady()
-        medialibrary.addAlbumsCb(this)
-    }
-
     override fun onCleared() {
         medialibrary.removeAlbumsCb(this)
         super.onCleared()
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 ccfba5fad..ae520e50d 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt
@@ -11,6 +11,7 @@ import org.videolan.vlc.util.EmptyMLCallbacks
 class PagedArtistsModel(context: Context, private var showAll: Boolean = false): MLPagedModel<Artist>(context), Medialibrary.ArtistsCb by EmptyMLCallbacks {
 
     init {
+        medialibrary.addArtistsCb(this)
         if (medialibrary.isStarted) refresh()
     }
     override fun onArtistsAdded() {
@@ -32,11 +33,6 @@ class PagedArtistsModel(context: Context, private var showAll: Boolean = false):
     override fun getTotalCount() = if (filterQuery == null) medialibrary.getArtistsCount(showAll)
     else medialibrary.getArtistsCount(filterQuery)
 
-    override fun onMedialibraryReady() {
-        super.onMedialibraryReady()
-        medialibrary.addArtistsCb(this)
-    }
-
     override fun onCleared() {
         medialibrary.removeArtistsCb(this)
         super.onCleared()
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 765aab81c..4fbfb3c7b 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt
@@ -13,12 +13,8 @@ class PagedGenresModel(context: Context): MLPagedModel<Genre>(context), Medialib
     init {
         sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
         desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
-        if (medialibrary.isStarted) refresh()
-    }
-
-    override fun onMedialibraryReady() {
-        super.onMedialibraryReady()
         medialibrary.addGenreCb(this)
+        if (medialibrary.isStarted) refresh()
     }
 
     override fun onCleared() {
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 9a5ea89fa..f9abe8d1d 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt
@@ -9,12 +9,8 @@ import org.videolan.medialibrary.media.Playlist
 class PagedPlaylistsModel(context: Context): MLPagedModel<Playlist>(context), Medialibrary.PlaylistsCb {
 
     init {
-        if (medialibrary.isStarted) refresh()
-    }
-
-    override fun onMedialibraryReady() {
-        super.onMedialibraryReady()
         medialibrary.addPlaylistCb(this)
+        if (medialibrary.isStarted) refresh()
     }
 
     override fun onCleared() {



More information about the Android mailing list