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 command: String,
val createdDate: Instant,
val enabled: Boolean,
) : Comparable<DGlobalUrlOverride> {
val accentColor = run {
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.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(),
)
}
}

View File

@ -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 {

View File

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

View File

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

View File

@ -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,
)

View File

@ -7,6 +7,8 @@
<!-- A name of a thing, such as an account -->
<string name="generic_name">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="username">Username</string>
<string name="password">Password</string>

View File

@ -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:

View File

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