mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-02-16 20:00:40 +01:00
Split SettingsScreen
into sections
This commit is contained in:
parent
2f6000db6a
commit
9e3b207509
@ -13,6 +13,8 @@ import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
|
||||
import com.simplemobiletools.flashlight.extensions.config
|
||||
import com.simplemobiletools.flashlight.extensions.launchChangeAppLanguageIntent
|
||||
import com.simplemobiletools.flashlight.extensions.startCustomizationActivity
|
||||
import com.simplemobiletools.flashlight.screens.ColorCustomizationSettingsSection
|
||||
import com.simplemobiletools.flashlight.screens.GeneralSettingsSection
|
||||
import com.simplemobiletools.flashlight.screens.SettingsScreen
|
||||
import java.util.Locale
|
||||
|
||||
@ -24,42 +26,50 @@ class SettingsActivity : ComponentActivity() {
|
||||
enableEdgeToEdgeSimple()
|
||||
setContent {
|
||||
AppThemeSurface {
|
||||
val displayLanguage = remember { Locale.getDefault().displayLanguage }
|
||||
val turnFlashlightOnStartupFlow by preferences.turnFlashlightOnFlow.collectAsStateWithLifecycle(preferences.turnFlashlightOn)
|
||||
val forcePortraitModeFlow by preferences.forcePortraitModeFlow.collectAsStateWithLifecycle(preferences.forcePortraitMode)
|
||||
val showBrightDisplayButtonFlow by preferences.brightDisplayFlow.collectAsStateWithLifecycle(preferences.brightDisplay)
|
||||
val showSosButtonFlow by preferences.sosFlow.collectAsStateWithLifecycle(preferences.sos)
|
||||
val showStroboscopeButtonFlow by preferences.stroboscopeFlow.collectAsStateWithLifecycle(preferences.stroboscope)
|
||||
|
||||
SettingsScreen(
|
||||
displayLanguage = displayLanguage,
|
||||
onSetupLanguagePress = ::launchChangeAppLanguageIntent,
|
||||
customizeColors = ::startCustomizationActivity,
|
||||
turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow,
|
||||
forcePortraitModeChecked = forcePortraitModeFlow,
|
||||
showBrightDisplayButtonChecked = showBrightDisplayButtonFlow,
|
||||
showSosButtonChecked = showSosButtonFlow,
|
||||
showStroboscopeButtonChecked = showStroboscopeButtonFlow,
|
||||
customizeWidgetColors = {
|
||||
Intent(this, WidgetTorchConfigureActivity::class.java).apply {
|
||||
putExtra(IS_CUSTOMIZING_COLORS, true)
|
||||
startActivity(this)
|
||||
}
|
||||
colorCustomizationSection = {
|
||||
ColorCustomizationSettingsSection(
|
||||
customizeColors = ::startCustomizationActivity,
|
||||
customizeWidgetColors = {
|
||||
Intent(this, WidgetTorchConfigureActivity::class.java).apply {
|
||||
putExtra(IS_CUSTOMIZING_COLORS, true)
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
onTurnFlashlightOnStartupPress = {
|
||||
preferences.turnFlashlightOn = it
|
||||
},
|
||||
onForcePortraitModePress = {
|
||||
preferences.forcePortraitMode = it
|
||||
},
|
||||
onShowBrightDisplayButtonPress = {
|
||||
preferences.brightDisplay = it
|
||||
},
|
||||
onShowSosButtonPress = {
|
||||
preferences.sos = it
|
||||
},
|
||||
onShowStroboscopeButtonPress = {
|
||||
preferences.stroboscope = it
|
||||
generalSection = {
|
||||
val displayLanguage = remember { Locale.getDefault().displayLanguage }
|
||||
val turnFlashlightOnStartupFlow by preferences.turnFlashlightOnFlow.collectAsStateWithLifecycle(preferences.turnFlashlightOn)
|
||||
val forcePortraitModeFlow by preferences.forcePortraitModeFlow.collectAsStateWithLifecycle(preferences.forcePortraitMode)
|
||||
val showBrightDisplayButtonFlow by preferences.brightDisplayFlow.collectAsStateWithLifecycle(preferences.brightDisplay)
|
||||
val showSosButtonFlow by preferences.sosFlow.collectAsStateWithLifecycle(preferences.sos)
|
||||
val showStroboscopeButtonFlow by preferences.stroboscopeFlow.collectAsStateWithLifecycle(preferences.stroboscope)
|
||||
|
||||
GeneralSettingsSection(
|
||||
displayLanguage = displayLanguage,
|
||||
onSetupLanguagePress = ::launchChangeAppLanguageIntent,
|
||||
turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow,
|
||||
forcePortraitModeChecked = forcePortraitModeFlow,
|
||||
showBrightDisplayButtonChecked = showBrightDisplayButtonFlow,
|
||||
showSosButtonChecked = showSosButtonFlow,
|
||||
showStroboscopeButtonChecked = showStroboscopeButtonFlow,
|
||||
onTurnFlashlightOnStartupPress = {
|
||||
preferences.turnFlashlightOn = it
|
||||
},
|
||||
onForcePortraitModePress = {
|
||||
preferences.forcePortraitMode = it
|
||||
},
|
||||
onShowBrightDisplayButtonPress = {
|
||||
preferences.brightDisplay = it
|
||||
},
|
||||
onShowSosButtonPress = {
|
||||
preferences.sos = it
|
||||
},
|
||||
onShowStroboscopeButtonPress = {
|
||||
preferences.stroboscope = it
|
||||
},
|
||||
)
|
||||
},
|
||||
goBack = ::finish
|
||||
)
|
||||
|
@ -17,6 +17,42 @@ import com.simplemobiletools.flashlight.R
|
||||
|
||||
@Composable
|
||||
internal fun SettingsScreen(
|
||||
colorCustomizationSection: @Composable () -> Unit,
|
||||
generalSection: @Composable () -> Unit,
|
||||
goBack: () -> Unit,
|
||||
) {
|
||||
SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) {
|
||||
SettingsGroup(title = {
|
||||
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization))
|
||||
}) {
|
||||
colorCustomizationSection()
|
||||
}
|
||||
HorizontalDivider(color = divider_grey)
|
||||
SettingsGroup(title = {
|
||||
SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings))
|
||||
}) {
|
||||
generalSection()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun ColorCustomizationSettingsSection(
|
||||
customizeColors: () -> Unit,
|
||||
customizeWidgetColors: () -> Unit,
|
||||
) {
|
||||
SettingsPreferenceComponent(
|
||||
label = stringResource(id = R.string.customize_colors),
|
||||
doOnPreferenceClick = customizeColors,
|
||||
)
|
||||
SettingsPreferenceComponent(
|
||||
label = stringResource(id = R.string.customize_widget_colors),
|
||||
doOnPreferenceClick = customizeWidgetColors
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun GeneralSettingsSection(
|
||||
displayLanguage: String,
|
||||
turnFlashlightOnStartupChecked: Boolean,
|
||||
forcePortraitModeChecked: Boolean,
|
||||
@ -24,68 +60,45 @@ internal fun SettingsScreen(
|
||||
showSosButtonChecked: Boolean,
|
||||
showStroboscopeButtonChecked: Boolean,
|
||||
onSetupLanguagePress: () -> Unit,
|
||||
customizeColors: () -> Unit,
|
||||
customizeWidgetColors: () -> Unit,
|
||||
onTurnFlashlightOnStartupPress: (Boolean) -> Unit,
|
||||
onForcePortraitModePress: (Boolean) -> Unit,
|
||||
onShowBrightDisplayButtonPress: (Boolean) -> Unit,
|
||||
onShowSosButtonPress: (Boolean) -> Unit,
|
||||
onShowStroboscopeButtonPress: (Boolean) -> Unit,
|
||||
goBack: () -> Unit,
|
||||
) {
|
||||
SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) {
|
||||
SettingsGroup(title = {
|
||||
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization))
|
||||
}) {
|
||||
SettingsPreferenceComponent(
|
||||
label = stringResource(id = R.string.customize_colors),
|
||||
doOnPreferenceClick = customizeColors,
|
||||
)
|
||||
SettingsPreferenceComponent(
|
||||
label = stringResource(id = R.string.customize_widget_colors),
|
||||
doOnPreferenceClick = customizeWidgetColors
|
||||
)
|
||||
}
|
||||
HorizontalDivider(color = divider_grey)
|
||||
SettingsGroup(title = {
|
||||
SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings))
|
||||
}) {
|
||||
|
||||
if (isTiramisuPlus()) {
|
||||
SettingsPreferenceComponent(
|
||||
label = stringResource(id = R.string.language),
|
||||
value = displayLanguage,
|
||||
doOnPreferenceClick = onSetupLanguagePress,
|
||||
preferenceValueColor = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
}
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.turn_flashlight_on),
|
||||
initialValue = turnFlashlightOnStartupChecked,
|
||||
onChange = onTurnFlashlightOnStartupPress
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.force_portrait_mode),
|
||||
initialValue = forcePortraitModeChecked,
|
||||
onChange = onForcePortraitModePress
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.show_bright_display),
|
||||
initialValue = showBrightDisplayButtonChecked,
|
||||
onChange = onShowBrightDisplayButtonPress
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.show_sos),
|
||||
initialValue = showSosButtonChecked,
|
||||
onChange = onShowSosButtonPress
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.show_stroboscope),
|
||||
initialValue = showStroboscopeButtonChecked,
|
||||
onChange = onShowStroboscopeButtonPress
|
||||
)
|
||||
}
|
||||
if (isTiramisuPlus()) {
|
||||
SettingsPreferenceComponent(
|
||||
label = stringResource(id = R.string.language),
|
||||
value = displayLanguage,
|
||||
doOnPreferenceClick = onSetupLanguagePress,
|
||||
preferenceValueColor = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
}
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.turn_flashlight_on),
|
||||
initialValue = turnFlashlightOnStartupChecked,
|
||||
onChange = onTurnFlashlightOnStartupPress
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.force_portrait_mode),
|
||||
initialValue = forcePortraitModeChecked,
|
||||
onChange = onForcePortraitModePress
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.show_bright_display),
|
||||
initialValue = showBrightDisplayButtonChecked,
|
||||
onChange = onShowBrightDisplayButtonPress
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.show_sos),
|
||||
initialValue = showSosButtonChecked,
|
||||
onChange = onShowSosButtonPress
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
label = stringResource(id = R.string.show_stroboscope),
|
||||
initialValue = showStroboscopeButtonChecked,
|
||||
onChange = onShowStroboscopeButtonPress
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -93,20 +106,28 @@ internal fun SettingsScreen(
|
||||
private fun SettingsScreenPreview() {
|
||||
AppThemeSurface {
|
||||
SettingsScreen(
|
||||
displayLanguage = "English",
|
||||
turnFlashlightOnStartupChecked = false,
|
||||
forcePortraitModeChecked = true,
|
||||
showBrightDisplayButtonChecked = true,
|
||||
showSosButtonChecked = true,
|
||||
showStroboscopeButtonChecked = true,
|
||||
onSetupLanguagePress = {},
|
||||
customizeColors = {},
|
||||
customizeWidgetColors = {},
|
||||
onTurnFlashlightOnStartupPress = {},
|
||||
onForcePortraitModePress = {},
|
||||
onShowBrightDisplayButtonPress = {},
|
||||
onShowSosButtonPress = {},
|
||||
onShowStroboscopeButtonPress = {},
|
||||
colorCustomizationSection = {
|
||||
ColorCustomizationSettingsSection(
|
||||
customizeColors = {},
|
||||
customizeWidgetColors = {},
|
||||
)
|
||||
},
|
||||
generalSection = {
|
||||
GeneralSettingsSection(
|
||||
displayLanguage = "English",
|
||||
turnFlashlightOnStartupChecked = false,
|
||||
forcePortraitModeChecked = true,
|
||||
showBrightDisplayButtonChecked = true,
|
||||
showSosButtonChecked = true,
|
||||
showStroboscopeButtonChecked = true,
|
||||
onSetupLanguagePress = {},
|
||||
onTurnFlashlightOnStartupPress = {},
|
||||
onForcePortraitModePress = {},
|
||||
onShowBrightDisplayButtonPress = {},
|
||||
onShowSosButtonPress = {},
|
||||
onShowStroboscopeButtonPress = {},
|
||||
)
|
||||
},
|
||||
goBack = {},
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user