diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/segment/BitwardenSegmentedButton.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/segment/BitwardenSegmentedButton.kt index 46a846e25..3dad060ba 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/segment/BitwardenSegmentedButton.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/segment/BitwardenSegmentedButton.kt @@ -29,6 +29,7 @@ fun BitwardenSegmentedButton( options: ImmutableList, modifier: Modifier = Modifier, ) { + if (options.isEmpty()) return Box( modifier = modifier .background(color = BitwardenTheme.colorScheme.background.secondary) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorScreen.kt index 9d065e45c..6166f50a9 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorScreen.kt @@ -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, diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorViewModel.kt index e3387ac40..3be394188 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorViewModel.kt @@ -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 - 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