Split SettingsScreen into sections

This commit is contained in:
Ensar Sarajčić
2023-10-03 13:27:41 +02:00
parent 2f6000db6a
commit 9e3b207509
2 changed files with 134 additions and 103 deletions

View File

@@ -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,6 +26,19 @@ class SettingsActivity : ComponentActivity() {
enableEdgeToEdgeSimple() enableEdgeToEdgeSimple()
setContent { setContent {
AppThemeSurface { AppThemeSurface {
SettingsScreen(
colorCustomizationSection = {
ColorCustomizationSettingsSection(
customizeColors = ::startCustomizationActivity,
customizeWidgetColors = {
Intent(this, WidgetTorchConfigureActivity::class.java).apply {
putExtra(IS_CUSTOMIZING_COLORS, true)
startActivity(this)
}
}
)
},
generalSection = {
val displayLanguage = remember { Locale.getDefault().displayLanguage } val displayLanguage = remember { Locale.getDefault().displayLanguage }
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)
@@ -31,21 +46,14 @@ class SettingsActivity : ComponentActivity() {
val showSosButtonFlow by preferences.sosFlow.collectAsStateWithLifecycle(preferences.sos) val showSosButtonFlow by preferences.sosFlow.collectAsStateWithLifecycle(preferences.sos)
val showStroboscopeButtonFlow by preferences.stroboscopeFlow.collectAsStateWithLifecycle(preferences.stroboscope) val showStroboscopeButtonFlow by preferences.stroboscopeFlow.collectAsStateWithLifecycle(preferences.stroboscope)
SettingsScreen( GeneralSettingsSection(
displayLanguage = displayLanguage, displayLanguage = displayLanguage,
onSetupLanguagePress = ::launchChangeAppLanguageIntent, onSetupLanguagePress = ::launchChangeAppLanguageIntent,
customizeColors = ::startCustomizationActivity,
turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow, turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow,
forcePortraitModeChecked = forcePortraitModeFlow, forcePortraitModeChecked = forcePortraitModeFlow,
showBrightDisplayButtonChecked = showBrightDisplayButtonFlow, showBrightDisplayButtonChecked = showBrightDisplayButtonFlow,
showSosButtonChecked = showSosButtonFlow, showSosButtonChecked = showSosButtonFlow,
showStroboscopeButtonChecked = showStroboscopeButtonFlow, showStroboscopeButtonChecked = showStroboscopeButtonFlow,
customizeWidgetColors = {
Intent(this, WidgetTorchConfigureActivity::class.java).apply {
putExtra(IS_CUSTOMIZING_COLORS, true)
startActivity(this)
}
},
onTurnFlashlightOnStartupPress = { onTurnFlashlightOnStartupPress = {
preferences.turnFlashlightOn = it preferences.turnFlashlightOn = it
}, },
@@ -61,6 +69,8 @@ class SettingsActivity : ComponentActivity() {
onShowStroboscopeButtonPress = { onShowStroboscopeButtonPress = {
preferences.stroboscope = it preferences.stroboscope = it
}, },
)
},
goBack = ::finish goBack = ::finish
) )
} }

View File

@@ -17,26 +17,30 @@ import com.simplemobiletools.flashlight.R
@Composable @Composable
internal fun SettingsScreen( internal fun SettingsScreen(
displayLanguage: String, colorCustomizationSection: @Composable () -> Unit,
turnFlashlightOnStartupChecked: Boolean, generalSection: @Composable () -> Unit,
forcePortraitModeChecked: Boolean,
showBrightDisplayButtonChecked: Boolean,
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, goBack: () -> Unit,
) { ) {
SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) { SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) {
SettingsGroup(title = { SettingsGroup(title = {
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization)) 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( SettingsPreferenceComponent(
label = stringResource(id = R.string.customize_colors), label = stringResource(id = R.string.customize_colors),
doOnPreferenceClick = customizeColors, doOnPreferenceClick = customizeColors,
@@ -45,12 +49,23 @@ internal fun SettingsScreen(
label = stringResource(id = R.string.customize_widget_colors), label = stringResource(id = R.string.customize_widget_colors),
doOnPreferenceClick = customizeWidgetColors doOnPreferenceClick = customizeWidgetColors
) )
} }
HorizontalDivider(color = divider_grey)
SettingsGroup(title = {
SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings))
}) {
@Composable
internal fun GeneralSettingsSection(
displayLanguage: String,
turnFlashlightOnStartupChecked: Boolean,
forcePortraitModeChecked: Boolean,
showBrightDisplayButtonChecked: Boolean,
showSosButtonChecked: Boolean,
showStroboscopeButtonChecked: Boolean,
onSetupLanguagePress: () -> Unit,
onTurnFlashlightOnStartupPress: (Boolean) -> Unit,
onForcePortraitModePress: (Boolean) -> Unit,
onShowBrightDisplayButtonPress: (Boolean) -> Unit,
onShowSosButtonPress: (Boolean) -> Unit,
onShowStroboscopeButtonPress: (Boolean) -> Unit,
) {
if (isTiramisuPlus()) { if (isTiramisuPlus()) {
SettingsPreferenceComponent( SettingsPreferenceComponent(
label = stringResource(id = R.string.language), label = stringResource(id = R.string.language),
@@ -84,8 +99,6 @@ internal fun SettingsScreen(
initialValue = showStroboscopeButtonChecked, initialValue = showStroboscopeButtonChecked,
onChange = onShowStroboscopeButtonPress onChange = onShowStroboscopeButtonPress
) )
}
}
} }
@Composable @Composable
@@ -93,6 +106,14 @@ internal fun SettingsScreen(
private fun SettingsScreenPreview() { private fun SettingsScreenPreview() {
AppThemeSurface { AppThemeSurface {
SettingsScreen( SettingsScreen(
colorCustomizationSection = {
ColorCustomizationSettingsSection(
customizeColors = {},
customizeWidgetColors = {},
)
},
generalSection = {
GeneralSettingsSection(
displayLanguage = "English", displayLanguage = "English",
turnFlashlightOnStartupChecked = false, turnFlashlightOnStartupChecked = false,
forcePortraitModeChecked = true, forcePortraitModeChecked = true,
@@ -100,13 +121,13 @@ private fun SettingsScreenPreview() {
showSosButtonChecked = true, showSosButtonChecked = true,
showStroboscopeButtonChecked = true, showStroboscopeButtonChecked = true,
onSetupLanguagePress = {}, onSetupLanguagePress = {},
customizeColors = {},
customizeWidgetColors = {},
onTurnFlashlightOnStartupPress = {}, onTurnFlashlightOnStartupPress = {},
onForcePortraitModePress = {}, onForcePortraitModePress = {},
onShowBrightDisplayButtonPress = {}, onShowBrightDisplayButtonPress = {},
onShowSosButtonPress = {}, onShowSosButtonPress = {},
onShowStroboscopeButtonPress = {}, onShowStroboscopeButtonPress = {},
)
},
goBack = {}, goBack = {},
) )
} }