Readability improvements for GeneratorScreen.kt (#296)

This commit is contained in:
joshua-livefront 2023-11-29 14:51:17 -05:00 committed by Álison Fernandes
parent d404b95b6d
commit 762f2f4dcc

View file

@ -3,6 +3,7 @@
package com.x8bit.bitwarden.ui.tools.feature.generator package com.x8bit.bitwarden.ui.tools.feature.generator
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
@ -275,8 +276,7 @@ private fun MainStateOptionsItem(
possibleMainStates: List<GeneratorState.MainTypeOption>, possibleMainStates: List<GeneratorState.MainTypeOption>,
onMainStateOptionClicked: (GeneratorState.MainTypeOption) -> Unit, onMainStateOptionClicked: (GeneratorState.MainTypeOption) -> Unit,
) { ) {
val optionsWithStrings = val optionsWithStrings = possibleMainStates.associateWith { stringResource(id = it.labelRes) }
possibleMainStates.associateBy({ it }, { stringResource(id = it.labelRes) })
BitwardenMultiSelectButton( BitwardenMultiSelectButton(
label = stringResource(id = R.string.what_would_you_like_to_generate), label = stringResource(id = R.string.what_would_you_like_to_generate),
@ -298,7 +298,7 @@ private fun MainStateOptionsItem(
//region PasscodeType Composables //region PasscodeType Composables
@Composable @Composable
private fun PasscodeTypeItems( private fun ColumnScope.PasscodeTypeItems(
passcodeState: GeneratorState.MainType.Passcode, passcodeState: GeneratorState.MainType.Passcode,
onSubStateOptionClicked: (GeneratorState.MainType.Passcode.PasscodeTypeOption) -> Unit, onSubStateOptionClicked: (GeneratorState.MainType.Passcode.PasscodeTypeOption) -> Unit,
passwordHandlers: PasswordHandlers, passwordHandlers: PasswordHandlers,
@ -329,8 +329,7 @@ private fun PasscodeOptionsItem(
onSubStateOptionClicked: (GeneratorState.MainType.Passcode.PasscodeTypeOption) -> Unit, onSubStateOptionClicked: (GeneratorState.MainType.Passcode.PasscodeTypeOption) -> Unit,
) { ) {
val possibleSubStates = GeneratorState.MainType.Passcode.PasscodeTypeOption.values().toList() val possibleSubStates = GeneratorState.MainType.Passcode.PasscodeTypeOption.values().toList()
val optionsWithStrings = val optionsWithStrings = possibleSubStates.associateWith { stringResource(id = it.labelRes) }
possibleSubStates.associateBy({ it }, { stringResource(id = it.labelRes) })
BitwardenMultiSelectButton( BitwardenMultiSelectButton(
label = stringResource(id = R.string.password_type), label = stringResource(id = R.string.password_type),
@ -352,7 +351,7 @@ private fun PasscodeOptionsItem(
//region PasswordType Composables //region PasswordType Composables
@Composable @Composable
private fun PasswordTypeContent( private fun ColumnScope.PasswordTypeContent(
passwordTypeState: GeneratorState.MainType.Passcode.PasscodeType.Password, passwordTypeState: GeneratorState.MainType.Passcode.PasscodeType.Password,
passwordHandlers: PasswordHandlers, passwordHandlers: PasswordHandlers,
) { ) {
@ -582,7 +581,7 @@ private fun PasswordAvoidAmbiguousCharsToggleItem(
//region PassphraseType Composables //region PassphraseType Composables
@Composable @Composable
private fun PassphraseTypeContent( private fun ColumnScope.PassphraseTypeContent(
passphraseTypeState: GeneratorState.MainType.Passcode.PasscodeType.Passphrase, passphraseTypeState: GeneratorState.MainType.Passcode.PasscodeType.Passphrase,
passphraseHandlers: PassphraseHandlers, passphraseHandlers: PassphraseHandlers,
) { ) {
@ -686,7 +685,7 @@ private fun PassphraseIncludeNumberToggleItem(
//region UsernameType Composables //region UsernameType Composables
@Composable @Composable
private fun UsernameTypeItems( private fun ColumnScope.UsernameTypeItems(
usernameState: GeneratorState.MainType.Username, usernameState: GeneratorState.MainType.Username,
onSubStateOptionClicked: (GeneratorState.MainType.Username.UsernameTypeOption) -> Unit, onSubStateOptionClicked: (GeneratorState.MainType.Username.UsernameTypeOption) -> Unit,
plusAddressedEmailHandlers: PlusAddressedEmailHandlers, plusAddressedEmailHandlers: PlusAddressedEmailHandlers,
@ -721,8 +720,7 @@ private fun UsernameOptionsItem(
onSubStateOptionClicked: (GeneratorState.MainType.Username.UsernameTypeOption) -> Unit, onSubStateOptionClicked: (GeneratorState.MainType.Username.UsernameTypeOption) -> Unit,
) { ) {
val possibleSubStates = GeneratorState.MainType.Username.UsernameTypeOption.values().toList() val possibleSubStates = GeneratorState.MainType.Username.UsernameTypeOption.values().toList()
val optionsWithStrings = val optionsWithStrings = possibleSubStates.associateWith { stringResource(id = it.labelRes) }
possibleSubStates.associateBy({ it }, { stringResource(id = it.labelRes) })
BitwardenMultiSelectButton( BitwardenMultiSelectButton(
label = stringResource(id = R.string.username_type), label = stringResource(id = R.string.username_type),
@ -744,7 +742,7 @@ private fun UsernameOptionsItem(
//region PlusAddressedEmailType Composables //region PlusAddressedEmailType Composables
@Composable @Composable
private fun PlusAddressedEmailTypeContent( private fun ColumnScope.PlusAddressedEmailTypeContent(
usernameTypeState: GeneratorState.MainType.Username.UsernameType.PlusAddressedEmail, usernameTypeState: GeneratorState.MainType.Username.UsernameType.PlusAddressedEmail,
plusAddressedEmailHandlers: PlusAddressedEmailHandlers, plusAddressedEmailHandlers: PlusAddressedEmailHandlers,
) { ) {