Persist full-screen mode across app restarts

This commit is contained in:
Hasinjato 2026-12-01 10:38:14 +03:00
parent 1829fcdb74
commit 4f5e93e182
3 changed files with 17 additions and 12 deletions

View file

@ -15,6 +15,7 @@ import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
@ -91,6 +92,11 @@ class MainActivity : ComponentActivity() {
} }
setContent { setContent {
val isFullScreenEnabled = sharedScreenModel.isFullScreen.value
LaunchedEffect(isFullScreenEnabled) {
updateSystemBarsVisibility(isFullScreenEnabled)
}
KoinAndroidContext { KoinAndroidContext {
CompositionLocalProvider( CompositionLocalProvider(
LocalFullscreenController provides { isFullScreen -> LocalFullscreenController provides { isFullScreen ->

View file

@ -128,14 +128,11 @@ fun MainScreenWithDrawer(
val isFullScreenEnabled by sharedScreenModel.isFullScreen.collectAsState() val isFullScreenEnabled by sharedScreenModel.isFullScreen.collectAsState()
val fullscreenController = LocalFullscreenController.current val fullscreenController = LocalFullscreenController.current
LaunchedEffect(isFullScreenEnabled, isSearchActive) {
fullscreenController(isFullScreenEnabled)
}
val isImeVisible = WindowInsets.ime.asPaddingValues().calculateBottomPadding() > 0.dp val isImeVisible = WindowInsets.ime.asPaddingValues().calculateBottomPadding() > 0.dp
LaunchedEffect(isImeVisible) {
if (!isImeVisible && isFullScreenEnabled) { LaunchedEffect(isFullScreenEnabled, isSearchActive, isImeVisible) {
fullscreenController(true) if (!isImeVisible) {
fullscreenController(isFullScreenEnabled)
} }
} }

View file

@ -737,12 +737,14 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
_harmonyView.value = enabled _harmonyView.value = enabled
} }
private val _isFullScreen = MutableStateFlow(false) val isFullScreenV = prefs.getBoolean("isFullScreen", false)
val isFullScreen = _isFullScreen.asStateFlow() private val _isFullScreen = MutableStateFlow(isFullScreenV)
val isFullScreen = _isFullScreen.asStateFlow()
fun toggleFullScreen(enabled: Boolean) { fun toggleFullScreen(enabled: Boolean) {
_isFullScreen.value = enabled _isFullScreen.value = enabled
} prefs.putBoolean("isFullScreen", enabled)
}
val transpositionInterval = MutableStateFlow(0) val transpositionInterval = MutableStateFlow(0)
fun setTranspositionInterval(interval: Int) { fun setTranspositionInterval(interval: Int) {