PM-14644: Segmented control should be conditionally displayed for modal generator screen (#4262)

This commit is contained in:
David Perez 2024-11-08 11:03:54 -06:00 committed by GitHub
parent b76f7202a4
commit 27666c193e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 12 deletions

View file

@ -29,6 +29,7 @@ fun BitwardenSegmentedButton(
options: ImmutableList<SegmentedButtonState>,
modifier: Modifier = Modifier,
) {
if (options.isEmpty()) return
Box(
modifier = modifier
.background(color = BitwardenTheme.colorScheme.background.secondary)

View file

@ -202,16 +202,14 @@ fun GeneratorScreen(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
) { innerPadding ->
Column(modifier = Modifier.padding(innerPadding)) {
if (state.generatorMode == GeneratorMode.Default) {
MainStateOptionsItem(
selectedType = state.selectedType,
passcodePolicyOverride = state.passcodePolicyOverride,
possibleMainStates = state.typeOptions.toImmutableList(),
onMainStateOptionClicked = onMainStateOptionClicked,
modifier = Modifier
.scrolledContainerBottomDivider(topAppBarScrollBehavior = scrollBehavior),
)
}
MainStateOptionsItem(
selectedType = state.selectedType,
passcodePolicyOverride = state.passcodePolicyOverride,
possibleMainStates = state.typeOptions.toImmutableList(),
onMainStateOptionClicked = onMainStateOptionClicked,
modifier = Modifier
.scrolledContainerBottomDivider(topAppBarScrollBehavior = scrollBehavior),
)
ScrollContent(
state = state,
onRegenerateClick = onRegenerateClick,

View file

@ -53,6 +53,7 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import javax.inject.Inject
import kotlin.collections.filter
import kotlin.math.max
private const val KEY_STATE = "state"
@ -1726,10 +1727,17 @@ data class GeneratorState(
) : Parcelable {
/**
* Provides a list of available main types for the generator.
* Provides a list of available main types for the generator based on the [GeneratorMode].
*/
val typeOptions: List<MainTypeOption>
get() = MainTypeOption.entries.toList()
get() = when (generatorMode) {
GeneratorMode.Default -> MainTypeOption.entries.toList()
GeneratorMode.Modal.Password -> MainTypeOption
.entries
.filter { it != MainTypeOption.USERNAME }
is GeneratorMode.Modal.Username -> emptyList()
}
/**
* Enum representing the main type options for the generator, such as PASSWORD PASSPHRASE, and