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