From 9df9b68d4c5eae7837c4060018d74ea2148727d6 Mon Sep 17 00:00:00 2001 From: Artem Chepurnoy Date: Sun, 28 Jan 2024 16:37:42 +0200 Subject: [PATCH] Rename Duplicates sensitivity to Tolerance and move it to the translatable resources --- .../common/usecase/CipherDuplicatesCheck.kt | 28 +++++++++++++++---- .../duplicates/list/DuplicatesListScreen.kt | 22 ++++++++------- .../list/DuplicatesListStateProducer.kt | 4 +-- .../commonMain/resources/MR/base/strings.xml | 7 +++++ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/CipherDuplicatesCheck.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/CipherDuplicatesCheck.kt index a03aecee..2a6ef08d 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/CipherDuplicatesCheck.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/CipherDuplicatesCheck.kt @@ -2,18 +2,36 @@ package com.artemchep.keyguard.common.usecase import com.artemchep.keyguard.common.model.DSecret import com.artemchep.keyguard.common.model.DSecretDuplicateGroup +import com.artemchep.keyguard.res.Res +import dev.icerock.moko.resources.StringResource import kotlinx.serialization.Serializable interface CipherDuplicatesCheck : (List, CipherDuplicatesCheck.Sensitivity) -> List { @Serializable enum class Sensitivity( + val title: StringResource, val threshold: Float, ) { - MAX(0.3f), - HIGH(0.15f), - NORMAL(0f), - LOW(-0.1f), - MIN(-0.15f), + MAX( + title = Res.strings.tolerance_min, + threshold = 0.3f, + ), + HIGH( + title = Res.strings.tolerance_low, + threshold = 0.15f, + ), + NORMAL( + title = Res.strings.tolerance_normal, + threshold = 0f, + ), + LOW( + title = Res.strings.tolerance_high, + threshold = -0.1f, + ), + MIN( + title = Res.strings.tolerance_max, + threshold = -0.15f, + ), } } diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/duplicates/list/DuplicatesListScreen.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/duplicates/list/DuplicatesListScreen.kt index 75031856..b410b59d 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/duplicates/list/DuplicatesListScreen.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/duplicates/list/DuplicatesListScreen.kt @@ -7,6 +7,9 @@ import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.lazy.items import androidx.compose.material.ExperimentalMaterialApi +import androidx.compose.material.Icon +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.EdgesensorHigh import androidx.compose.material3.DropdownMenu import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.LocalContentColor @@ -127,25 +130,24 @@ fun DuplicatesListScreen( mutableStateOf(false) } - val normalContentColor = LocalContentColor.current TextButton( onClick = { isAutofillWindowShowing = true }, ) { Column { - Text(text = "Sensitivity") - val textOrNull = - loadableState.getOrNull()?.sensitivity?.name - ?.lowercase() - ?.capitalize() + Text( + text = stringResource(Res.strings.tolerance), + ) + val textResOrNull = + loadableState.getOrNull()?.sensitivity?.title ExpandedIfNotEmpty( - valueOrNull = textOrNull, - ) { text -> + valueOrNull = textResOrNull, + ) { textRes -> Text( - text = text, + text = stringResource(textRes), style = MaterialTheme.typography.labelSmall, - color = normalContentColor + color = LocalContentColor.current .combineAlpha(MediumEmphasisAlpha), ) } diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/duplicates/list/DuplicatesListStateProducer.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/duplicates/list/DuplicatesListStateProducer.kt index 517787b6..b8337431 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/duplicates/list/DuplicatesListStateProducer.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/duplicates/list/DuplicatesListStateProducer.kt @@ -349,9 +349,7 @@ fun produceDuplicatesListState( .entries .map { s -> FlatItemAction( - title = s.name - .lowercase() - .capitalize(), + title = translate(s.title), onClick = { sensitivitySink.value = s }, diff --git a/common/src/commonMain/resources/MR/base/strings.xml b/common/src/commonMain/resources/MR/base/strings.xml index 17264593..dd7df1fc 100644 --- a/common/src/commonMain/resources/MR/base/strings.xml +++ b/common/src/commonMain/resources/MR/base/strings.xml @@ -370,6 +370,13 @@ November December + Tolerance + Min + Low + Normal + High + Max + Move up Move down Remove