Skip to content

Commit

Permalink
feat: Add Enable toggle to the URL overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
AChep committed Jan 14, 2024
1 parent c2f0a81 commit fbbe27d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,6 +40,7 @@ class UrlOverrideRepositoryImpl(
regex = regex,
command = entity.command,
createdDate = entity.createdAt,
enabled = entity.enabled != 0L,
)
}
}
Expand All @@ -55,13 +57,15 @@ class UrlOverrideRepositoryImpl(
regex = regex,
command = model.command,
createdAt = model.createdDate,
enabled = model.enabled.int.toLong(),
)
} else {
dao.insert(
name = model.name,
regex = regex,
command = model.command,
createdAt = model.createdDate,
enabled = model.enabled.int.toLong(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private fun UrlOverrideItem(
AvatarBuilder(
icon = item.icon,
accent = accent,
active = true,
active = item.active,
badge = {
// Do nothing.
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -115,6 +122,7 @@ fun produceUrlOverrideListState(
nameItem,
regexItem,
commandItem,
enabledItem,
)
val route = registerRouteResultReceiver(
route = ConfirmationRoute(
Expand All @@ -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
Expand All @@ -146,6 +156,7 @@ fun produceUrlOverrideListState(
regex = regex.toRegex(),
command = placeholder,
createdDate = createdAt,
enabled = enabled,
)
addUrlOverride(model)
.launchIn(appScope)
Expand Down Expand Up @@ -333,6 +344,7 @@ fun produceUrlOverrideListState(
icon = icon,
accentLight = it.accentColor.light,
accentDark = it.accentColor.dark,
active = it.enabled,
dropdown = dropdown,
selectableState = selectableStateFlow,
)
Expand Down
2 changes: 2 additions & 0 deletions common/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions common/src/commonMain/sqldelight/migrations/8.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE urlOverride
ADD COLUMN enabled INTEGER DEFAULT 1;

0 comments on commit fbbe27d

Please sign in to comment.