all: make callbacks initialize impls
Make addCallback calls (or similar) initalize the caller by calling the specific callback methods. This is primarily intended as a fix to an issue where the music library would actually reload during a warm start. This is extremely bad, but I hope it doesn't make the app too unusable until the next version.
This commit is contained in:
parent
47726c3e02
commit
48289ef006
6 changed files with 11 additions and 27 deletions
|
@ -54,6 +54,7 @@ class MusicStore private constructor() {
|
|||
private val callbacks = mutableListOf<Callback>()
|
||||
|
||||
fun addCallback(callback: Callback) {
|
||||
response?.let(callback::onMusicUpdate)
|
||||
callbacks.add(callback)
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class MusicViewModel : ViewModel(), MusicStore.Callback {
|
|||
* navigated to and because SnackBars will have the best UX here.
|
||||
*/
|
||||
fun loadMusic(context: Context) {
|
||||
if (musicStore.library != null || isBusy) {
|
||||
if (_loaderResponse.value != null || isBusy) {
|
||||
logD("Loader is busy/already completed, not reloading")
|
||||
return
|
||||
}
|
||||
|
|
|
@ -83,18 +83,6 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback, MusicStore
|
|||
init {
|
||||
musicStore.addCallback(this)
|
||||
playbackManager.addCallback(this)
|
||||
|
||||
// If the PlaybackViewModel was cleared [Signified by PlaybackStateManager still being
|
||||
// around & the fact that we are in the init function], then attempt to restore the
|
||||
// ViewModel state. If it isn't, then wait for MainFragment to give the command to restore
|
||||
// PlaybackStateManager.
|
||||
if (playbackManager.isInitialized) {
|
||||
onNewPlayback(playbackManager.index, playbackManager.queue, playbackManager.parent)
|
||||
onPositionChanged(playbackManager.positionMs)
|
||||
onPlayingChanged(playbackManager.isPlaying)
|
||||
onShuffledChanged(playbackManager.isShuffled)
|
||||
onRepeatChanged(playbackManager.repeatMode)
|
||||
}
|
||||
}
|
||||
|
||||
// --- PLAYING FUNCTIONS ---
|
||||
|
|
|
@ -96,6 +96,15 @@ class PlaybackStateManager private constructor() {
|
|||
* [removeCallback] when done.
|
||||
*/
|
||||
fun addCallback(callback: Callback) {
|
||||
if (isInitialized) {
|
||||
callback.onNewPlayback(index, queue, parent)
|
||||
callback.onSeek(positionMs)
|
||||
callback.onPositionChanged(positionMs)
|
||||
callback.onRepeatChanged(repeatMode)
|
||||
callback.onShuffledChanged(isShuffled)
|
||||
callback.onPlayingChanged(isPlaying)
|
||||
}
|
||||
|
||||
callbacks.add(callback)
|
||||
}
|
||||
|
||||
|
|
|
@ -55,13 +55,6 @@ class MediaSessionComponent(private val context: Context, private val player: Pl
|
|||
playbackManager.addCallback(this)
|
||||
settingsManager.addCallback(this)
|
||||
mediaSession.setCallback(this)
|
||||
|
||||
if (playbackManager.isInitialized) {
|
||||
updateMediaMetadata(playbackManager.song)
|
||||
invalidateSessionState()
|
||||
onRepeatChanged(playbackManager.repeatMode)
|
||||
onShuffledChanged(playbackManager.isShuffled)
|
||||
}
|
||||
}
|
||||
|
||||
fun release() {
|
||||
|
|
|
@ -139,13 +139,6 @@ class PlaybackService :
|
|||
// --- PLAYBACKSTATEMANAGER SETUP ---
|
||||
|
||||
playbackManager.addCallback(this)
|
||||
if (playbackManager.isInitialized) {
|
||||
loadSong(playbackManager.song)
|
||||
onSeek(playbackManager.positionMs)
|
||||
onPlayingChanged(playbackManager.isPlaying)
|
||||
onShuffledChanged(playbackManager.isShuffled)
|
||||
onRepeatChanged(playbackManager.repeatMode)
|
||||
}
|
||||
|
||||
// --- SETTINGSMANAGER SETUP ---
|
||||
|
||||
|
|
Loading…
Reference in a new issue