diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/CopyText.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/CopyText.kt index 81ff146..bf95f86 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/CopyText.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/CopyText.kt @@ -2,22 +2,49 @@ package com.artemchep.keyguard.common.usecase import com.artemchep.keyguard.common.model.ToastMessage import com.artemchep.keyguard.common.service.clipboard.ClipboardService +import com.artemchep.keyguard.feature.navigation.state.TranslatorScope +import com.artemchep.keyguard.res.Res +import dev.icerock.moko.resources.StringResource /** * @author Artem Chepurnyi */ class CopyText( private val clipboardService: ClipboardService, + private val translator: TranslatorScope, private val onMessage: (ToastMessage) -> Unit, ) { + enum class Type( + val res: StringResource, + ) { + VALUE(Res.strings.copied_value), + URL(Res.strings.copied_url), + URI(Res.strings.copied_uri), + PACKAGE_NAME(Res.strings.copied_package_name), + PASSWORD(Res.strings.copied_password), + USERNAME(Res.strings.copied_username), + EMAIL(Res.strings.copied_email), + PHONE_NUMBER(Res.strings.copied_phone_number), + PASSPORT_NUMBER(Res.strings.copied_passport_number), + LICENSE_NUMBER(Res.strings.copied_license_number), + CARD_NUMBER(Res.strings.copied_card_number), + CARD_CARDHOLDER_NAME(Res.strings.copied_cardholder_name), + CARD_EXP_YEAR(Res.strings.copied_expiration_year), + CARD_EXP_MONTH(Res.strings.copied_expiration_month), + CARD_CVV(Res.strings.copied_cvv_code), + OTP(Res.strings.copied_otp_code), + OTP_SECRET(Res.strings.copied_otp_secret_code), + } + fun copy( text: String, hidden: Boolean, + type: Type = Type.VALUE, ) { clipboardService.setPrimaryClip(text, concealed = hidden) if (!clipboardService.hasCopyNotification()) { val message = ToastMessage( - title = "Copied a value", + title = translator.translate(type.res), text = text.takeUnless { hidden }, ) onMessage(message) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/auth/AccountViewStateProducer.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/auth/AccountViewStateProducer.kt index 07784a5..ed0461d 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/auth/AccountViewStateProducer.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/auth/AccountViewStateProducer.kt @@ -785,6 +785,7 @@ private suspend fun FlowCollector.emitEmail( this += copyText.FlatItemAction( title = scope.translate(Res.strings.copy), value = email, + type = CopyText.Type.EMAIL, ) } section { 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 5db5eba..ea557c3 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 @@ -38,6 +38,7 @@ import com.artemchep.keyguard.common.model.isExpensive import com.artemchep.keyguard.common.service.clipboard.ClipboardService import com.artemchep.keyguard.common.service.relays.api.EmailRelay import com.artemchep.keyguard.common.usecase.AddGeneratorHistory +import com.artemchep.keyguard.common.usecase.CopyText import com.artemchep.keyguard.common.usecase.GetCanWrite import com.artemchep.keyguard.common.usecase.GetEmailRelays import com.artemchep.keyguard.common.usecase.GetPassword @@ -1226,6 +1227,7 @@ fun produceGeneratorState( this += copyItemFactory.FlatItemAction( title = translate(Res.strings.copy), value = password, + type = CopyText.Type.PASSWORD, ) } val actions = kotlin.run { @@ -1263,6 +1265,7 @@ fun produceGeneratorState( copyItemFactory::copy .partially1(password) .partially1(false) + .partially1(CopyText.Type.PASSWORD) } else { null }, diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/component/VaultViewTotpItem.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/component/VaultViewTotpItem.kt index 0a30d37..523c12a 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/component/VaultViewTotpItem.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/component/VaultViewTotpItem.kt @@ -196,7 +196,11 @@ fun VaultViewTotpBadge2( .clickable(enabled = state is VaultViewTotpItemBadgeState.Success) { val code = (state as? VaultViewTotpItemBadgeState.Success) ?.codeRaw ?: return@clickable - copyText.copy(code, hidden = false) + copyText.copy( + text = code, + hidden = false, + type = CopyText.Type.OTP, + ) } .padding( start = 8.dp, diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultListItemMapping.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultListItemMapping.kt index 74be1bb..f40856b 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultListItemMapping.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultListItemMapping.kt @@ -227,7 +227,11 @@ private suspend fun DSecret.createLogin( getTotpCode(token) .toIO() .effectTap { code -> - copy.copy(code.code, false) + copy.copy( + text = code.code, + hidden = false, + type = CopyText.Type.OTP, + ) } .attempt() .launchIn(GlobalScope) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/Copy.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/Copy.kt index e527d6a..ef73267 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/Copy.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/Copy.kt @@ -7,5 +7,6 @@ fun RememberStateFlowScope.copy( clipboardService: ClipboardService, ) = CopyText( clipboardService = clipboardService, + translator = this@copy, onMessage = ::message, ) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/PasswordFilterItem.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/PasswordFilterItem.kt index 0551c88..f6dc163 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/PasswordFilterItem.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/PasswordFilterItem.kt @@ -190,6 +190,7 @@ fun CopyText.FlatItemAction( title: String, value: String, hidden: Boolean = false, + type: CopyText.Type = CopyText.Type.VALUE, ) = FlatItemAction( leading = leading, icon = Icons.Outlined.ContentCopy, @@ -197,8 +198,11 @@ fun CopyText.FlatItemAction( text = value.takeUnless { hidden }, type = FlatItemAction.Type.COPY, onClick = { - println("Copying!") - copy(value, hidden) + copy( + text = value, + hidden = hidden, + type = type, + ) }, ) diff --git a/common/src/commonMain/resources/MR/base/strings.xml b/common/src/commonMain/resources/MR/base/strings.xml index 21dd374..fefd692 100644 --- a/common/src/commonMain/resources/MR/base/strings.xml +++ b/common/src/commonMain/resources/MR/base/strings.xml @@ -317,10 +317,28 @@ Copy cardholder name Copy expiration year Copy expiration month - Copy CVV code + Copy security code Copy one-time password Copy secret key + Copied a value + Copied a URL + Copied a URI + Copied a package name + Copied a password + Copied a username + Copied an email + Copied a phone number + Copied a passport number + Copied a license number + Copied a card number + Copied a cardholder name + Copied an expiration year + Copied an expiration month + Copied a security code + Copied an one-time password + Copied a secret key + Unlock Keyguard Open Keyguard