[Android] ViewModels: unsubscribe CBs before cancelling jobs
Geoffrey Métais
git at videolan.org
Fri Sep 28 17:32:03 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Sep 28 17:30:59 2018 +0200| [0ec663e6464da19d14860d054db558ea35ca4d18] | committer: Geoffrey Métais
ViewModels: unsubscribe CBs before cancelling jobs
> https://code.videolan.org/videolan/vlc-android/commit/0ec663e6464da19d14860d054db558ea35ca4d18
---
vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt | 1 +
vlc-android/src/org/videolan/vlc/viewmodels/VideosModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/audio/AlbumModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/audio/ArtistModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/audio/GenresModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/audio/PlaylistsModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/audio/TracksModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt | 1 +
vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt | 2 +-
.../src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt | 2 +-
vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt | 2 +-
14 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
index dccbaf7b1..ca1f1b21d 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
@@ -76,6 +76,7 @@ class PlaylistModel(private val service: PlaybackService) : ScopedModel(), Playb
public override fun onCleared() {
service.removeCallback(this)
+ super.onCleared()
}
fun getPlaylistPosition(position: Int, media: MediaWrapper): Int {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/VideosModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/VideosModel.kt
index c442c4ef3..a4a619537 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/VideosModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/VideosModel.kt
@@ -91,9 +91,9 @@ open class VideosModel(context: Context, private val group: String?, private val
}
override fun onCleared() {
- super.onCleared()
medialibrary.removeMediaCb(this)
Medialibrary.lastThumb.removeObserver(thumbObs)
+ super.onCleared()
}
fun getListWithPosition(list: MutableList<MediaWrapper>, position: Int): Int {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/audio/AlbumModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/audio/AlbumModel.kt
index d79ee66fc..6b182fa31 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/audio/AlbumModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/audio/AlbumModel.kt
@@ -66,8 +66,8 @@ class AlbumModel(context: Context, val parent: MediaLibraryItem? = null): AudioM
}
override fun onCleared() {
- super.onCleared()
medialibrary.removeAlbumsCb(this)
+ super.onCleared()
}
class Factory(private val context: Context, val parent: MediaLibraryItem?): ViewModelProvider.NewInstanceFactory() {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/audio/ArtistModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/audio/ArtistModel.kt
index 97e35273d..5475bf250 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/audio/ArtistModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/audio/ArtistModel.kt
@@ -56,8 +56,8 @@ class ArtistModel(context: Context, private var showAll: Boolean = false): Audio
}
override fun onCleared() {
- super.onCleared()
medialibrary.removeArtistsCb(this)
+ super.onCleared()
}
override fun onArtistsAdded() {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/audio/GenresModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/audio/GenresModel.kt
index c88fbf14e..5aa2e2ad4 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/audio/GenresModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/audio/GenresModel.kt
@@ -45,8 +45,8 @@ class GenresModel(context: Context): AudioModel(context), Medialibrary.GenresCb
}
override fun onCleared() {
- super.onCleared()
medialibrary.removeGenreCb(this)
+ super.onCleared()
}
@Suppress("UNCHECKED_CAST")
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/audio/PlaylistsModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/audio/PlaylistsModel.kt
index 87c157070..91665c28b 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/audio/PlaylistsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/audio/PlaylistsModel.kt
@@ -39,8 +39,8 @@ class PlaylistsModel(context: Context): AudioModel(context), Medialibrary.Playli
}
override fun onCleared() {
- super.onCleared()
medialibrary.removePlaylistCb(this)
+ super.onCleared()
}
override fun canSortByDuration() = true
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/audio/TracksModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/audio/TracksModel.kt
index 81aceef3d..87e7da2c7 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/audio/TracksModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/audio/TracksModel.kt
@@ -52,8 +52,8 @@ class TracksModel(context: Context, val parent: MediaLibraryItem? = null): Audio
}
override fun onCleared() {
- super.onCleared()
medialibrary.removeMediaCb(this)
+ super.onCleared()
}
override fun onMediaAdded() {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
index bdd9a899c..79c0a9c12 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
@@ -72,6 +72,7 @@ open class BrowserModel(context: Context, val url: String?, type: Int, showHidde
override fun onCleared() {
provider.release()
+ super.onCleared()
}
fun addCustomDirectory(path: String) = DirectoryRepository.getInstance(context).addCustomDirectory(path)
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 bb90cc179..f688be945 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
@@ -40,8 +40,8 @@ abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableMo
}
override fun onCleared() {
- super.onCleared()
medialibrary.removeOnMedialibraryReadyListener(this)
+ super.onCleared()
}
abstract fun getTotalCount() : Int
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 307e4227a..7000209a1 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedAlbumsModel.kt
@@ -60,8 +60,8 @@ class PagedAlbumsModel(context: Context, val parent: MediaLibraryItem? = null) :
}
override fun onCleared() {
- super.onCleared()
medialibrary.removeAlbumsCb(this)
+ super.onCleared()
}
class Factory(private val context: Context, val parent: MediaLibraryItem?) : ViewModelProvider.NewInstanceFactory() {
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 7a92f6fec..c7e89da57 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedArtistsModel.kt
@@ -40,8 +40,8 @@ class PagedArtistsModel(context: Context, private var showAll: Boolean = false):
}
override fun onCleared() {
- super.onCleared()
medialibrary.removeArtistsCb(this)
+ super.onCleared()
}
class Factory(private val context: Context, private val showAll: Boolean): ViewModelProvider.NewInstanceFactory() {
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 00dec7ea5..6456971f5 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedGenresModel.kt
@@ -21,8 +21,8 @@ class PagedGenresModel(context: Context): MLPagedModel<Genre>(context), Medialib
}
override fun onCleared() {
- super.onCleared()
medialibrary.removeGenreCb(this)
+ super.onCleared()
}
override fun getAll() : Array<Genre> = medialibrary.getGenres(sort, desc)
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 622c30b1b..366229bb9 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedPlaylistsModel.kt
@@ -14,8 +14,8 @@ class PagedPlaylistsModel(context: Context): MLPagedModel<Playlist>(context), Me
}
override fun onCleared() {
- super.onCleared()
medialibrary.removePlaylistCb(this)
+ super.onCleared()
}
override fun canSortByDuration() = true
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 23ae1927a..2b5896c83 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt
@@ -47,7 +47,6 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null):
}
override fun onCleared() {
- super.onCleared()
when (parent) {
is Artist -> medialibrary.removeArtistsCb(this)
is Album -> medialibrary.removeAlbumsCb(this)
@@ -55,6 +54,7 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null):
is Playlist -> medialibrary.removePlaylistCb(this)
else -> medialibrary.removeMediaCb(this)
}
+ super.onCleared()
}
override fun getAll(): Array<MediaWrapper> = parent?.tracks ?: medialibrary.getAudio(sort, desc)
More information about the Android
mailing list