From fbbe27d4bc296c0bbe94151d5c5f799a315484fa Mon Sep 17 00:00:00 2001 From: Artem Chepurnoy Date: Sun, 14 Jan 2024 12:54:29 +0200 Subject: [PATCH] feat: Add Enable toggle to the URL overrides --- .../keyguard/common/model/DGlobalUrlOverride.kt | 1 + .../service/urloverride/UrlOverrideRepositoryImpl.kt | 4 ++++ .../home/vault/screen/VaultViewStateProducer.kt | 4 ++-- .../feature/urloverride/UrlOverrideListScreen.kt | 2 +- .../feature/urloverride/UrlOverrideListState.kt | 1 + .../urloverride/UrlOverrideListStateProducer.kt | 12 ++++++++++++ common/src/commonMain/resources/MR/base/strings.xml | 2 ++ .../com/artemchep/keyguard/data/UrlOverride.sq | 10 ++++++---- common/src/commonMain/sqldelight/migrations/8.sqm | 2 ++ 9 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 common/src/commonMain/sqldelight/migrations/8.sqm diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/model/DGlobalUrlOverride.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/model/DGlobalUrlOverride.kt index 6bd89749..dc7c6319 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/model/DGlobalUrlOverride.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/model/DGlobalUrlOverride.kt @@ -9,6 +9,7 @@ data class DGlobalUrlOverride( val regex: Regex, val command: String, val createdDate: Instant, + val enabled: Boolean, ) : Comparable { val accentColor = run { val colors = generateAccentColors(name) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/service/urloverride/UrlOverrideRepositoryImpl.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/service/urloverride/UrlOverrideRepositoryImpl.kt index 344df3d9..9c99f87e 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/service/urloverride/UrlOverrideRepositoryImpl.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/service/urloverride/UrlOverrideRepositoryImpl.kt @@ -3,6 +3,7 @@ package com.artemchep.keyguard.common.service.urloverride import com.artemchep.keyguard.common.io.IO import com.artemchep.keyguard.common.io.effectMap import com.artemchep.keyguard.common.model.DGlobalUrlOverride +import com.artemchep.keyguard.common.util.int import com.artemchep.keyguard.common.util.sqldelight.flatMapQueryToList import com.artemchep.keyguard.core.store.DatabaseDispatcher import com.artemchep.keyguard.core.store.DatabaseManager @@ -39,6 +40,7 @@ class UrlOverrideRepositoryImpl( regex = regex, command = entity.command, createdDate = entity.createdAt, + enabled = entity.enabled != 0L, ) } } @@ -55,6 +57,7 @@ class UrlOverrideRepositoryImpl( regex = regex, command = model.command, createdAt = model.createdDate, + enabled = model.enabled.int.toLong(), ) } else { dao.insert( @@ -62,6 +65,7 @@ class UrlOverrideRepositoryImpl( regex = regex, command = model.command, createdAt = model.createdDate, + enabled = model.enabled.int.toLong(), ) } } diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultViewStateProducer.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultViewStateProducer.kt index 8871f030..eb8bc899 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultViewStateProducer.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultViewStateProducer.kt @@ -539,8 +539,8 @@ fun vaultViewScreenState( } val urlOverrideList = urlOverrides .filter { override -> - override.regex - .matches(newUriString) + override.enabled && + override.regex.matches(newUriString) } .map { override -> val contentOrException = Either.catch { diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListScreen.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListScreen.kt index 55e102ab..3b4b61e7 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListScreen.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListScreen.kt @@ -248,7 +248,7 @@ private fun UrlOverrideItem( AvatarBuilder( icon = item.icon, accent = accent, - active = true, + active = item.active, badge = { // Do nothing. }, diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListState.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListState.kt index a68f11e2..cd7c579b 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListState.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListState.kt @@ -36,6 +36,7 @@ data class UrlOverrideListState( val icon: VaultItemIcon, val accentLight: Color, val accentDark: Color, + val active: Boolean, val dropdown: ImmutableList, val selectableState: StateFlow, ) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListStateProducer.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListStateProducer.kt index 3f821899..542dea56 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListStateProducer.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/urloverride/UrlOverrideListStateProducer.kt @@ -86,6 +86,13 @@ fun produceUrlOverrideListState( canBeEmpty = false, ) + val enabledKey = "enabled" + val enabledItem = ConfirmationRoute.Args.Item.BooleanItem( + key = enabledKey, + value = entity?.enabled ?: true, + title = translate(Res.strings.enabled), + ) + val regexKey = "regex" val regexItem = ConfirmationRoute.Args.Item.StringItem( key = regexKey, @@ -115,6 +122,7 @@ fun produceUrlOverrideListState( nameItem, regexItem, commandItem, + enabledItem, ) val route = registerRouteResultReceiver( route = ConfirmationRoute( @@ -135,6 +143,8 @@ fun produceUrlOverrideListState( if (result is ConfirmationResult.Confirm) { val name = result.data[nameKey] as? String ?: return@registerRouteResultReceiver + val enabled = result.data[enabledKey] as? Boolean + ?: return@registerRouteResultReceiver val regex = result.data[regexKey] as? String ?: return@registerRouteResultReceiver val placeholder = result.data[commandKey] as? String @@ -146,6 +156,7 @@ fun produceUrlOverrideListState( regex = regex.toRegex(), command = placeholder, createdDate = createdAt, + enabled = enabled, ) addUrlOverride(model) .launchIn(appScope) @@ -333,6 +344,7 @@ fun produceUrlOverrideListState( icon = icon, accentLight = it.accentColor.light, accentDark = it.accentColor.dark, + active = it.enabled, dropdown = dropdown, selectableState = selectableStateFlow, ) diff --git a/common/src/commonMain/resources/MR/base/strings.xml b/common/src/commonMain/resources/MR/base/strings.xml index 6d841c5f..c158347b 100644 --- a/common/src/commonMain/resources/MR/base/strings.xml +++ b/common/src/commonMain/resources/MR/base/strings.xml @@ -7,6 +7,8 @@ Name Account name + Enabled + Disabled Wordlist Username Password diff --git a/common/src/commonMain/sqldelight/com/artemchep/keyguard/data/UrlOverride.sq b/common/src/commonMain/sqldelight/com/artemchep/keyguard/data/UrlOverride.sq index ce82c1e2..ab2425fc 100644 --- a/common/src/commonMain/sqldelight/com/artemchep/keyguard/data/UrlOverride.sq +++ b/common/src/commonMain/sqldelight/com/artemchep/keyguard/data/UrlOverride.sq @@ -5,7 +5,8 @@ CREATE TABLE urlOverride ( name TEXT NOT NULL, regex TEXT NOT NULL, command TEXT NOT NULL, - createdAt INTEGER AS Instant NOT NULL + createdAt INTEGER AS Instant NOT NULL, + enabled INTEGER NOT NULL ); update { @@ -14,14 +15,15 @@ update { name = :name, regex = :regex, command = :command, - createdAt = :createdAt + createdAt = :createdAt, + enabled = :enabled WHERE id = :id; } insert { - INSERT OR IGNORE INTO urlOverride(name, regex, command, createdAt) - VALUES (:name, :regex, :command, :createdAt); + INSERT OR IGNORE INTO urlOverride(name, regex, command, createdAt, enabled) + VALUES (:name, :regex, :command, :createdAt, :enabled); } get: diff --git a/common/src/commonMain/sqldelight/migrations/8.sqm b/common/src/commonMain/sqldelight/migrations/8.sqm new file mode 100644 index 00000000..1598f40f --- /dev/null +++ b/common/src/commonMain/sqldelight/migrations/8.sqm @@ -0,0 +1,2 @@ +ALTER TABLE urlOverride +ADD COLUMN enabled INTEGER DEFAULT 1;