From 72904b484b3623c5286a6a77dcbcd7a719922c23 Mon Sep 17 00:00:00 2001 From: Artem Chepurnoy Date: Fri, 29 Nov 2024 15:18:40 +0200 Subject: [PATCH] improvement: Show a tip that you can generate disposable emails #724 --- .../composeResources/values/strings.xml | 3 ++ .../generator/GeneratorStateProducer.kt | 34 +++++++++++++++++- .../com/artemchep/keyguard/ui/SimpleNote.kt | 36 +++++++++++-------- 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/common/src/commonMain/composeResources/values/strings.xml b/common/src/commonMain/composeResources/values/strings.xml index d45fc21d..3932c216 100644 --- a/common/src/commonMain/composeResources/values/strings.xml +++ b/common/src/commonMain/composeResources/values/strings.xml @@ -230,6 +230,9 @@ Requires Bitwarden premium Unofficial Bitwarden server + Pro tip: %1$s + Generate disposable emails for the better privacy. + Last synced at %1$s Change name Change color diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/generator/GeneratorStateProducer.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/generator/GeneratorStateProducer.kt index ea0a3fda..e78d44d3 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/generator/GeneratorStateProducer.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/generator/GeneratorStateProducer.kt @@ -92,6 +92,8 @@ import com.artemchep.keyguard.res.Res import com.artemchep.keyguard.res.* import com.artemchep.keyguard.ui.ContextItem import com.artemchep.keyguard.ui.FlatItemAction +import com.artemchep.keyguard.ui.FlatSimpleNote +import com.artemchep.keyguard.ui.SimpleNote import com.artemchep.keyguard.ui.buildContextItems import com.artemchep.keyguard.ui.icons.KeyguardIcons import com.artemchep.keyguard.ui.icons.icon @@ -1700,12 +1702,40 @@ private fun RememberStateFlowScope.flowOfGeneratorType( typesAllFlow, typeFlow, ) { allTypes, type -> + val shouldShowEmailRelayProTip = allTypes.none { it is GeneratorType2.EmailRelay } + val typeTitle = translate(type.title) val typeItems = buildContextItems { + var prevGroup: String? = null allTypes.forEachIndexed { index, item -> if (index > 0) { - val groupChanged = allTypes[index - 1].group != item.group + val groupChanged = prevGroup != item.group if (groupChanged) { + if ( + prevGroup == GENERATOR_TYPE_GROUP_USERNAME && + shouldShowEmailRelayProTip + ) { + val tipBody = translate(Res.string.pro_tip_generate_email_relay_title) + val tip = translate(Res.string.pro_tip, tipBody) + + val note = SimpleNote( + text = tip, + type = SimpleNote.Type.INFO, + ) + this += ContextItem.Custom { + FlatSimpleNote( + type = note.type, + text = note.text, + onClick = { + val route = EmailRelayListRoute + val intent = NavigationIntent.NavigateToRoute(route) + navigate(intent) + }, + icon = false, + ) + } + } + this += when (item.group) { GENERATOR_TYPE_GROUP_INTEGRATION -> ContextItem.Section( @@ -1738,6 +1768,8 @@ private fun RememberStateFlowScope.flowOfGeneratorType( ) } } + + prevGroup = item.group } } GeneratorState.Type( diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/SimpleNote.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/SimpleNote.kt index efb50ac3..6bca3227 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/SimpleNote.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/SimpleNote.kt @@ -62,6 +62,7 @@ fun FlatSimpleNote( content: (@Composable ColumnScope.() -> Unit)? = null, onClick: (() -> Unit)? = null, enabled: Boolean = true, + icon: Boolean = true, ) { val tintColor = when (type) { SimpleNote.Type.OK -> MaterialTheme.colorScheme.ok @@ -86,23 +87,28 @@ fun FlatSimpleNote( backgroundColor = surfaceColor .combineAlpha(DisabledEmphasisAlpha), contentColor = contentColor, - leading = { - if (leading != null) { - leading.invoke(this) - return@FlatItemLayout - } + leading = if (icon) { + // composable + leading@{ + if (leading != null) { + leading.invoke(this) + return@leading + } - val imageVector = when (type) { - SimpleNote.Type.OK -> Icons.Outlined.Check - SimpleNote.Type.INFO -> Icons.Outlined.Info - SimpleNote.Type.WARNING -> Icons.Outlined.Warning - SimpleNote.Type.ERROR -> Icons.Outlined.ErrorOutline + val imageVector = when (type) { + SimpleNote.Type.OK -> Icons.Outlined.Check + SimpleNote.Type.INFO -> Icons.Outlined.Info + SimpleNote.Type.WARNING -> Icons.Outlined.Warning + SimpleNote.Type.ERROR -> Icons.Outlined.ErrorOutline + } + Icon( + imageVector = imageVector, + contentDescription = null, + tint = tintColor, + ) } - Icon( - imageVector = imageVector, - contentDescription = null, - tint = tintColor, - ) + } else { + null }, content = { if (title != null) {