[Android] Prevent AudioPlayer viewmodel to be binded twice
Geoffrey Métais
git at videolan.org
Wed Jan 16 15:22:11 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan 16 15:18:27 2019 +0100| [7a47000e2e5f1524bd5babf2394a55b27fd36380] | committer: Geoffrey Métais
Prevent AudioPlayer viewmodel to be binded twice
> https://code.videolan.org/videolan/vlc-android/commit/7a47000e2e5f1524bd5babf2394a55b27fd36380
---
vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 4 ++--
vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt | 8 +++++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 53dbe6eb9..83970ebc6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -158,12 +158,12 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher {
override fun onStart() {
super.onStart()
- helper.onStart()
+ if (!playlistModel.connected) helper.onStart()
}
override fun onStop() {
super.onStop()
- helper.onStop()
+ if (playlistModel.connected) helper.onStop()
}
override fun onSaveInstanceState(outState: Bundle) {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
index 8e976f275..098596c8c 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
@@ -45,6 +45,8 @@ class PlaylistModel : ScopedModel(), PlaybackService.Callback by EmptyPBSCallbac
private var filtering = false
val progress = MediatorLiveData<PlaybackProgress>()
val playerState = MutableLiveData<PlayerState>()
+ val connected : Boolean
+ get() = service !== null
private val filter by lazy(LazyThreadSafetyMode.NONE) { PlaylistFilterDelegate(dataset) }
@@ -85,7 +87,11 @@ class PlaylistModel : ScopedModel(), PlaybackService.Callback by EmptyPBSCallbac
get() = service?.artist
public override fun onCleared() {
- service?.removeCallback(this)
+ service?.apply {
+ removeCallback(this at PlaylistModel)
+ abRepeat.removeSource(playlistManager.abRepeat)
+ progress.removeSource(playlistManager.player.progress)
+ }
super.onCleared()
}
More information about the Android
mailing list