mirror of
https://github.com/bbara04/Purefin.git
synced 2026-03-31 17:10:08 +02:00
feat: keep screen on during playback
This commit is contained in:
@@ -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() }
|
||||
|
||||
Reference in New Issue
Block a user