Skip to content

Commit

Permalink
refactoring SettingsScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
babichev.a committed Oct 25, 2024
1 parent 3629660 commit 508d05b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ androidxArch = "2.2.0"
androidxTestExt = "1.2.1"
androidxTest = "1.6.2"
androidxTestOrchestrator = "1.5.1"
firebase = "33.5.0"
firebase = "33.5.1"
leakCanary = "2.14"
junit = "4.13.2"
mockito = "5.14.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,21 @@ fun SettingsScreen(settingsViewModel: SettingsViewModel) {
onPauseOrDispose { result.checkEncryption() }
}
SettingsScreenBody(
onBackClick = result.navBack,
showLoading = result.loading,
changeTheme = result.changeTheme,
encryption = result.encryption,
changeEncryption = result.changeEncryption,
changePassword = result.changePassword,
showCipherVersion = result.showCipherVersion,
result = result,
snackbarHostState = snackbarHostState,
)
}

@Composable
fun SettingsScreenBody(
onBackClick: () -> Unit = {},
showLoading: Boolean = true,
changeTheme: () -> Unit = {},
encryption: Boolean = false,
changeEncryption: (Boolean) -> Unit = {},
changePassword: () -> Unit = {},
showCipherVersion: () -> Unit = {},
result: SecurityResult = SecurityResult(),
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() },
) = Scaffold(
topBar = {
TopAppBar(
title = { Text(stringResource(Res.string.settings)) },
navigationIcon = {
IconButton(onClick = onBackClick) {
IconButton(onClick = result.navBack) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = Icons.AutoMirrored.Filled.ArrowBack.name
Expand All @@ -110,31 +98,31 @@ fun SettingsScreenBody(
content = { paddingValues: PaddingValues ->
val enableEncryptionPrefTitle = stringResource(Res.string.pref_title_enable_encryption)
Column(modifier = Modifier.padding(paddingValues)) {
if (showLoading) LinearProgressIndicator(Modifier.fillMaxWidth())
if (result.loading) LinearProgressIndicator(Modifier.fillMaxWidth())
PreferenceCategory(stringResource(Res.string.theme), Icons.Default.Brightness4)
ThemePreferenceItem(onClick = changeTheme)
ThemePreferenceItem(onClick = result.changeTheme)
PreferenceCategory(stringResource(Res.string.security), Icons.Default.Security)
Preference(
modifier = Modifier.semantics {
contentDescription = enableEncryptionPrefTitle
toggleableState = ToggleableState(encryption)
toggleableState = ToggleableState(result.encryption)
testTag = enableEncryptionPrefTitle
},
title = enableEncryptionPrefTitle,
vector = Icons.Default.Lock,
onClick = { changeEncryption(!encryption) }
onClick = { result.changeEncryption(!result.encryption) }
) {
Switch(checked = encryption, onCheckedChange = changeEncryption)
Switch(checked = result.encryption, onCheckedChange = result.changeEncryption)
}
Preference(
title = stringResource(Res.string.pref_title_set_password),
vector = Icons.Default.Password,
onClick = changePassword
onClick = result.changePassword
)
Preference(
title = stringResource(Res.string.pref_title_check_cipher_version),
vector = Icons.Filled.FileLock,
onClick = showCipherVersion
onClick = result.showCipherVersion
)
Spacer(Modifier.height(32.dp))
ListItem(
Expand Down

0 comments on commit 508d05b

Please sign in to comment.