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,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
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -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,
|
||||||
@@ -46,11 +50,22 @@ internal fun SettingsScreen(
|
|||||||
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),
|
||||||
@@ -85,14 +100,20 @@ internal fun SettingsScreen(
|
|||||||
onChange = onShowStroboscopeButtonPress
|
onChange = onShowStroboscopeButtonPress
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@MyDevices
|
@MyDevices
|
||||||
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 = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user