feat: keep screen on during playback

This commit is contained in:
2026-02-16 10:36:50 +01:00
parent fe97ff5e73
commit c2a0eb60c8

View File

@@ -1,12 +1,15 @@
package hu.bbara.purefin.player
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.LaunchedEffect
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dagger.hilt.android.AndroidEntryPoint
import hu.bbara.purefin.player.ui.PlayerScreen
import hu.bbara.purefin.player.viewmodel.PlayerViewModel
@@ -22,6 +25,16 @@ class PlayerActivity : ComponentActivity() {
setContent {
PurefinTheme(darkTheme = true) {
val viewModel = hiltViewModel<PlayerViewModel>()
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
LaunchedEffect(uiState.value.isPlaying) {
if (uiState.value.isPlaying) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
PlayerScreen(
viewModel = viewModel,
onBack = { finish() }