[Android] TV: Fix 'now playing' card updates
Geoffrey Métais
git at videolan.org
Fri Jul 5 14:07:48 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jul 5 14:06:12 2019 +0200| [122e5fbab96be73b34cb4556cba6bf1c0a8e990a] | committer: Geoffrey Métais
TV: Fix 'now playing' card updates
> https://code.videolan.org/videolan/vlc-android/commit/122e5fbab96be73b34cb4556cba6bf1c0a8e990a
---
.../org/videolan/vlc/gui/tv/NowPlayingDelegate.kt | 21 ++++++++++++---------
.../org/videolan/vlc/viewmodels/tv/MainTvModel.kt | 4 ++--
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/NowPlayingDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/tv/NowPlayingDelegate.kt
index dfe086a31..f4edfa00f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/NowPlayingDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/NowPlayingDelegate.kt
@@ -28,6 +28,7 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.libvlc.MediaPlayer
import org.videolan.vlc.PlaybackService
+import org.videolan.vlc.media.PlaylistManager
import org.videolan.vlc.util.EmptyPBSCallback
import org.videolan.vlc.viewmodels.tv.MainTvModel
@@ -39,32 +40,34 @@ class NowPlayingDelegate(private val model: MainTvModel): PlaybackService.Callba
private val playbackServiceObserver = Observer<PlaybackService> { service ->
if (service !== null) {
this.service = service
- updateCurrent()
service.addCallback(this)
- } else {
- this.service?.removeCallback(this)
+ } else this.service?.let {
+ it.removeCallback(this)
this.service = null
}
+ updateCurrent()
}
+ private val nowPlayingObserver = Observer<Boolean> { updateCurrent() }
+
init {
PlaybackService.service.observeForever(playbackServiceObserver)
+ PlaylistManager.showAudioPlayer.observeForever(nowPlayingObserver)
}
fun onClear() {
PlaybackService.service.removeObserver(playbackServiceObserver)
+ PlaylistManager.showAudioPlayer.removeObserver(nowPlayingObserver)
}
override fun onMediaPlayerEvent(event: MediaPlayer.Event) {
when (event.type) {
- MediaPlayer.Event.MediaChanged -> updateCurrent()
+ MediaPlayer.Event.Playing -> updateCurrent()
}
}
- private fun updateCurrent() {
- model.run {
- updateAudioCategories()
- if (showHistory) launch { updateHistory() }
- }
+ private fun updateCurrent() = model.run {
+ updateNowPlaying()
+ if (showHistory) launch { updateHistory() }
}
}
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/tv/MainTvModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/tv/MainTvModel.kt
index ce505089c..366330e0e 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/tv/MainTvModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/tv/MainTvModel.kt
@@ -138,7 +138,7 @@ class MainTvModel(app: Application) : AndroidViewModel(app), AbstractMedialibrar
}
}
- private fun updateNowPlaying() = launch {
+ fun updateNowPlaying() = launch {
val list = mutableListOf<MediaLibraryItem>()
PlaybackService.service.value?.run {
currentMediaWrapper?.let {
@@ -159,7 +159,7 @@ class MainTvModel(app: Application) : AndroidViewModel(app), AbstractMedialibrar
}
}
- fun updateAudioCategories() {
+ private fun updateAudioCategories() {
val list = mutableListOf<MediaLibraryItem>(
DummyItem(CATEGORY_ARTISTS, context.getString(R.string.artists), ""),
DummyItem(CATEGORY_ALBUMS, context.getString(R.string.albums), ""),
More information about the Android
mailing list