BIT-714: Adding ui for duck duck go service type (#445)

This commit is contained in:
joshua-livefront
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent d615fec9c6
commit f528376c66
4 changed files with 184 additions and 1 deletions
@@ -838,7 +838,14 @@ private fun ColumnScope.ForwardedEmailAliasTypeContent(
}
is ServiceType.DuckDuckGo -> {
// TODO: DuckDuckGo Service Implementation (BIT-714)
BitwardenPasswordField(
label = stringResource(id = R.string.api_key_required_parenthesis),
value = usernameTypeState.selectedServiceType.apiKey,
onValueChange = forwardedEmailAliasHandlers.onDuckDuckGoApiKeyTextChange,
modifier = Modifier
.padding(horizontal = 16.dp)
.fillMaxWidth(),
)
}
is ServiceType.FastMail -> {
@@ -1171,6 +1178,7 @@ private class PassphraseHandlers(
*/
private class ForwardedEmailAliasHandlers(
val onServiceChange: (ServiceTypeOption) -> Unit,
val onDuckDuckGoApiKeyTextChange: (String) -> Unit,
) {
companion object {
fun create(viewModel: GeneratorViewModel): ForwardedEmailAliasHandlers {
@@ -1187,6 +1195,19 @@ private class ForwardedEmailAliasHandlers(
),
)
},
onDuckDuckGoApiKeyTextChange = { newApiKey ->
viewModel.trySendAction(
GeneratorAction
.MainType
.Username
.UsernameType
.ForwardedEmailAlias
.DuckDuckGo
.ApiKeyTextChange(
apiKey = newApiKey,
),
)
},
)
}
}
@@ -22,6 +22,7 @@ import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Pa
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username.UsernameType.CatchAllEmail
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username.UsernameType.ForwardedEmailAlias
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username.UsernameType.ForwardedEmailAlias.ServiceType.DuckDuckGo
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username.UsernameType.ForwardedEmailAlias.ServiceType
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username.UsernameType.PlusAddressedEmail
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username.UsernameType.RandomWord
@@ -113,6 +114,10 @@ class GeneratorViewModel @Inject constructor(
handleServiceTypeOptionSelect(action)
}
is GeneratorAction.MainType.Username.UsernameType.ForwardedEmailAlias.DuckDuckGo.ApiKeyTextChange -> {
handleDuckDuckGoTextInputChange(action)
}
is GeneratorAction.MainType.Username.UsernameType.PlusAddressedEmail.EmailTextChange -> {
handlePlusAddressedEmailTextInputChange(action)
}
@@ -594,6 +599,21 @@ class GeneratorViewModel @Inject constructor(
//endregion Forwarded Email Alias Specific Handlers
private fun handleDuckDuckGoTextInputChange(
action: GeneratorAction
.MainType
.Username
.UsernameType
.ForwardedEmailAlias
.DuckDuckGo
.ApiKeyTextChange,
) {
updateDuckDuckGoServiceType { duckDuckGoServiceType ->
val newApiKey = action.apiKey
duckDuckGoServiceType.copy(apiKey = newApiKey)
}
}
//region Plus Addressed Email Specific Handlers
private fun handlePlusAddressedEmailTextInputChange(
@@ -752,6 +772,30 @@ class GeneratorViewModel @Inject constructor(
}
}
private inline fun updateDuckDuckGoServiceType(
crossinline block: (DuckDuckGo) -> DuckDuckGo,
) {
updateGeneratorMainTypeUsername { currentUsernameType ->
if (currentUsernameType.selectedType !is ForwardedEmailAlias) {
return@updateGeneratorMainTypeUsername currentUsernameType
}
val currentServiceType = (currentUsernameType.selectedType).selectedServiceType
if (currentServiceType !is DuckDuckGo) {
return@updateGeneratorMainTypeUsername currentUsernameType
}
val updatedServiceType = block(currentServiceType)
currentUsernameType.copy(
selectedType = ForwardedEmailAlias(
selectedServiceType = updatedServiceType,
obfuscatedText = currentUsernameType.selectedType.obfuscatedText,
),
)
}
}
private inline fun updatePlusAddressedEmailType(
crossinline block: (PlusAddressedEmail) -> PlusAddressedEmail,
) {
@@ -1401,6 +1445,19 @@ sealed class GeneratorAction {
.ForwardedEmailAlias
.ServiceTypeOption,
) : ForwardedEmailAlias()
/**
* Represents actions specifically related to the DuckDuckGo service.
*/
sealed class DuckDuckGo : ForwardedEmailAlias() {
/**
* Fired when the api key input text is changed.
*
* @property apiKey The new api key text.
*/
data class ApiKeyTextChange(val apiKey: String) : DuckDuckGo()
}
}
/**