diff --git a/app/src/main/kotlin/ca/ksamad/encore/ui/EncoreApp.kt b/app/src/main/kotlin/ca/ksamad/encore/ui/EncoreApp.kt index 4e6c101..43969ee 100644 --- a/app/src/main/kotlin/ca/ksamad/encore/ui/EncoreApp.kt +++ b/app/src/main/kotlin/ca/ksamad/encore/ui/EncoreApp.kt @@ -1,5 +1,6 @@ package ca.ksamad.encore.ui +import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -75,6 +76,18 @@ fun EncoreApp(vm: PlayerViewModel = viewModel()) { } is AppScreen.Player -> { + // The overlays form a back stack the OS knows nothing about (we don't use a + // nav library). Intercept the system/gesture back button and pop one level so + // it mirrors the on-screen back arrow, instead of falling through and closing + // the app. Only enabled when there's somewhere to pop back to. + BackHandler(enabled = overlay != PlayerOverlay.None) { + if (detailAlbum != null) { + detailAlbum = null + } else { + overlay = PlayerOverlay.None + } + } + when (overlay) { PlayerOverlay.Settings -> { SettingsScreen(vm, onBack = { overlay = PlayerOverlay.None })