Commit 59eefe9d authored by Geoffrey Métais's avatar Geoffrey Métais

Clear callbacks on delegates/models death

parent 9582db9c
Pipeline #19179 passed with stage
in 3 minutes and 27 seconds
......@@ -27,6 +27,7 @@ import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.videolan.libvlc.MediaPlayer
......@@ -44,7 +45,9 @@ class NowPlayingDelegate(private val model: MainTvModel): PlaybackService.Callba
init {
PlaylistManager.showAudioPlayer.observeForever(nowPlayingObserver)
PlaybackService.serviceFlow.onEach { onServiceChanged(it) }.launchIn(model.viewModelScope)
PlaybackService.serviceFlow.onEach { onServiceChanged(it) }
.onCompletion { service?.removeCallback(this@NowPlayingDelegate) }
.launchIn(model.viewModelScope)
}
fun onClear() {
......
......@@ -27,6 +27,7 @@ import androidx.lifecycle.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import org.videolan.medialibrary.Tools
import org.videolan.medialibrary.interfaces.media.MediaWrapper
......@@ -61,7 +62,9 @@ class PlaylistModel : ViewModel(), PlaybackService.Callback by EmptyPBSCallback
}
init {
PlaybackService.serviceFlow.onEach { onServiceChanged(it) }.launchIn(viewModelScope)
PlaybackService.serviceFlow.onEach { onServiceChanged(it) }
.onCompletion { onServiceChanged(null) }
.launchIn(viewModelScope)
}
private fun setup(service: PlaybackService) {
......
......@@ -27,6 +27,7 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
......@@ -48,7 +49,9 @@ class StreamsModel(context: Context, private val showDummy: Boolean = false, cor
init {
if (medialibrary.isStarted) refresh()
PlaybackService.serviceFlow.onEach { onServiceChanged(it) }.launchIn(viewModelScope)
PlaybackService.serviceFlow.onEach { onServiceChanged(it) }
.onCompletion { onServiceChanged(null) }
.launchIn(viewModelScope)
}
override suspend fun updateList() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment