mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix templates #1128
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
KeePassDX(3.1.0)
|
||||
* Change default Argon2 parameters #1098
|
||||
* Add & edit custom icon name #976
|
||||
* Fix templates #1128
|
||||
|
||||
KeePassDX(3.0.2)
|
||||
* Samsung DeX mode #1114 #245 (Thx @chenxiaolong)
|
||||
|
||||
@@ -86,7 +86,8 @@ abstract class TemplateAbstractView<
|
||||
if (mTemplate != template) {
|
||||
mTemplate = template
|
||||
if (mEntryInfo != null) {
|
||||
populateEntryInfoWithViews(true)
|
||||
populateEntryInfoWithViews(templateFieldNotEmpty = true,
|
||||
retrieveDefaultValues = false)
|
||||
}
|
||||
buildTemplateAndPopulateInfo()
|
||||
clearFocus()
|
||||
@@ -203,9 +204,7 @@ abstract class TemplateAbstractView<
|
||||
setNumberLines(20)
|
||||
},
|
||||
TemplateAttributeAction.CUSTOM_EDITION
|
||||
).apply {
|
||||
default = field.protectedValue.stringValue
|
||||
}
|
||||
)
|
||||
return buildViewForTemplateField(customFieldTemplateAttribute, field, FIELD_CUSTOM_TAG)
|
||||
}
|
||||
|
||||
@@ -390,7 +389,8 @@ abstract class TemplateAbstractView<
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
protected open fun populateEntryInfoWithViews(templateFieldNotEmpty: Boolean) {
|
||||
protected open fun populateEntryInfoWithViews(templateFieldNotEmpty: Boolean,
|
||||
retrieveDefaultValues: Boolean) {
|
||||
if (mEntryInfo == null)
|
||||
mEntryInfo = EntryInfo()
|
||||
|
||||
@@ -429,11 +429,12 @@ abstract class TemplateAbstractView<
|
||||
mEntryInfo?.notes = it
|
||||
}
|
||||
|
||||
retrieveCustomFieldsFromView(templateFieldNotEmpty)
|
||||
retrieveCustomFieldsFromView(templateFieldNotEmpty, retrieveDefaultValues)
|
||||
}
|
||||
|
||||
fun getEntryInfo(): EntryInfo {
|
||||
populateEntryInfoWithViews(true)
|
||||
populateEntryInfoWithViews(templateFieldNotEmpty = true,
|
||||
retrieveDefaultValues = true)
|
||||
return mEntryInfo ?: EntryInfo()
|
||||
}
|
||||
|
||||
@@ -479,23 +480,31 @@ abstract class TemplateAbstractView<
|
||||
return mViewFields.indexOfFirst { it.field.name.equals(name, true) }
|
||||
}
|
||||
|
||||
private fun retrieveCustomFieldsFromView(templateFieldNotEmpty: Boolean = false) {
|
||||
private fun retrieveCustomFieldsFromView(templateFieldNotEmpty: Boolean = false,
|
||||
retrieveDefaultValues: Boolean = false) {
|
||||
mEntryInfo?.customFields = mViewFields.mapNotNull {
|
||||
getCustomField(it.field.name, templateFieldNotEmpty)
|
||||
getCustomField(it.field.name, templateFieldNotEmpty, retrieveDefaultValues)
|
||||
}.toMutableList()
|
||||
}
|
||||
|
||||
protected fun getCustomField(fieldName: String): Field {
|
||||
return getCustomField(fieldName, false)
|
||||
?: Field(fieldName, ProtectedString(false))
|
||||
return getCustomField(fieldName,
|
||||
templateFieldNotEmpty = false,
|
||||
retrieveDefaultValues = false
|
||||
) ?: Field(fieldName, ProtectedString(false))
|
||||
}
|
||||
|
||||
private fun getCustomField(fieldName: String, templateFieldNotEmpty: Boolean): Field? {
|
||||
private fun getCustomField(fieldName: String,
|
||||
templateFieldNotEmpty: Boolean,
|
||||
retrieveDefaultValues: Boolean): Field? {
|
||||
getViewFieldByName(fieldName)?.let { fieldId ->
|
||||
val editView: View? = fieldId.view
|
||||
val editView: View = fieldId.view
|
||||
if (editView is GenericFieldView) {
|
||||
// Do not return field with a default value
|
||||
val defaultViewValue = if (editView.value == editView.default) "" else editView.value
|
||||
val defaultViewValue =
|
||||
if (retrieveDefaultValues || editView.value != editView.default) {
|
||||
editView.value
|
||||
} else ""
|
||||
if (!templateFieldNotEmpty
|
||||
|| (editView.tag == FIELD_CUSTOM_TAG && defaultViewValue.isNotEmpty())) {
|
||||
return Field(
|
||||
@@ -641,7 +650,8 @@ abstract class TemplateAbstractView<
|
||||
override fun onSaveInstanceState(): Parcelable {
|
||||
val superSave = super.onSaveInstanceState()
|
||||
val saveState = SavedState(superSave)
|
||||
populateEntryInfoWithViews(false)
|
||||
populateEntryInfoWithViews(templateFieldNotEmpty = false,
|
||||
retrieveDefaultValues = false)
|
||||
saveState.template = this.mTemplate
|
||||
saveState.entryInfo = this.mEntryInfo
|
||||
onSaveEntryInstanceState(saveState)
|
||||
|
||||
@@ -64,6 +64,7 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
|
||||
TextEditFieldView(it).apply {
|
||||
// hiddenProtectedValue (mHideProtectedValue) don't work with TextInputLayout
|
||||
setProtection(field.protectedValue.isProtected)
|
||||
default = templateAttribute.default
|
||||
setMaxChars(templateAttribute.options.getNumberChars())
|
||||
setMaxLines(templateAttribute.options.getNumberLines())
|
||||
setActionClick(templateAttribute, field, this)
|
||||
@@ -79,7 +80,7 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
|
||||
return context?.let {
|
||||
TextSelectFieldView(it).apply {
|
||||
setItems(templateAttribute.options.getListItems())
|
||||
default = field.protectedValue.stringValue
|
||||
default = templateAttribute.default
|
||||
setActionClick(templateAttribute, field, this)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_NO
|
||||
@@ -198,8 +199,9 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
|
||||
return super.populateViewsWithEntryInfo(showEmptyFields)
|
||||
}
|
||||
|
||||
override fun populateEntryInfoWithViews(templateFieldNotEmpty: Boolean) {
|
||||
super.populateEntryInfoWithViews(templateFieldNotEmpty)
|
||||
override fun populateEntryInfoWithViews(templateFieldNotEmpty: Boolean,
|
||||
retrieveDefaultValues: Boolean) {
|
||||
super.populateEntryInfoWithViews(templateFieldNotEmpty, retrieveDefaultValues)
|
||||
mEntryInfo?.otpModel = OtpEntryFields.parseFields { key ->
|
||||
getCustomField(key).protectedValue.toString()
|
||||
}?.otpModel
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
* Change default Argon2 parameters #1098
|
||||
* Add & edit custom icon name #976
|
||||
* Add & edit custom icon name #976
|
||||
* Fix templates #1128
|
||||
@@ -1,2 +1,3 @@
|
||||
* Changement des paramètres Argon2 par défaut #1098
|
||||
* Ajout & édition du nom d'icone customisé #976
|
||||
* Ajout & édition du nom d'icone customisé #976
|
||||
* Correction des gabarits #1128
|
||||
Reference in New Issue
Block a user