fix: All past dates and times are crossed out #1710

This commit is contained in:
J-Jamet 2024-11-13 20:54:31 +01:00
parent 8e05309021
commit 55206b3dde
8 changed files with 44 additions and 8 deletions

View file

@ -3,7 +3,7 @@ KeePassDX(4.1.0)
* Generate keyfile #1290
* Hide template group #1894
* Group count sum recursively #421
* Fix when selecting date fields #1695
* Fix date fields #1695 #1710
* Fix distinct domain names #1105 #1820
* Support otpauth://steam/Steam link #1289
* Small fixes #1711 #1831 #1780 #1821 #1863 #1889

View file

@ -57,8 +57,6 @@ class DateTimeFieldView @JvmOverloads constructor(context: Context,
}
private fun assignExpiresDateText() {
val isExpires = mDateTime.isCurrentlyExpire()
// Show or not the warning icon
expiresImage.isVisible = if (mActivated) {
isExpires
@ -100,6 +98,13 @@ class DateTimeFieldView @JvmOverloads constructor(context: Context,
mDateTime.type = value
}
var isExpirable: Boolean = false
val isExpires: Boolean
get() {
return isExpirable && mDateTime.isCurrentlyExpire()
}
override var activation: Boolean
get() {
return mActivated

View file

@ -100,13 +100,12 @@ class TemplateView @JvmOverloads constructor(context: Context,
return context?.let {
DateTimeFieldView(it).apply {
label = TemplateField.getLocalizedName(context, field.name)
val dateInstantType = templateAttribute.options.getDateFormat()
type = templateAttribute.options.getDateFormat()
isExpirable = templateAttribute.options.getExpirable()
try {
val value = field.protectedValue.toString().trim()
type = dateInstantType
activation = value.isNotEmpty()
} catch (e: Exception) {
type = dateInstantType
activation = false
}
}

View file

@ -154,7 +154,10 @@ class Template : Parcelable {
val EXPIRATION_ATTRIBUTE = TemplateAttribute(
TemplateField.LABEL_EXPIRATION,
TemplateAttributeType.DATETIME,
false)
false,
TemplateAttributeOption().apply {
setExpirable(true)
})
val NOTES_ATTRIBUTE = TemplateAttribute(
TemplateField.LABEL_NOTES,
TemplateAttributeType.TEXT,

View file

@ -152,6 +152,18 @@ class TemplateAttributeOption() : Parcelable {
mOptions[DATETIME_FORMAT_ATTR] = DATETIME_FORMAT_VALUE_TIME
}
fun getExpirable(): Boolean {
return try {
mOptions[DATETIME_EXPIRABLE_ATTR]?.toBoolean() ?: DATETIME_EXPIRABLE_VALUE_DEFAULT
} catch (e: Exception) {
DATETIME_EXPIRABLE_VALUE_DEFAULT
}
}
fun setExpirable(value: Boolean) {
mOptions[DATETIME_EXPIRABLE_ATTR] = value.toString().lowercase()
}
fun get(label: String): String? {
return mOptions[label]
}
@ -246,6 +258,15 @@ class TemplateAttributeOption() : Parcelable {
private const val DATETIME_FORMAT_VALUE_DATE = "date"
private const val DATETIME_FORMAT_VALUE_TIME = "time"
/**
* Applicable to type DATETIME
* Define if a datetime is expirable
* Boolean ("true" or "false")
* "false" if not defined
*/
private const val DATETIME_EXPIRABLE_ATTR = "expirable"
private const val DATETIME_EXPIRABLE_VALUE_DEFAULT = false
private fun removeSpecialChars(string: String): String {
return string.filterNot { "{,:}".indexOf(it) > -1 }
}

View file

@ -216,6 +216,11 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database)
attribute.options.associatePasswordGenerator()
}
// Add expiration
if (attribute.label.equals(TEMPLATE_ATTRIBUTE_EXPIRES, true)) {
attribute.options.setExpirable(true)
}
// Add default value
if (defaultValues.containsKey(attribute.label)) {
attribute.options.default = defaultValues[attribute.label]!!

View file

@ -2,7 +2,7 @@
* Generate keyfile #1290
* Hide template group #1894
* Group count sum recursively #421
* Fix when selecting date fields #1695
* Fix date fields #1695 #1710
* Fix distinct domain names #1105 #1820
* Support otpauth://steam/Steam link #1289
* Small fixes #1711 #1831 #1780 #1821 #1863 #1889

View file

@ -2,4 +2,7 @@
* Génération de fichier de clé #1290
* Cacher les groupes de modèles #1894
* Somme de comptage de groupes de manière récursive #421
* Correction des champs date #1695 #1710
* Correction des noms de domaines #1105 #1820
* Support des liens otpauth://steam/Steam #1289
* Petites corrections #1711 #1831 #1780 #1821 #1863