-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up the generator screen and handlers
- Loading branch information
1 parent
54d3b34
commit 5de6306
Showing
8 changed files
with
439 additions
and
453 deletions.
There are no files selected for viewing
532 changes: 79 additions & 453 deletions
532
app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorScreen.kt
Large diffs are not rendered by default.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
...ain/java/com/x8bit/bitwarden/ui/tools/feature/generator/handlers/CatchAllEmailHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorViewModel | ||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorAction.MainType.Username.UsernameType.CatchAllEmail as CatchAllEmailAction | ||
|
||
/** | ||
* A class dedicated to handling user interactions related to plus addressed email | ||
* configuration. | ||
* Each lambda corresponds to a specific user action, allowing for easy delegation of | ||
* logic when user input is detected. | ||
*/ | ||
data class CatchAllEmailHandlers( | ||
val onDomainChange: (String) -> Unit, | ||
) { | ||
@Suppress("UndocumentedPublicClass") | ||
companion object { | ||
/** | ||
* Creates an instance of [CatchAllEmailHandlers] by binding actions to the provided | ||
* [GeneratorViewModel]. | ||
*/ | ||
fun create( | ||
viewModel: GeneratorViewModel, | ||
): CatchAllEmailHandlers = CatchAllEmailHandlers( | ||
onDomainChange = { newDomain -> | ||
viewModel.trySendAction(CatchAllEmailAction.DomainTextChange(domain = newDomain)) | ||
}, | ||
) | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...va/com/x8bit/bitwarden/ui/tools/feature/generator/handlers/ForwardedEmailAliasHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username.UsernameType.ForwardedEmailAlias | ||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorViewModel | ||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorAction.MainType.Username.UsernameType.ForwardedEmailAlias as ForwardedEmailAliasAction | ||
|
||
/** | ||
* A class dedicated to handling user interactions related to forwarded email alias | ||
* configuration. | ||
* Each lambda corresponds to a specific user action, allowing for easy delegation of | ||
* logic when user input is detected. | ||
*/ | ||
@Suppress("LongParameterList") | ||
data class ForwardedEmailAliasHandlers( | ||
val onServiceChange: (ForwardedEmailAlias.ServiceTypeOption) -> Unit, | ||
val onAddyIoAccessTokenTextChange: (String) -> Unit, | ||
val onAddyIoDomainNameTextChange: (String) -> Unit, | ||
val onDuckDuckGoApiKeyTextChange: (String) -> Unit, | ||
val onFastMailApiKeyTextChange: (String) -> Unit, | ||
val onFirefoxRelayAccessTokenTextChange: (String) -> Unit, | ||
val onForwardEmailApiKeyTextChange: (String) -> Unit, | ||
val onForwardEmailDomainNameTextChange: (String) -> Unit, | ||
val onSimpleLoginApiKeyTextChange: (String) -> Unit, | ||
) { | ||
@Suppress("UndocumentedPublicClass") | ||
companion object { | ||
/** | ||
* Creates an instance of [ForwardedEmailAliasHandlers] by binding actions to the provided | ||
* [GeneratorViewModel]. | ||
*/ | ||
fun create( | ||
viewModel: GeneratorViewModel, | ||
): ForwardedEmailAliasHandlers = ForwardedEmailAliasHandlers( | ||
onServiceChange = { newServiceTypeOption -> | ||
viewModel.trySendAction( | ||
ForwardedEmailAliasAction.ServiceTypeOptionSelect( | ||
serviceTypeOption = newServiceTypeOption, | ||
), | ||
) | ||
}, | ||
onAddyIoAccessTokenTextChange = { newAccessToken -> | ||
viewModel.trySendAction( | ||
ForwardedEmailAliasAction.AddyIo.AccessTokenTextChange( | ||
accessToken = newAccessToken, | ||
), | ||
) | ||
}, | ||
onAddyIoDomainNameTextChange = { newDomainName -> | ||
viewModel.trySendAction( | ||
ForwardedEmailAliasAction.AddyIo.DomainTextChange(domain = newDomainName), | ||
) | ||
}, | ||
onDuckDuckGoApiKeyTextChange = { newApiKey -> | ||
viewModel.trySendAction( | ||
ForwardedEmailAliasAction.DuckDuckGo.ApiKeyTextChange(apiKey = newApiKey), | ||
) | ||
}, | ||
onFastMailApiKeyTextChange = { newApiKey -> | ||
viewModel.trySendAction( | ||
ForwardedEmailAliasAction.FastMail.ApiKeyTextChange(apiKey = newApiKey), | ||
) | ||
}, | ||
onFirefoxRelayAccessTokenTextChange = { newAccessToken -> | ||
viewModel.trySendAction( | ||
ForwardedEmailAliasAction.FirefoxRelay.AccessTokenTextChange( | ||
accessToken = newAccessToken, | ||
), | ||
) | ||
}, | ||
onForwardEmailApiKeyTextChange = { newApiKey -> | ||
viewModel.trySendAction( | ||
ForwardedEmailAliasAction.ForwardEmail.ApiKeyTextChange(apiKey = newApiKey), | ||
) | ||
}, | ||
onForwardEmailDomainNameTextChange = { newDomainName -> | ||
viewModel.trySendAction( | ||
ForwardedEmailAliasAction.ForwardEmail.DomainNameTextChange( | ||
domainName = newDomainName, | ||
), | ||
) | ||
}, | ||
onSimpleLoginApiKeyTextChange = { newApiKey -> | ||
viewModel.trySendAction( | ||
ForwardedEmailAliasAction.SimpleLogin.ApiKeyTextChange(apiKey = newApiKey), | ||
) | ||
}, | ||
) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...c/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/handlers/PassphraseHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorAction | ||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorViewModel | ||
|
||
/** | ||
* A class dedicated to handling user interactions related to passphrase configuration. | ||
* Each lambda corresponds to a specific user action, allowing for easy delegation of | ||
* logic when user input is detected. | ||
*/ | ||
data class PassphraseHandlers( | ||
val onPassphraseNumWordsCounterChange: (Int) -> Unit, | ||
val onPassphraseWordSeparatorChange: (Char?) -> Unit, | ||
val onPassphraseCapitalizeToggleChange: (Boolean) -> Unit, | ||
val onPassphraseIncludeNumberToggleChange: (Boolean) -> Unit, | ||
) { | ||
@Suppress("UndocumentedPublicClass") | ||
companion object { | ||
/** | ||
* Creates an instance of [PassphraseHandlers] by binding actions to the provided | ||
* [GeneratorViewModel]. | ||
*/ | ||
fun create( | ||
viewModel: GeneratorViewModel, | ||
): PassphraseHandlers = PassphraseHandlers( | ||
onPassphraseNumWordsCounterChange = { changeInCounter -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Passphrase.NumWordsCounterChange( | ||
numWords = changeInCounter, | ||
), | ||
) | ||
}, | ||
onPassphraseWordSeparatorChange = { newSeparator -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Passphrase.WordSeparatorTextChange( | ||
wordSeparator = newSeparator, | ||
), | ||
) | ||
}, | ||
onPassphraseCapitalizeToggleChange = { shouldCapitalize -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Passphrase.ToggleCapitalizeChange( | ||
capitalize = shouldCapitalize, | ||
), | ||
) | ||
}, | ||
onPassphraseIncludeNumberToggleChange = { shouldIncludeNumber -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Passphrase.ToggleIncludeNumberChange( | ||
includeNumber = shouldIncludeNumber, | ||
), | ||
) | ||
}, | ||
) | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/handlers/PasswordHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorAction | ||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorViewModel | ||
|
||
/** | ||
* A class dedicated to handling user interactions related to password configuration. | ||
* Each lambda corresponds to a specific user action, allowing for easy delegation of | ||
* logic when user input is detected. | ||
*/ | ||
@Suppress("LongParameterList") | ||
data class PasswordHandlers( | ||
val onPasswordSliderLengthChange: (Int, Boolean) -> Unit, | ||
val onPasswordToggleCapitalLettersChange: (Boolean) -> Unit, | ||
val onPasswordToggleLowercaseLettersChange: (Boolean) -> Unit, | ||
val onPasswordToggleNumbersChange: (Boolean) -> Unit, | ||
val onPasswordToggleSpecialCharactersChange: (Boolean) -> Unit, | ||
val onPasswordMinNumbersCounterChange: (Int) -> Unit, | ||
val onPasswordMinSpecialCharactersChange: (Int) -> Unit, | ||
val onPasswordToggleAvoidAmbiguousCharsChange: (Boolean) -> Unit, | ||
) { | ||
@Suppress("UndocumentedPublicClass") | ||
companion object { | ||
/** | ||
* Creates an instance of [PasswordHandlers] by binding actions to the provided | ||
* [GeneratorViewModel]. | ||
*/ | ||
fun create( | ||
viewModel: GeneratorViewModel, | ||
): PasswordHandlers = PasswordHandlers( | ||
onPasswordSliderLengthChange = { newLength, isUserInteracting -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Password.SliderLengthChange( | ||
length = newLength, | ||
isUserInteracting = isUserInteracting, | ||
), | ||
) | ||
}, | ||
onPasswordToggleCapitalLettersChange = { shouldUseCapitals -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Password.ToggleCapitalLettersChange( | ||
useCapitals = shouldUseCapitals, | ||
), | ||
) | ||
}, | ||
onPasswordToggleLowercaseLettersChange = { shouldUseLowercase -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Password.ToggleLowercaseLettersChange( | ||
useLowercase = shouldUseLowercase, | ||
), | ||
) | ||
}, | ||
onPasswordToggleNumbersChange = { shouldUseNumbers -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Password.ToggleNumbersChange( | ||
useNumbers = shouldUseNumbers, | ||
), | ||
) | ||
}, | ||
onPasswordToggleSpecialCharactersChange = { shouldUseSpecialChars -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Password.ToggleSpecialCharactersChange( | ||
useSpecialChars = shouldUseSpecialChars, | ||
), | ||
) | ||
}, | ||
onPasswordMinNumbersCounterChange = { newMinNumbers -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Password.MinNumbersCounterChange( | ||
minNumbers = newMinNumbers, | ||
), | ||
) | ||
}, | ||
onPasswordMinSpecialCharactersChange = { newMinSpecial -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Password.MinSpecialCharactersChange( | ||
minSpecial = newMinSpecial, | ||
), | ||
) | ||
}, | ||
onPasswordToggleAvoidAmbiguousCharsChange = { shouldAvoidAmbiguousChars -> | ||
viewModel.trySendAction( | ||
GeneratorAction.MainType.Password.ToggleAvoidAmbigousCharactersChange( | ||
avoidAmbiguousChars = shouldAvoidAmbiguousChars, | ||
), | ||
) | ||
}, | ||
) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ava/com/x8bit/bitwarden/ui/tools/feature/generator/handlers/PlusAddressedEmailHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorViewModel | ||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorAction.MainType.Username.UsernameType.PlusAddressedEmail as PlusAddressedEmailAction | ||
|
||
/** | ||
* A class dedicated to handling user interactions related to plus addressed email | ||
* configuration. | ||
* Each lambda corresponds to a specific user action, allowing for easy delegation of | ||
* logic when user input is detected. | ||
*/ | ||
data class PlusAddressedEmailHandlers( | ||
val onEmailChange: (String) -> Unit, | ||
) { | ||
@Suppress("UndocumentedPublicClass") | ||
companion object { | ||
/** | ||
* Creates an instance of [PlusAddressedEmailHandlers] by binding actions to the provided | ||
* [GeneratorViewModel]. | ||
*/ | ||
fun create(viewModel: GeneratorViewModel): PlusAddressedEmailHandlers = | ||
PlusAddressedEmailHandlers( | ||
onEmailChange = { newEmail -> | ||
viewModel.trySendAction( | ||
PlusAddressedEmailAction.EmailTextChange(email = newEmail), | ||
) | ||
}, | ||
) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...c/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/handlers/RandomWordHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorViewModel | ||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorAction.MainType.Username.UsernameType.RandomWord as RandomWordAction | ||
|
||
/** | ||
* A class dedicated to handling user interactions related to Random Word | ||
* configuration. | ||
* Each lambda corresponds to a specific user action, allowing for easy delegation of | ||
* logic when user input is detected. | ||
*/ | ||
data class RandomWordHandlers( | ||
val onCapitalizeChange: (Boolean) -> Unit, | ||
val onIncludeNumberChange: (Boolean) -> Unit, | ||
) { | ||
@Suppress("UndocumentedPublicClass") | ||
companion object { | ||
/** | ||
* Creates an instance of [RandomWordHandlers] by binding actions to the provided | ||
* [GeneratorViewModel]. | ||
*/ | ||
fun create( | ||
viewModel: GeneratorViewModel, | ||
): RandomWordHandlers = RandomWordHandlers( | ||
onCapitalizeChange = { shouldCapitalize -> | ||
viewModel.trySendAction( | ||
RandomWordAction.ToggleCapitalizeChange(capitalize = shouldCapitalize), | ||
) | ||
}, | ||
onIncludeNumberChange = { shouldIncludeNumber -> | ||
viewModel.trySendAction( | ||
RandomWordAction.ToggleIncludeNumberChange(includeNumber = shouldIncludeNumber), | ||
) | ||
}, | ||
) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...main/java/com/x8bit/bitwarden/ui/tools/feature/generator/handlers/UsernameTypeHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorAction | ||
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorViewModel | ||
|
||
/** | ||
* A class dedicated to handling user interactions related to all username configurations. | ||
* Each lambda corresponds to a specific user action, allowing for easy delegation of | ||
* logic when user input is detected. | ||
*/ | ||
@Suppress("LongParameterList") | ||
data class UsernameTypeHandlers( | ||
val onUsernameTooltipClicked: () -> Unit, | ||
) { | ||
@Suppress("UndocumentedPublicClass") | ||
companion object { | ||
/** | ||
* Creates an instance of [UsernameTypeHandlers] by binding actions to the provided | ||
* [GeneratorViewModel]. | ||
*/ | ||
fun create( | ||
viewModel: GeneratorViewModel, | ||
): UsernameTypeHandlers = UsernameTypeHandlers( | ||
onUsernameTooltipClicked = { | ||
viewModel.trySendAction(GeneratorAction.MainType.Username.UsernameType.TooltipClick) | ||
}, | ||
) | ||
} | ||
} |