mirror of
https://github.com/jellyfin/jellyfin-android.git
synced 2026-09-03 05:10:27 +03:00
Refactor ViewModel teardown
Remove never called onDestroy from LifecycleObserver, dismiss notification in ViewModel onCleared instead, if necessary
This commit is contained in:
@@ -22,10 +22,4 @@ class PlayerLifecycleObserver(private val viewModel: PlayerViewModel) : Lifecycl
|
||||
viewModel.notificationHelper.postNotification()
|
||||
} else viewModel.pause()
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
fun onDestroy() {
|
||||
viewModel.notificationHelper.dismissNotification()
|
||||
viewModel.releasePlayer()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application),
|
||||
/**
|
||||
* Release the current ExoPlayer and stop/release the current MediaSession
|
||||
*/
|
||||
fun releasePlayer() {
|
||||
private fun releasePlayer() {
|
||||
mediaSession.isActive = false
|
||||
mediaSession.release()
|
||||
val playerState = playerOrNull?.let { player ->
|
||||
@@ -256,8 +256,8 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application),
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
releasePlayer()
|
||||
ProcessLifecycleOwner.get().lifecycle.removeObserver(lifecycleObserver)
|
||||
notificationHelper.dismissNotification()
|
||||
releasePlayer()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user