From 00498aaeac0c6769d950e54102efa8a2fdc9a495 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 3 Jul 2021 20:49:04 +0200 Subject: [PATCH] Fix options recognition --- .../template/TemplateAttributeOption.kt | 10 ++++--- .../element/template/TemplateBuilder.kt | 2 +- .../template/TemplateEngineCompatible.kt | 27 ++++++++++++++++--- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateAttributeOption.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateAttributeOption.kt index 074bbe1dc..d03ce07b5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateAttributeOption.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateAttributeOption.kt @@ -8,11 +8,11 @@ class TemplateAttributeOption { /** * Applicable to type TEXT - * Integer, can be "-1" to infinite value + * Integer, can be "-1" or "many" to infinite value * "1" if not defined */ const val NUMBER_LINES = "lines" - const val NUMBER_LINES_INFINITE = "-1" + const val NUMBER_LINES_MANY = "many" /** * Applicable to type TEXT @@ -33,7 +33,11 @@ class TemplateAttributeOption { fun getNumberLines(options: LinkedHashMap): Int { return try { - options[NUMBER_LINES]?.toInt() ?: 1 + val value = options[NUMBER_LINES] + if (value == NUMBER_LINES_MANY) + -1 + else + options[NUMBER_LINES]?.toInt() ?: 1 } catch (e: Exception) { 1 } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateBuilder.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateBuilder.kt index 317f1a4aa..93ff28fc2 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateBuilder.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateBuilder.kt @@ -14,7 +14,7 @@ class TemplateBuilder { TemplateAttributeType.TEXT, false, LinkedHashMap().apply { - put(TemplateAttributeOption.NUMBER_LINES, TemplateAttributeOption.NUMBER_LINES_INFINITE) + put(TemplateAttributeOption.NUMBER_LINES, TemplateAttributeOption.NUMBER_LINES_MANY) }) private val holderAttribute = TemplateAttribute(TemplateField.LABEL_HOLDER, TemplateAttributeType.TEXT) private val numberAttribute = TemplateAttribute(TemplateField.LABEL_NUMBER, TemplateAttributeType.TEXT) diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateEngineCompatible.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateEngineCompatible.kt index 9b9dd4887..47569fb70 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateEngineCompatible.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateEngineCompatible.kt @@ -117,7 +117,7 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database) value.contains(TEMPLATE_ATTRIBUTE_TYPE_RICH_TEXTBOX, true) -> { attribute.attribute.type = TemplateAttributeType.TEXT attribute.attribute.options[TemplateAttributeOption.NUMBER_LINES] = - TemplateAttributeOption.NUMBER_LINES_INFINITE + TemplateAttributeOption.NUMBER_LINES_MANY } value.contains(TEMPLATE_ATTRIBUTE_TYPE_DATE_TIME, true) -> { attribute.attribute.type = TemplateAttributeType.DATETIME @@ -134,6 +134,7 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database) } value.contains(TEMPLATE_ATTRIBUTE_TYPE_LISTBOX, true) -> { attribute.attribute.type = TemplateAttributeType.TEXT + // TODO List box } value.contains(TEMPLATE_ATTRIBUTE_TYPE_DIVIDER, true) -> { attribute.attribute.type = TemplateAttributeType.DIVIDER @@ -190,9 +191,27 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database) ProtectedString(false, label) ) // Add protected string if needed - var typeString = value.stringValue - if (value.isProtected - && !typeString.contains(TEMPLATE_ATTRIBUTE_TYPE_PROTECTED)) { + var typeString: String = when { + value.stringValue.contains(TemplateAttributeType.TEXT.label, true) -> { + when (TemplateAttributeOption.getOptionsFromString(field.protectedValue.stringValue)[TemplateAttributeOption.NUMBER_LINES]) { + TemplateAttributeOption.NUMBER_LINES_MANY -> TEMPLATE_ATTRIBUTE_TYPE_MULTILINE + else -> TEMPLATE_ATTRIBUTE_TYPE_INLINE + } + } + value.stringValue.contains(TemplateAttributeType.DATETIME.label, true) -> { + when (TemplateAttributeOption.getOptionsFromString(field.protectedValue.stringValue)[TemplateAttributeOption.DATETIME_FORMAT]) { + TemplateAttributeOption.DATETIME_FORMAT_DATE -> TEMPLATE_ATTRIBUTE_TYPE_DATE + TemplateAttributeOption.DATETIME_FORMAT_TIME -> TEMPLATE_ATTRIBUTE_TYPE_TIME + else -> TEMPLATE_ATTRIBUTE_TYPE_DATE_TIME + } + } + value.stringValue.contains(TemplateAttributeType.DIVIDER.label, true) -> { + TEMPLATE_ATTRIBUTE_TYPE_DIVIDER + } + else -> TEMPLATE_ATTRIBUTE_TYPE_INLINE + } + + if (value.isProtected) { typeString = "$TEMPLATE_ATTRIBUTE_TYPE_PROTECTED $typeString" } entryCopy.putField(