Skip to content
Snippets Groups Projects
Commit 59eefe9d authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Clear callbacks on delegates/models death

parent 9582db9c
No related branches found
No related tags found
2 merge requests!644License: Make sure a web browser is installed on the device else fallback on Webview,!639Clear callbacks on delegates/models death
Pipeline #19455 passed with stage
in 20 minutes and 8 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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment