mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix password generator
This commit is contained in:
@@ -121,8 +121,8 @@ class Template : Parcelable {
|
||||
true,
|
||||
TemplateAttributeOption().apply {
|
||||
setNumberLines(3)
|
||||
},
|
||||
TemplateAttributeAction.PASSWORD_GENERATION
|
||||
associatePasswordGenerator()
|
||||
}
|
||||
)
|
||||
val URL_ATTRIBUTE = TemplateAttribute(
|
||||
TemplateField.LABEL_URL,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.kunzisoft.keepass.database.element.template
|
||||
|
||||
enum class TemplateAttributeAction {
|
||||
NONE, CUSTOM_EDITION, PASSWORD_GENERATION
|
||||
NONE, CUSTOM_EDITION
|
||||
}
|
||||
@@ -96,6 +96,18 @@ class TemplateAttributeOption() : Parcelable {
|
||||
mOptions[TEXT_LINK_ATTR] = isLink.toString()
|
||||
}
|
||||
|
||||
fun isAssociatedWithPasswordGenerator(): Boolean {
|
||||
return try {
|
||||
mOptions[PASSWORD_GENERATOR_ATTR]?.toBoolean() ?: PASSWORD_GENERATOR_VALUE_DEFAULT
|
||||
} catch (e: Exception) {
|
||||
PASSWORD_GENERATOR_VALUE_DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
fun associatePasswordGenerator() {
|
||||
mOptions[PASSWORD_GENERATOR_ATTR] = true.toString()
|
||||
}
|
||||
|
||||
fun getListItems(): List<String> {
|
||||
return mOptions[LIST_ITEMS]?.split(LIST_ITEMS_SEPARATOR) ?: listOf()
|
||||
}
|
||||
@@ -158,6 +170,7 @@ class TemplateAttributeOption() : Parcelable {
|
||||
|
||||
/**
|
||||
* Applicable to type TEXT
|
||||
* Define a number of chars
|
||||
* Integer, can be "many" or "-1" to infinite value
|
||||
* "1" if not defined
|
||||
*/
|
||||
@@ -168,6 +181,7 @@ class TemplateAttributeOption() : Parcelable {
|
||||
|
||||
/**
|
||||
* Applicable to type TEXT
|
||||
* Define a number of lines
|
||||
* Integer, can be "-1" to infinite value
|
||||
* "1" if not defined
|
||||
*/
|
||||
@@ -178,14 +192,25 @@ class TemplateAttributeOption() : Parcelable {
|
||||
|
||||
/**
|
||||
* Applicable to type TEXT
|
||||
* Define if a text is a link
|
||||
* Boolean ("true" or "false")
|
||||
* "true" if not defined
|
||||
*/
|
||||
private const val TEXT_LINK_ATTR = "link"
|
||||
private const val TEXT_LINK_VALUE_DEFAULT = false
|
||||
|
||||
/**
|
||||
* Applicable to type TEXT
|
||||
* Define if a password generator is associated with the text
|
||||
* Boolean ("true" or "false")
|
||||
* "false" if not defined
|
||||
*/
|
||||
private const val PASSWORD_GENERATOR_ATTR = "generator"
|
||||
private const val PASSWORD_GENERATOR_VALUE_DEFAULT = false
|
||||
|
||||
/**
|
||||
* Applicable to type LIST
|
||||
* Define items of a list
|
||||
* List of items, separator is '|'
|
||||
*/
|
||||
private const val LIST_ITEMS = "items"
|
||||
@@ -193,6 +218,7 @@ class TemplateAttributeOption() : Parcelable {
|
||||
|
||||
/**
|
||||
* Applicable to type DATETIME
|
||||
* Define the type of date
|
||||
* String ("date" or "time" or "datetime" or based on https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html)
|
||||
* "datetime" if not defined
|
||||
*/
|
||||
@@ -200,7 +226,6 @@ class TemplateAttributeOption() : Parcelable {
|
||||
private const val DATETIME_FORMAT_VALUE_DATE = "date"
|
||||
private const val DATETIME_FORMAT_VALUE_TIME = "time"
|
||||
|
||||
|
||||
fun getOptionsFromString(label: String): TemplateAttributeOption {
|
||||
val options = TemplateAttributeOption()
|
||||
val optionsMap = if (label.contains("{") || label.contains("}")) {
|
||||
|
||||
@@ -195,6 +195,11 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database)
|
||||
|
||||
val attribute = it.attribute
|
||||
|
||||
// Add password generator
|
||||
if (attribute.label.equals(TEMPLATE_ATTRIBUTE_PASSWORD, true)) {
|
||||
attribute.options.associatePasswordGenerator()
|
||||
}
|
||||
|
||||
// Recognize each temp option
|
||||
attribute.options.get(TEMPLATE_ATTRIBUTE_OPTIONS_TEMP)?.let { defaultOption ->
|
||||
when (attribute.type) {
|
||||
|
||||
@@ -88,6 +88,7 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
|
||||
?: TemplateField.getLocalizedName(context, field.name)
|
||||
val fieldValue = field.protectedValue.stringValue
|
||||
value = if (fieldValue.isEmpty()) templateAttribute.default else fieldValue
|
||||
// TODO edition and password generator at same time
|
||||
when (templateAttribute.action) {
|
||||
TemplateAttributeAction.NONE -> {
|
||||
setOnActionClickListener(null)
|
||||
@@ -97,11 +98,11 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
|
||||
mOnCustomEditionActionClickListener?.invoke(field)
|
||||
}, R.drawable.ic_more_white_24dp)
|
||||
}
|
||||
TemplateAttributeAction.PASSWORD_GENERATION -> {
|
||||
setOnActionClickListener({
|
||||
mOnPasswordGenerationActionClickListener?.invoke(field)
|
||||
}, R.drawable.ic_generate_password_white_24dp)
|
||||
}
|
||||
}
|
||||
if (templateAttribute.options.isAssociatedWithPasswordGenerator()) {
|
||||
setOnActionClickListener({
|
||||
mOnPasswordGenerationActionClickListener?.invoke(field)
|
||||
}, R.drawable.ic_generate_password_white_24dp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user