feat: Add Enable toggle to the URL overrides

This commit is contained in:
Artem Chepurnoy 2024-01-14 12:54:29 +02:00
parent c2f0a81e8a
commit fbbe27d4bc
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
9 changed files with 31 additions and 7 deletions

View File

@ -9,6 +9,7 @@ data class DGlobalUrlOverride(
val regex: Regex, val regex: Regex,
val command: String, val command: String,
val createdDate: Instant, val createdDate: Instant,
val enabled: Boolean,
) : Comparable<DGlobalUrlOverride> { ) : Comparable<DGlobalUrlOverride> {
val accentColor = run { val accentColor = run {
val colors = generateAccentColors(name) val colors = generateAccentColors(name)

View File

@ -3,6 +3,7 @@ package com.artemchep.keyguard.common.service.urloverride
import com.artemchep.keyguard.common.io.IO import com.artemchep.keyguard.common.io.IO
import com.artemchep.keyguard.common.io.effectMap import com.artemchep.keyguard.common.io.effectMap
import com.artemchep.keyguard.common.model.DGlobalUrlOverride 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.common.util.sqldelight.flatMapQueryToList
import com.artemchep.keyguard.core.store.DatabaseDispatcher import com.artemchep.keyguard.core.store.DatabaseDispatcher
import com.artemchep.keyguard.core.store.DatabaseManager import com.artemchep.keyguard.core.store.DatabaseManager
@ -39,6 +40,7 @@ class UrlOverrideRepositoryImpl(
regex = regex, regex = regex,
command = entity.command, command = entity.command,
createdDate = entity.createdAt, createdDate = entity.createdAt,
enabled = entity.enabled != 0L,
) )
} }
} }
@ -55,6 +57,7 @@ class UrlOverrideRepositoryImpl(
regex = regex, regex = regex,
command = model.command, command = model.command,
createdAt = model.createdDate, createdAt = model.createdDate,
enabled = model.enabled.int.toLong(),
) )
} else { } else {
dao.insert( dao.insert(
@ -62,6 +65,7 @@ class UrlOverrideRepositoryImpl(
regex = regex, regex = regex,
command = model.command, command = model.command,
createdAt = model.createdDate, createdAt = model.createdDate,
enabled = model.enabled.int.toLong(),
) )
} }
} }

View File

@ -539,8 +539,8 @@ fun vaultViewScreenState(
} }
val urlOverrideList = urlOverrides val urlOverrideList = urlOverrides
.filter { override -> .filter { override ->
override.regex override.enabled &&
.matches(newUriString) override.regex.matches(newUriString)
} }
.map { override -> .map { override ->
val contentOrException = Either.catch { val contentOrException = Either.catch {

View File

@ -248,7 +248,7 @@ private fun UrlOverrideItem(
AvatarBuilder( AvatarBuilder(
icon = item.icon, icon = item.icon,
accent = accent, accent = accent,
active = true, active = item.active,
badge = { badge = {
// Do nothing. // Do nothing.
}, },

View File

@ -36,6 +36,7 @@ data class UrlOverrideListState(
val icon: VaultItemIcon, val icon: VaultItemIcon,
val accentLight: Color, val accentLight: Color,
val accentDark: Color, val accentDark: Color,
val active: Boolean,
val dropdown: ImmutableList<ContextItem>, val dropdown: ImmutableList<ContextItem>,
val selectableState: StateFlow<SelectableItemState>, val selectableState: StateFlow<SelectableItemState>,
) )

View File

@ -86,6 +86,13 @@ fun produceUrlOverrideListState(
canBeEmpty = false, 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 regexKey = "regex"
val regexItem = ConfirmationRoute.Args.Item.StringItem( val regexItem = ConfirmationRoute.Args.Item.StringItem(
key = regexKey, key = regexKey,
@ -115,6 +122,7 @@ fun produceUrlOverrideListState(
nameItem, nameItem,
regexItem, regexItem,
commandItem, commandItem,
enabledItem,
) )
val route = registerRouteResultReceiver( val route = registerRouteResultReceiver(
route = ConfirmationRoute( route = ConfirmationRoute(
@ -135,6 +143,8 @@ fun produceUrlOverrideListState(
if (result is ConfirmationResult.Confirm) { if (result is ConfirmationResult.Confirm) {
val name = result.data[nameKey] as? String val name = result.data[nameKey] as? String
?: return@registerRouteResultReceiver ?: return@registerRouteResultReceiver
val enabled = result.data[enabledKey] as? Boolean
?: return@registerRouteResultReceiver
val regex = result.data[regexKey] as? String val regex = result.data[regexKey] as? String
?: return@registerRouteResultReceiver ?: return@registerRouteResultReceiver
val placeholder = result.data[commandKey] as? String val placeholder = result.data[commandKey] as? String
@ -146,6 +156,7 @@ fun produceUrlOverrideListState(
regex = regex.toRegex(), regex = regex.toRegex(),
command = placeholder, command = placeholder,
createdDate = createdAt, createdDate = createdAt,
enabled = enabled,
) )
addUrlOverride(model) addUrlOverride(model)
.launchIn(appScope) .launchIn(appScope)
@ -333,6 +344,7 @@ fun produceUrlOverrideListState(
icon = icon, icon = icon,
accentLight = it.accentColor.light, accentLight = it.accentColor.light,
accentDark = it.accentColor.dark, accentDark = it.accentColor.dark,
active = it.enabled,
dropdown = dropdown, dropdown = dropdown,
selectableState = selectableStateFlow, selectableState = selectableStateFlow,
) )

View File

@ -7,6 +7,8 @@
<!-- A name of a thing, such as an account --> <!-- A name of a thing, such as an account -->
<string name="generic_name">Name</string> <string name="generic_name">Name</string>
<string name="account_name">Account name</string> <string name="account_name">Account name</string>
<string name="enabled">Enabled</string>
<string name="disabled">Disabled</string>
<string name="wordlist">Wordlist</string> <string name="wordlist">Wordlist</string>
<string name="username">Username</string> <string name="username">Username</string>
<string name="password">Password</string> <string name="password">Password</string>

View File

@ -5,7 +5,8 @@ CREATE TABLE urlOverride (
name TEXT NOT NULL, name TEXT NOT NULL,
regex TEXT NOT NULL, regex TEXT NOT NULL,
command TEXT NOT NULL, command TEXT NOT NULL,
createdAt INTEGER AS Instant NOT NULL createdAt INTEGER AS Instant NOT NULL,
enabled INTEGER NOT NULL
); );
update { update {
@ -14,14 +15,15 @@ update {
name = :name, name = :name,
regex = :regex, regex = :regex,
command = :command, command = :command,
createdAt = :createdAt createdAt = :createdAt,
enabled = :enabled
WHERE WHERE
id = :id; id = :id;
} }
insert { insert {
INSERT OR IGNORE INTO urlOverride(name, regex, command, createdAt) INSERT OR IGNORE INTO urlOverride(name, regex, command, createdAt, enabled)
VALUES (:name, :regex, :command, :createdAt); VALUES (:name, :regex, :command, :createdAt, :enabled);
} }
get: get:

View File

@ -0,0 +1,2 @@
ALTER TABLE urlOverride
ADD COLUMN enabled INTEGER DEFAULT 1;