From b4e9578d5e9be673dd3993b29fad6c100aff45b2 Mon Sep 17 00:00:00 2001 From: Hasinjato Date: Tue, 16 Jun 2026 15:20:26 +0300 Subject: [PATCH] Move search to TopAppBar & Android fullscreen toggle in Settings --- .../kotlin/mg/dot/feufaro/MainActivity.kt | 27 ++++++++++- .../kotlin/mg/dot/feufaro/ScreenSolfa.kt | 45 ++++++------------- .../kotlin/mg/dot/feufaro/ui/Settings.kt | 38 +++++++++++----- .../mg/dot/feufaro/ui/SimpleDrawerContent.kt | 2 +- .../feufaro/viewmodel/SharedScreenModel.kt | 6 +++ 5 files changed, 73 insertions(+), 45 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt index 7c6c219..aa5a1b2 100644 --- a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt @@ -13,11 +13,13 @@ import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.tooling.preview.Preview import androidx.core.app.ActivityCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat +import mg.dot.feufaro.ui.LocalFullscreenController import org.koin.androidx.compose.KoinAndroidContext import java.io.File import java.util.zip.GZIPInputStream @@ -37,16 +39,37 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) setFilePickerActivity(this) WindowCompat.setDecorFitsSystemWindows(window, false) - hideSystemBar() intent?.let { handleDeepLinkIntent(it) } setContent { KoinAndroidContext { - App() + CompositionLocalProvider( + LocalFullscreenController provides { isFullScreen -> + updateSystemBarsVisibility(isFullScreen) + } + ) { + App() + } } } } + fun updateSystemBarsVisibility(isFullScreen: Boolean) { + val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView) + + if (isFullScreen) { + windowInsetsController.hide(WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars()) + windowInsetsController.systemBarsBehavior = + WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + window.attributes.layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + } + } else { + windowInsetsController.show(WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars()) + } + } @Suppress("OVERRIDE_DEPRECATION") override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ScreenSolfa.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ScreenSolfa.kt index 9b43244..786695d 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ScreenSolfa.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ScreenSolfa.kt @@ -3,42 +3,17 @@ package mg.dot.feufaro import SharedScreenModel import androidx.compose.foundation.background import androidx.compose.foundation.gestures.detectTapGestures -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.FlowRow -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.ime -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.safeDrawing -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.layout.windowInsetsPadding +import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.Edit import androidx.compose.material3.Icon import androidx.compose.material3.IconToggleButton -import androidx.compose.material3.Switch import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset @@ -50,9 +25,6 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Popup -import mg.dot.feufaro.solfa.LazyVerticalGridTUO -import mg.dot.feufaro.ui.MainScreenWithDrawer -import kotlin.math.roundToInt import cafe.adriel.voyager.core.screen.Screen import cafe.adriel.voyager.koin.koinScreenModel import kotlinx.coroutines.Dispatchers @@ -60,9 +32,12 @@ import kotlinx.coroutines.launch import mg.dot.feufaro.data.GridTUOData import mg.dot.feufaro.solfa.ColorPrefixB import mg.dot.feufaro.solfa.EditSourceCompose +import mg.dot.feufaro.solfa.LazyVerticalGridTUO +import mg.dot.feufaro.ui.MainScreenWithDrawer import mg.dot.feufaro.ui.MyVerticalScrollbar import mg.dot.feufaro.viewmodel.SolfaScreenModel import java.io.ObjectStreamException +import kotlin.math.roundToInt object ScreenSolfa : Screen { @Composable @@ -92,6 +67,7 @@ object ScreenSolfa : Screen { } val tuoEditState by sharedScreenModel.tuoEditState.collectAsState() + val isFullScreenEnabled by sharedScreenModel.isFullScreen.collectAsState() LaunchedEffect(tuoEditState) { tuoEditState?.let { state -> @@ -116,11 +92,16 @@ object ScreenSolfa : Screen { }, solfaScrollState = scrollState ) { paddingValues -> + val partitionInsets = if (isFullScreenEnabled) { + WindowInsets(0, 0, 0, 0) + } else { + WindowInsets.ime + } Box( Modifier.fillMaxSize() .padding(paddingValues) - .windowInsetsPadding(WindowInsets.safeDrawing) - .windowInsetsPadding(WindowInsets.ime) + .consumeWindowInsets(paddingValues) + .windowInsetsPadding(partitionInsets) .padding(horizontal = 16.dp) ) { Column( diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/Settings.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/Settings.kt index 2ff6639..799cb96 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/Settings.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/Settings.kt @@ -20,19 +20,25 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import SharedScreenModel +import androidx.compose.material.icons.automirrored.filled.Undo +import mg.dot.feufaro.getPlatform import mg.dot.feufaro.midi.Dynamic @OptIn(ExperimentalMaterial3Api::class) @Composable fun Settings( + sharedScreenModel: SharedScreenModel, onDismissRequest: () -> Unit ) { var isDynamicEnabled by remember { mutableStateOf(Dynamic.isGloballyEnabled) } var refreshTrigger by remember { mutableStateOf(0) } - var expandedGeneral by remember { mutableStateOf(false) } + var expandedGeneral by remember { mutableStateOf(true) } var expandedPrint by remember { mutableStateOf(false) } - var expandedAudio by remember { mutableStateOf(true) } - + var expandedAudio by remember { mutableStateOf(false) } + val isFullScreenEnabled by sharedScreenModel.isFullScreen.collectAsState() + val platform = getPlatform() + val isAndroid = platform.name.startsWith("Android") AlertDialog( onDismissRequest = onDismissRequest, title = { @@ -60,12 +66,20 @@ fun Settings( modifier = Modifier.padding(8.dp), verticalArrangement = Arrangement.spacedBy(10.dp) ) { - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - + if(isAndroid) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Text("Mode Plein Écran") + Switch( + checked = isFullScreenEnabled, + onCheckedChange = { isChecked -> + sharedScreenModel.toggleFullScreen(isChecked) + } + ) + } } } } @@ -128,7 +142,11 @@ fun Settings( ), contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp) ) { - Text("Réinitialiser", fontSize = 14.sp) + Icon( + imageVector = Icons.AutoMirrored.Default.Undo, + contentDescription = null, + tint = Color.Red + ) } } } diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/SimpleDrawerContent.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/SimpleDrawerContent.kt index eb7fa8c..ceb1b5b 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/SimpleDrawerContent.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/SimpleDrawerContent.kt @@ -58,7 +58,7 @@ fun SimpleDrawerContent( val playList by sharedScreenModel.playlistItems.collectAsState() val listState = rememberLazyListState() - var internalExpanded by remember { mutableStateOf(true) } + var internalExpanded by remember { mutableStateOf(false) } var externalExpanded by remember { mutableStateOf(false) } var playListExpanded by remember { mutableStateOf(false) } diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/viewmodel/SharedScreenModel.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/viewmodel/SharedScreenModel.kt index 3074c7b..2c0b5f2 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/viewmodel/SharedScreenModel.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/viewmodel/SharedScreenModel.kt @@ -226,6 +226,12 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode fun toggleEditorMode(enabled: Boolean) { _modeEditor.value = enabled } + private val _isFullScreen = MutableStateFlow(false) + val isFullScreen = _isFullScreen.asStateFlow() + + fun toggleFullScreen(enabled: Boolean) { + _isFullScreen.value = enabled + } val transpositionInterval = MutableStateFlow(0) fun setTranspositionInterval(interval: Int) {