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.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,6 +26,19 @@ class SettingsActivity : ComponentActivity() {
enableEdgeToEdgeSimple()
setContent {
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 turnFlashlightOnStartupFlow by preferences.turnFlashlightOnFlow.collectAsStateWithLifecycle(preferences.turnFlashlightOn)
val forcePortraitModeFlow by preferences.forcePortraitModeFlow.collectAsStateWithLifecycle(preferences.forcePortraitMode)
@@ -31,21 +46,14 @@ class SettingsActivity : ComponentActivity() {
val showSosButtonFlow by preferences.sosFlow.collectAsStateWithLifecycle(preferences.sos)
val showStroboscopeButtonFlow by preferences.stroboscopeFlow.collectAsStateWithLifecycle(preferences.stroboscope)
SettingsScreen(
GeneralSettingsSection(
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)
}
},
onTurnFlashlightOnStartupPress = {
preferences.turnFlashlightOn = it
},
@@ -61,6 +69,8 @@ class SettingsActivity : ComponentActivity() {
onShowStroboscopeButtonPress = {
preferences.stroboscope = it
},
)
},
goBack = ::finish
)
}

View File

@@ -17,26 +17,30 @@ import com.simplemobiletools.flashlight.R
@Composable
internal fun SettingsScreen(
displayLanguage: String,
turnFlashlightOnStartupChecked: Boolean,
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,
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,
@@ -46,11 +50,22 @@ internal fun SettingsScreen(
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()) {
SettingsPreferenceComponent(
label = stringResource(id = R.string.language),
@@ -85,14 +100,20 @@ internal fun SettingsScreen(
onChange = onShowStroboscopeButtonPress
)
}
}
}
@Composable
@MyDevices
private fun SettingsScreenPreview() {
AppThemeSurface {
SettingsScreen(
colorCustomizationSection = {
ColorCustomizationSettingsSection(
customizeColors = {},
customizeWidgetColors = {},
)
},
generalSection = {
GeneralSettingsSection(
displayLanguage = "English",
turnFlashlightOnStartupChecked = false,
forcePortraitModeChecked = true,
@@ -100,13 +121,13 @@ private fun SettingsScreenPreview() {
showSosButtonChecked = true,
showStroboscopeButtonChecked = true,
onSetupLanguagePress = {},
customizeColors = {},
customizeWidgetColors = {},
onTurnFlashlightOnStartupPress = {},
onForcePortraitModePress = {},
onShowBrightDisplayButtonPress = {},
onShowSosButtonPress = {},
onShowStroboscopeButtonPress = {},
)
},
goBack = {},
)
}