mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Better playback lifecycle handling (#191)
Refactors lifecycle event observers When the app is "paused", aka not actively focused, but still visible (such as when opening Android TV OS menu), playback will pause. When the app is "stopped", aka not visible (such as pressing Home button), playback will stop, report playback progress, and return to the previous screen. I think this will fix #181, but I don't have a controller to test with
This commit is contained in:
parent
ce8cab0d1f
commit
fbf77b9376
5 changed files with 130 additions and 36 deletions
|
|
@ -37,6 +37,7 @@ import com.github.damontecres.wholphin.ui.nav.Destination
|
|||
import com.github.damontecres.wholphin.ui.nav.NavigationManager
|
||||
import com.github.damontecres.wholphin.ui.theme.WholphinTheme
|
||||
import com.github.damontecres.wholphin.util.AppUpgradeHandler
|
||||
import com.github.damontecres.wholphin.util.PlaybackLifecycleObserver
|
||||
import com.github.damontecres.wholphin.util.ServerEventListener
|
||||
import com.github.damontecres.wholphin.util.UpdateChecker
|
||||
import com.github.damontecres.wholphin.util.profile.createDeviceProfile
|
||||
|
|
@ -70,10 +71,14 @@ class MainActivity : AppCompatActivity() {
|
|||
@Inject
|
||||
lateinit var serverEventListener: ServerEventListener
|
||||
|
||||
@Inject
|
||||
lateinit var playbackLifecycleObserver: PlaybackLifecycleObserver
|
||||
|
||||
@OptIn(ExperimentalTvMaterial3Api::class)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Timber.i("MainActivity.onCreate")
|
||||
super.onCreate(savedInstanceState)
|
||||
lifecycle.addObserver(playbackLifecycleObserver)
|
||||
setContent {
|
||||
CoilConfig(okHttpClient, false)
|
||||
val appPreferences by userPreferencesDataStore.data.collectAsState(null)
|
||||
|
|
@ -175,11 +180,4 @@ class MainActivity : AppCompatActivity() {
|
|||
appUpgradeHandler.run()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
if (navigationManager.backStack.lastOrNull() is Destination.Playback) {
|
||||
navigationManager.goBack()
|
||||
}
|
||||
super.onPause()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue