Add `useEnglish` to `SettingsScreen`

This commit is contained in:
Ensar Sarajčić 2023-10-09 13:18:25 +02:00
parent 410f2759fc
commit 30c95833c3
3 changed files with 41 additions and 10 deletions

View File

@ -4,12 +4,14 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS 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.config
import com.simplemobiletools.flashlight.extensions.launchChangeAppLanguageIntent import com.simplemobiletools.flashlight.extensions.launchChangeAppLanguageIntent
import com.simplemobiletools.flashlight.extensions.startCustomizationActivity 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.GeneralSettingsSection
import com.simplemobiletools.flashlight.screens.SettingsScreen import com.simplemobiletools.flashlight.screens.SettingsScreen
import java.util.Locale import java.util.Locale
import kotlin.system.exitProcess
class SettingsActivity : ComponentActivity() { class SettingsActivity : ComponentActivity() {
private val preferences by lazy { config } private val preferences by lazy { config }
@ -40,6 +43,13 @@ class SettingsActivity : ComponentActivity() {
}, },
generalSection = { generalSection = {
val displayLanguage = remember { Locale.getDefault().displayLanguage } 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 turnFlashlightOnStartupFlow by preferences.turnFlashlightOnFlow.collectAsStateWithLifecycle(preferences.turnFlashlightOn)
val forcePortraitModeFlow by preferences.forcePortraitModeFlow.collectAsStateWithLifecycle(preferences.forcePortraitMode) val forcePortraitModeFlow by preferences.forcePortraitModeFlow.collectAsStateWithLifecycle(preferences.forcePortraitMode)
val showBrightDisplayButtonFlow by preferences.brightDisplayFlow.collectAsStateWithLifecycle(preferences.brightDisplay) val showBrightDisplayButtonFlow by preferences.brightDisplayFlow.collectAsStateWithLifecycle(preferences.brightDisplay)
@ -47,7 +57,14 @@ class SettingsActivity : ComponentActivity() {
val showStroboscopeButtonFlow by preferences.stroboscopeFlow.collectAsStateWithLifecycle(preferences.stroboscope) val showStroboscopeButtonFlow by preferences.stroboscopeFlow.collectAsStateWithLifecycle(preferences.stroboscope)
GeneralSettingsSection( GeneralSettingsSection(
showUseEnglish = showUseEnglish,
useEnglishChecked = useEnglishChecked,
showDisplayLanguage = isTiramisuPlus(),
displayLanguage = displayLanguage, displayLanguage = displayLanguage,
onUseEnglishPress = {
config.useEnglish = it
exitProcess(0)
},
onSetupLanguagePress = ::launchChangeAppLanguageIntent, onSetupLanguagePress = ::launchChangeAppLanguageIntent,
turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow, turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow,
forcePortraitModeChecked = forcePortraitModeFlow, forcePortraitModeChecked = forcePortraitModeFlow,

View File

@ -21,13 +21,13 @@ import androidx.compose.ui.unit.dp
import com.simplemobiletools.commons.compose.extensions.AdjustNavigationBarColors import com.simplemobiletools.commons.compose.extensions.AdjustNavigationBarColors
import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.extensions.rememberMutableInteractionSource 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.ActionItem
import com.simplemobiletools.commons.compose.menus.ActionMenu import com.simplemobiletools.commons.compose.menus.ActionMenu
import com.simplemobiletools.commons.compose.menus.OverflowMode 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.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.SimpleTheme import com.simplemobiletools.commons.compose.theme.SimpleTheme
import com.simplemobiletools.flashlight.R import com.simplemobiletools.flashlight.R
@ -51,7 +51,7 @@ internal fun MainScreen(
moreAppsFromUs: () -> Unit, moreAppsFromUs: () -> Unit,
) { ) {
AdjustNavigationBarColors() AdjustNavigationBarColors()
SettingsLazyScaffold( SimpleLazyListScaffold(
customTopBar = { scrolledColor: Color, _: MutableInteractionSource, scrollBehavior: TopAppBarScrollBehavior, statusBarColor: Int, colorTransitionFraction: Float, contrastColor: Color -> customTopBar = { scrolledColor: Color, _: MutableInteractionSource, scrollBehavior: TopAppBarScrollBehavior, statusBarColor: Int, colorTransitionFraction: Float, contrastColor: Color ->
TopAppBar( TopAppBar(
title = {}, title = {},
@ -67,7 +67,7 @@ internal fun MainScreen(
) )
}, },
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
colors = topAppBarColors(statusBarColor, colorTransitionFraction, contrastColor), colors = simpleTopAppBarColors(statusBarColor, colorTransitionFraction, contrastColor),
modifier = Modifier.topAppBarPaddings(), modifier = Modifier.topAppBarPaddings(),
windowInsets = topAppBarInsets() windowInsets = topAppBarInsets()
) )

View File

@ -3,11 +3,10 @@ package com.simplemobiletools.flashlight.screens
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import com.simplemobiletools.commons.compose.extensions.MyDevices 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.*
import com.simplemobiletools.commons.compose.settings.scaffold.SettingsScaffold
import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.SimpleTheme import com.simplemobiletools.commons.compose.theme.SimpleTheme
import com.simplemobiletools.commons.helpers.isTiramisuPlus
import com.simplemobiletools.flashlight.R import com.simplemobiletools.flashlight.R
@Composable @Composable
@ -16,7 +15,7 @@ internal fun SettingsScreen(
generalSection: @Composable () -> Unit, generalSection: @Composable () -> Unit,
goBack: () -> 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 = { SettingsGroup(title = {
SettingsTitleTextComponent(text = stringResource(id = com.simplemobiletools.commons.R.string.color_customization)) SettingsTitleTextComponent(text = stringResource(id = com.simplemobiletools.commons.R.string.color_customization))
}) { }) {
@ -48,12 +47,16 @@ internal fun ColorCustomizationSettingsSection(
@Composable @Composable
internal fun GeneralSettingsSection( internal fun GeneralSettingsSection(
showUseEnglish: Boolean,
useEnglishChecked: Boolean,
showDisplayLanguage: Boolean,
displayLanguage: String, displayLanguage: String,
turnFlashlightOnStartupChecked: Boolean, turnFlashlightOnStartupChecked: Boolean,
forcePortraitModeChecked: Boolean, forcePortraitModeChecked: Boolean,
showBrightDisplayButtonChecked: Boolean, showBrightDisplayButtonChecked: Boolean,
showSosButtonChecked: Boolean, showSosButtonChecked: Boolean,
showStroboscopeButtonChecked: Boolean, showStroboscopeButtonChecked: Boolean,
onUseEnglishPress: (Boolean) -> Unit,
onSetupLanguagePress: () -> Unit, onSetupLanguagePress: () -> Unit,
onTurnFlashlightOnStartupPress: (Boolean) -> Unit, onTurnFlashlightOnStartupPress: (Boolean) -> Unit,
onForcePortraitModePress: (Boolean) -> Unit, onForcePortraitModePress: (Boolean) -> Unit,
@ -61,7 +64,14 @@ internal fun GeneralSettingsSection(
onShowSosButtonPress: (Boolean) -> Unit, onShowSosButtonPress: (Boolean) -> Unit,
onShowStroboscopeButtonPress: (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( SettingsPreferenceComponent(
label = stringResource(id = com.simplemobiletools.commons.R.string.language), label = stringResource(id = com.simplemobiletools.commons.R.string.language),
value = displayLanguage, value = displayLanguage,
@ -109,12 +119,16 @@ private fun SettingsScreenPreview() {
}, },
generalSection = { generalSection = {
GeneralSettingsSection( GeneralSettingsSection(
useEnglishChecked = true,
showUseEnglish = true,
showDisplayLanguage = true,
displayLanguage = "English", displayLanguage = "English",
turnFlashlightOnStartupChecked = false, turnFlashlightOnStartupChecked = false,
forcePortraitModeChecked = true, forcePortraitModeChecked = true,
showBrightDisplayButtonChecked = true, showBrightDisplayButtonChecked = true,
showSosButtonChecked = true, showSosButtonChecked = true,
showStroboscopeButtonChecked = true, showStroboscopeButtonChecked = true,
onUseEnglishPress = {},
onSetupLanguagePress = {}, onSetupLanguagePress = {},
onTurnFlashlightOnStartupPress = {}, onTurnFlashlightOnStartupPress = {},
onForcePortraitModePress = {}, onForcePortraitModePress = {},