-
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
dae50a7
commit c1b1875
Showing
8 changed files
with
535 additions
and
484 deletions.
There are no files selected for viewing
580 changes: 96 additions & 484 deletions
580
app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorScreen.kt
Large diffs are not rendered by default.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
...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,40 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
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)) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to remember a [CatchAllEmailHandlers] instance in a [Composable] scope. | ||
*/ | ||
@Composable | ||
fun rememberCatchAllEmailHandlers(viewModel: GeneratorViewModel): CatchAllEmailHandlers = | ||
remember(viewModel) { | ||
CatchAllEmailHandlers.create(viewModel = viewModel) | ||
} |
102 changes: 102 additions & 0 deletions
102
...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,102 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
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), | ||
) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to remember a [ForwardedEmailAliasHandlers] instance in a [Composable] scope. | ||
*/ | ||
@Composable | ||
fun rememberForwardedEmailAliasHandlers( | ||
viewModel: GeneratorViewModel, | ||
): ForwardedEmailAliasHandlers = | ||
remember(viewModel) { | ||
ForwardedEmailAliasHandlers.create(viewModel = viewModel) | ||
} |
67 changes: 67 additions & 0 deletions
67
...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,67 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
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, | ||
), | ||
) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to remember a [PassphraseHandlers] instance in a [Composable] scope. | ||
*/ | ||
@Composable | ||
fun rememberPassphraseHandlers(viewModel: GeneratorViewModel): PassphraseHandlers = | ||
remember(viewModel) { | ||
PassphraseHandlers.create(viewModel = viewModel) | ||
} |
101 changes: 101 additions & 0 deletions
101
...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,101 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
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, | ||
), | ||
) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to remember a [PasswordHandlers] instance in a [Composable] scope. | ||
*/ | ||
@Composable | ||
fun rememberPasswordHandlers(viewModel: GeneratorViewModel): PasswordHandlers = | ||
remember(viewModel) { | ||
PasswordHandlers.create(viewModel = viewModel) | ||
} |
41 changes: 41 additions & 0 deletions
41
...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,41 @@ | ||
package com.x8bit.bitwarden.ui.tools.feature.generator.handlers | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
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), | ||
) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to remember a [PlusAddressedEmailHandlers] instance in a [Composable] scope. | ||
*/ | ||
@Composable | ||
fun rememberPlusAddressedEmailHandlers(viewModel: GeneratorViewModel): PlusAddressedEmailHandlers = | ||
remember(viewModel) { | ||
PlusAddressedEmailHandlers.create(viewModel = viewModel) | ||
} |
Oops, something went wrong.