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 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,

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.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()
)

View File

@ -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 = {},