From 5a6be93644dc121fb9f1af3c9bc836a8f1dbba10 Mon Sep 17 00:00:00 2001 From: David Perez Date: Thu, 8 Feb 2024 15:02:37 -0600 Subject: [PATCH] Add helper handle methods for MainType and Internal actions (#989) --- .../feature/generator/GeneratorViewModel.kt | 91 +++++++++---------- 1 file changed, 42 insertions(+), 49 deletions(-) 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 f6224018d..b0b6f13ed 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 @@ -105,33 +105,22 @@ class GeneratorViewModel @Inject constructor( } } - @Suppress("MaxLineLength", "LongMethod") override fun handleAction(action: GeneratorAction) { when (action) { - is GeneratorAction.PasswordHistoryClick -> { - handlePasswordHistoryClick() - } - - is GeneratorAction.CloseClick -> { - handleCloseClick() - } - - is GeneratorAction.SelectClick -> { - handleSelectClick() - } - - is GeneratorAction.RegenerateClick -> { - handleRegenerationClick() - } - - is GeneratorAction.CopyClick -> { - handleCopyClick() - } - - is GeneratorAction.MainTypeOptionSelect -> { - handleMainTypeOptionSelect(action) - } + is GeneratorAction.PasswordHistoryClick -> handlePasswordHistoryClick() + is GeneratorAction.CloseClick -> handleCloseClick() + is GeneratorAction.SelectClick -> handleSelectClick() + is GeneratorAction.RegenerateClick -> handleRegenerationClick() + is GeneratorAction.CopyClick -> handleCopyClick() + is GeneratorAction.MainTypeOptionSelect -> handleMainTypeOptionSelect(action) + is GeneratorAction.MainType -> handleMainTypeAction(action) + is GeneratorAction.Internal -> handleInternalAction(action) + } + } + @Suppress("MaxLineLength") + private fun handleMainTypeAction(action: GeneratorAction.MainType) { + when (action) { is GeneratorAction.MainType.Passcode.PasscodeTypeOptionSelect -> { handlePasscodeTypeOptionSelect(action) } @@ -144,30 +133,6 @@ class GeneratorViewModel @Inject constructor( handlePassphraseSpecificAction(action) } - is GeneratorAction.Internal.UpdateGeneratedPasswordResult -> { - handleUpdateGeneratedPasswordResult(action) - } - - is GeneratorAction.Internal.UpdateGeneratedPassphraseResult -> { - handleUpdateGeneratedPassphraseResult(action) - } - - is GeneratorAction.Internal.UpdateGeneratedPlusAddessedUsernameResult -> { - handleUpdatePlusAddressedGeneratedUsernameResult(action) - } - - is GeneratorAction.Internal.UpdateGeneratedCatchAllUsernameResult -> { - handleUpdateCatchAllGeneratedUsernameResult(action) - } - - is GeneratorAction.Internal.UpdateGeneratedRandomWordUsernameResult -> { - handleUpdateRandomWordGeneratedUsernameResult(action) - } - - is GeneratorAction.Internal.UpdateGeneratedForwardedServiceUsernameResult -> { - handleUpdateForwardedServiceGeneratedUsernameResult(action) - } - is GeneratorAction.MainType.Username.UsernameTypeOptionSelect -> { handleUsernameTypeOptionSelect(action) } @@ -214,6 +179,34 @@ class GeneratorViewModel @Inject constructor( } } + private fun handleInternalAction(action: GeneratorAction.Internal) { + when (action) { + is GeneratorAction.Internal.UpdateGeneratedPasswordResult -> { + handleUpdateGeneratedPasswordResult(action) + } + + is GeneratorAction.Internal.UpdateGeneratedPassphraseResult -> { + handleUpdateGeneratedPassphraseResult(action) + } + + is GeneratorAction.Internal.UpdateGeneratedPlusAddessedUsernameResult -> { + handleUpdatePlusAddressedGeneratedUsernameResult(action) + } + + is GeneratorAction.Internal.UpdateGeneratedCatchAllUsernameResult -> { + handleUpdateCatchAllGeneratedUsernameResult(action) + } + + is GeneratorAction.Internal.UpdateGeneratedRandomWordUsernameResult -> { + handleUpdateRandomWordGeneratedUsernameResult(action) + } + + is GeneratorAction.Internal.UpdateGeneratedForwardedServiceUsernameResult -> { + handleUpdateForwardedServiceGeneratedUsernameResult(action) + } + } + } + //endregion Initialization and Overrides //region Top Level Handlers @@ -2111,7 +2104,7 @@ sealed class GeneratorAction { /** * Represents the action to learn more. */ - data object TooltipClick : GeneratorAction() + data object TooltipClick : UsernameType() /** * Represents actions specifically related to Forwarded Email Alias.