From 30c95833c31da7780a1691ef9314b4d509524cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Mon, 9 Oct 2023 13:18:25 +0200 Subject: [PATCH] Add `useEnglish` to `SettingsScreen` --- .../flashlight/activities/SettingsActivity.kt | 17 ++++++++++++++ .../flashlight/screens/MainScreen.kt | 12 +++++----- .../flashlight/screens/SettingsScreen.kt | 22 +++++++++++++++---- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/SettingsActivity.kt index aba51d6..a83ebfa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/SettingsActivity.kt @@ -4,12 +4,14 @@ import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS +import com.simplemobiletools.commons.helpers.isTiramisuPlus import com.simplemobiletools.flashlight.extensions.config import com.simplemobiletools.flashlight.extensions.launchChangeAppLanguageIntent import com.simplemobiletools.flashlight.extensions.startCustomizationActivity @@ -17,6 +19,7 @@ import com.simplemobiletools.flashlight.screens.ColorCustomizationSettingsSectio import com.simplemobiletools.flashlight.screens.GeneralSettingsSection import com.simplemobiletools.flashlight.screens.SettingsScreen import java.util.Locale +import kotlin.system.exitProcess class SettingsActivity : ComponentActivity() { private val preferences by lazy { config } @@ -40,6 +43,13 @@ class SettingsActivity : ComponentActivity() { }, generalSection = { val displayLanguage = remember { Locale.getDefault().displayLanguage } + val useEnglishChecked by preferences.useEnglishFlow.collectAsStateWithLifecycle(preferences.useEnglish) + val wasUseEnglishToggled by preferences.wasUseEnglishToggledFlow.collectAsStateWithLifecycle(preferences.wasUseEnglishToggled) + val showUseEnglish by remember { + derivedStateOf { + (wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus() + } + } val turnFlashlightOnStartupFlow by preferences.turnFlashlightOnFlow.collectAsStateWithLifecycle(preferences.turnFlashlightOn) val forcePortraitModeFlow by preferences.forcePortraitModeFlow.collectAsStateWithLifecycle(preferences.forcePortraitMode) val showBrightDisplayButtonFlow by preferences.brightDisplayFlow.collectAsStateWithLifecycle(preferences.brightDisplay) @@ -47,7 +57,14 @@ class SettingsActivity : ComponentActivity() { val showStroboscopeButtonFlow by preferences.stroboscopeFlow.collectAsStateWithLifecycle(preferences.stroboscope) GeneralSettingsSection( + showUseEnglish = showUseEnglish, + useEnglishChecked = useEnglishChecked, + showDisplayLanguage = isTiramisuPlus(), displayLanguage = displayLanguage, + onUseEnglishPress = { + config.useEnglish = it + exitProcess(0) + }, onSetupLanguagePress = ::launchChangeAppLanguageIntent, turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow, forcePortraitModeChecked = forcePortraitModeFlow, diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/MainScreen.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/MainScreen.kt index 7d8a228..7c4bd3d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/MainScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/MainScreen.kt @@ -21,13 +21,13 @@ import androidx.compose.ui.unit.dp import com.simplemobiletools.commons.compose.extensions.AdjustNavigationBarColors import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.extensions.rememberMutableInteractionSource +import com.simplemobiletools.commons.compose.lists.SimpleLazyListScaffold +import com.simplemobiletools.commons.compose.lists.simpleTopAppBarColors +import com.simplemobiletools.commons.compose.lists.topAppBarInsets +import com.simplemobiletools.commons.compose.lists.topAppBarPaddings import com.simplemobiletools.commons.compose.menus.ActionItem import com.simplemobiletools.commons.compose.menus.ActionMenu import com.simplemobiletools.commons.compose.menus.OverflowMode -import com.simplemobiletools.commons.compose.settings.scaffold.SettingsLazyScaffold -import com.simplemobiletools.commons.compose.settings.scaffold.topAppBarColors -import com.simplemobiletools.commons.compose.settings.scaffold.topAppBarInsets -import com.simplemobiletools.commons.compose.settings.scaffold.topAppBarPaddings import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.SimpleTheme import com.simplemobiletools.flashlight.R @@ -51,7 +51,7 @@ internal fun MainScreen( moreAppsFromUs: () -> Unit, ) { AdjustNavigationBarColors() - SettingsLazyScaffold( + SimpleLazyListScaffold( customTopBar = { scrolledColor: Color, _: MutableInteractionSource, scrollBehavior: TopAppBarScrollBehavior, statusBarColor: Int, colorTransitionFraction: Float, contrastColor: Color -> TopAppBar( title = {}, @@ -67,7 +67,7 @@ internal fun MainScreen( ) }, scrollBehavior = scrollBehavior, - colors = topAppBarColors(statusBarColor, colorTransitionFraction, contrastColor), + colors = simpleTopAppBarColors(statusBarColor, colorTransitionFraction, contrastColor), modifier = Modifier.topAppBarPaddings(), windowInsets = topAppBarInsets() ) diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/SettingsScreen.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/SettingsScreen.kt index b5ec7d0..35c3c51 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/SettingsScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/SettingsScreen.kt @@ -3,11 +3,10 @@ package com.simplemobiletools.flashlight.screens import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import com.simplemobiletools.commons.compose.extensions.MyDevices +import com.simplemobiletools.commons.compose.lists.SimpleColumnScaffold import com.simplemobiletools.commons.compose.settings.* -import com.simplemobiletools.commons.compose.settings.scaffold.SettingsScaffold import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.SimpleTheme -import com.simplemobiletools.commons.helpers.isTiramisuPlus import com.simplemobiletools.flashlight.R @Composable @@ -16,7 +15,7 @@ internal fun SettingsScreen( generalSection: @Composable () -> Unit, goBack: () -> Unit, ) { - SettingsScaffold(title = stringResource(id = com.simplemobiletools.commons.R.string.settings), goBack = goBack) { + SimpleColumnScaffold(title = stringResource(id = com.simplemobiletools.commons.R.string.settings), goBack = goBack) { SettingsGroup(title = { SettingsTitleTextComponent(text = stringResource(id = com.simplemobiletools.commons.R.string.color_customization)) }) { @@ -48,12 +47,16 @@ internal fun ColorCustomizationSettingsSection( @Composable internal fun GeneralSettingsSection( + showUseEnglish: Boolean, + useEnglishChecked: Boolean, + showDisplayLanguage: Boolean, displayLanguage: String, turnFlashlightOnStartupChecked: Boolean, forcePortraitModeChecked: Boolean, showBrightDisplayButtonChecked: Boolean, showSosButtonChecked: Boolean, showStroboscopeButtonChecked: Boolean, + onUseEnglishPress: (Boolean) -> Unit, onSetupLanguagePress: () -> Unit, onTurnFlashlightOnStartupPress: (Boolean) -> Unit, onForcePortraitModePress: (Boolean) -> Unit, @@ -61,7 +64,14 @@ internal fun GeneralSettingsSection( onShowSosButtonPress: (Boolean) -> Unit, onShowStroboscopeButtonPress: (Boolean) -> Unit, ) { - if (isTiramisuPlus()) { + if (showUseEnglish) { + SettingsCheckBoxComponent( + label = stringResource(id = com.simplemobiletools.commons.R.string.use_english_language), + initialValue = useEnglishChecked, + onChange = onUseEnglishPress + ) + } + if (showDisplayLanguage) { SettingsPreferenceComponent( label = stringResource(id = com.simplemobiletools.commons.R.string.language), value = displayLanguage, @@ -109,12 +119,16 @@ private fun SettingsScreenPreview() { }, generalSection = { GeneralSettingsSection( + useEnglishChecked = true, + showUseEnglish = true, + showDisplayLanguage = true, displayLanguage = "English", turnFlashlightOnStartupChecked = false, forcePortraitModeChecked = true, showBrightDisplayButtonChecked = true, showSosButtonChecked = true, showStroboscopeButtonChecked = true, + onUseEnglishPress = {}, onSetupLanguagePress = {}, onTurnFlashlightOnStartupPress = {}, onForcePortraitModePress = {},