mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix not referenced fields
This commit is contained in:
@@ -28,6 +28,7 @@ import com.kunzisoft.keepass.database.element.icon.IconImageStandard.Companion.B
|
|||||||
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_EXPIRATION
|
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_EXPIRATION
|
||||||
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_NOTES
|
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_NOTES
|
||||||
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_PASSWORD
|
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_PASSWORD
|
||||||
|
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_TITLE
|
||||||
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_URL
|
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_URL
|
||||||
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_USERNAME
|
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_USERNAME
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -114,20 +115,26 @@ class Template : Parcelable {
|
|||||||
return arrayOfNulls(size)
|
return arrayOfNulls(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val TITLE_ATTRIBUTE = TemplateAttribute(LABEL_TITLE, TemplateAttributeType.INLINE)
|
||||||
|
val USERNAME_ATTRIBUTE = TemplateAttribute(LABEL_USERNAME, TemplateAttributeType.INLINE)
|
||||||
|
val PASSWORD_ATTRIBUTE = TemplateAttribute(LABEL_PASSWORD,
|
||||||
|
TemplateAttributeType.SMALL_MULTILINE,
|
||||||
|
true,
|
||||||
|
"",
|
||||||
|
TemplateAttributeAction.PASSWORD_GENERATION)
|
||||||
|
val URL_ATTRIBUTE = TemplateAttribute(LABEL_URL, TemplateAttributeType.INLINE)
|
||||||
|
val EXPIRATION_ATTRIBUTE = TemplateAttribute(LABEL_EXPIRATION, TemplateAttributeType.DATETIME)
|
||||||
|
val NOTES_ATTRIBUTE = TemplateAttribute(LABEL_NOTES, TemplateAttributeType.MULTILINE)
|
||||||
|
|
||||||
val STANDARD: Template
|
val STANDARD: Template
|
||||||
get() {
|
get() {
|
||||||
val sections = ArrayList<TemplateSection>()
|
val sections = ArrayList<TemplateSection>()
|
||||||
val mainSection = TemplateSection(ArrayList<TemplateAttribute>().apply {
|
val mainSection = TemplateSection(ArrayList<TemplateAttribute>().apply {
|
||||||
add(TemplateAttribute(LABEL_USERNAME, TemplateAttributeType.INLINE))
|
add(USERNAME_ATTRIBUTE)
|
||||||
add(TemplateAttribute(LABEL_PASSWORD,
|
add(PASSWORD_ATTRIBUTE)
|
||||||
TemplateAttributeType.SMALL_MULTILINE,
|
add(URL_ATTRIBUTE)
|
||||||
true,
|
add(EXPIRATION_ATTRIBUTE)
|
||||||
"",
|
add(NOTES_ATTRIBUTE)
|
||||||
TemplateAttributeAction.PASSWORD_GENERATION)
|
|
||||||
)
|
|
||||||
add(TemplateAttribute(LABEL_URL, TemplateAttributeType.INLINE))
|
|
||||||
add(TemplateAttribute(LABEL_EXPIRATION, TemplateAttributeType.DATETIME))
|
|
||||||
add(TemplateAttribute(LABEL_NOTES, TemplateAttributeType.MULTILINE))
|
|
||||||
})
|
})
|
||||||
sections.add(mainSection)
|
sections.add(mainSection)
|
||||||
return Template(DatabaseVersioned.UUID_ZERO,
|
return Template(DatabaseVersioned.UUID_ZERO,
|
||||||
|
|||||||
@@ -168,14 +168,12 @@ abstract class TemplateAbstractView<TEntryFieldView: GenericEntryFieldView, TDat
|
|||||||
|
|
||||||
abstract fun preProcessTemplate()
|
abstract fun preProcessTemplate()
|
||||||
|
|
||||||
private fun buildViewForNotReferencedField(field: Field, attributeType: TemplateAttributeType): View? {
|
/**
|
||||||
val standardFieldTemplateAttribute = TemplateAttribute(
|
* Not referenced fields are standard fields with content but not in template
|
||||||
field.name,
|
*/
|
||||||
attributeType,
|
private fun buildViewForNotReferencedField(field: Field, templateAttribute: TemplateAttribute): View? {
|
||||||
field.protectedValue.isProtected,
|
val fieldTag: String = getTagFromStandardTemplateAttribute(templateAttribute)
|
||||||
field.protectedValue.stringValue)
|
return buildViewForTemplateField(templateAttribute, field, fieldTag)
|
||||||
val fieldTag: String = getTagFromStandardTemplateAttribute(standardFieldTemplateAttribute)
|
|
||||||
return buildViewForTemplateField(standardFieldTemplateAttribute, field, fieldTag)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildViewForCustomField(field: Field): View? {
|
private fun buildViewForCustomField(field: Field): View? {
|
||||||
@@ -241,8 +239,7 @@ abstract class TemplateAbstractView<TEntryFieldView: GenericEntryFieldView, TDat
|
|||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
private fun populateEntryFieldView(fieldTag: String,
|
private fun populateEntryFieldView(fieldTag: String,
|
||||||
label: String,
|
templateAttribute: TemplateAttribute,
|
||||||
type: TemplateAttributeType,
|
|
||||||
entryInfoValue: String,
|
entryInfoValue: String,
|
||||||
showEmptyFields: Boolean) {
|
showEmptyFields: Boolean) {
|
||||||
var fieldView: TEntryFieldView? = findViewWithTag(fieldTag)
|
var fieldView: TEntryFieldView? = findViewWithTag(fieldTag)
|
||||||
@@ -251,8 +248,9 @@ abstract class TemplateAbstractView<TEntryFieldView: GenericEntryFieldView, TDat
|
|||||||
} else if (fieldView == null && entryInfoValue.isNotEmpty()) {
|
} else if (fieldView == null && entryInfoValue.isNotEmpty()) {
|
||||||
// Add new not referenced view if standard field not in template
|
// Add new not referenced view if standard field not in template
|
||||||
fieldView = buildViewForNotReferencedField(
|
fieldView = buildViewForNotReferencedField(
|
||||||
Field(label, ProtectedString(false, entryInfoValue)),
|
Field(templateAttribute.label,
|
||||||
type
|
ProtectedString(templateAttribute.protected, "")),
|
||||||
|
templateAttribute
|
||||||
) as? TEntryFieldView?
|
) as? TEntryFieldView?
|
||||||
fieldView?.let {
|
fieldView?.let {
|
||||||
addNotReferencedView(it as View)
|
addNotReferencedView(it as View)
|
||||||
@@ -264,8 +262,7 @@ abstract class TemplateAbstractView<TEntryFieldView: GenericEntryFieldView, TDat
|
|||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
private fun populateDateTimeView(fieldTag: String,
|
private fun populateDateTimeView(fieldTag: String,
|
||||||
label: String,
|
templateAttribute: TemplateAttribute,
|
||||||
type: TemplateAttributeType,
|
|
||||||
expires: Boolean,
|
expires: Boolean,
|
||||||
expiryTime: DateInstant,
|
expiryTime: DateInstant,
|
||||||
showEmptyFields: Boolean) {
|
showEmptyFields: Boolean) {
|
||||||
@@ -275,8 +272,9 @@ abstract class TemplateAbstractView<TEntryFieldView: GenericEntryFieldView, TDat
|
|||||||
fieldView?.isFieldVisible = false
|
fieldView?.isFieldVisible = false
|
||||||
} else if (fieldView == null && expires) {
|
} else if (fieldView == null && expires) {
|
||||||
fieldView = buildViewForNotReferencedField(
|
fieldView = buildViewForNotReferencedField(
|
||||||
Field(label, ProtectedString(false, "")),
|
Field(templateAttribute.label,
|
||||||
type
|
ProtectedString(templateAttribute.protected, "")),
|
||||||
|
templateAttribute
|
||||||
) as? TDateTimeView?
|
) as? TDateTimeView?
|
||||||
fieldView?.let {
|
fieldView?.let {
|
||||||
addNotReferencedView(it as View)
|
addNotReferencedView(it as View)
|
||||||
@@ -293,34 +291,28 @@ abstract class TemplateAbstractView<TEntryFieldView: GenericEntryFieldView, TDat
|
|||||||
mEntryInfo?.let { entryInfo ->
|
mEntryInfo?.let { entryInfo ->
|
||||||
|
|
||||||
populateEntryFieldView(FIELD_TITLE_TAG,
|
populateEntryFieldView(FIELD_TITLE_TAG,
|
||||||
TemplateField.LABEL_TITLE,
|
Template.TITLE_ATTRIBUTE,
|
||||||
TemplateAttributeType.INLINE,
|
|
||||||
entryInfo.title,
|
entryInfo.title,
|
||||||
showEmptyFields)
|
showEmptyFields)
|
||||||
populateEntryFieldView(FIELD_USERNAME_TAG,
|
populateEntryFieldView(FIELD_USERNAME_TAG,
|
||||||
TemplateField.LABEL_USERNAME,
|
Template.USERNAME_ATTRIBUTE,
|
||||||
TemplateAttributeType.INLINE,
|
|
||||||
entryInfo.username,
|
entryInfo.username,
|
||||||
showEmptyFields)
|
showEmptyFields)
|
||||||
populateEntryFieldView(FIELD_PASSWORD_TAG,
|
populateEntryFieldView(FIELD_PASSWORD_TAG,
|
||||||
TemplateField.LABEL_PASSWORD,
|
Template.PASSWORD_ATTRIBUTE,
|
||||||
TemplateAttributeType.INLINE,
|
|
||||||
entryInfo.password,
|
entryInfo.password,
|
||||||
showEmptyFields)
|
showEmptyFields)
|
||||||
populateEntryFieldView(FIELD_URL_TAG,
|
populateEntryFieldView(FIELD_URL_TAG,
|
||||||
TemplateField.LABEL_URL,
|
Template.URL_ATTRIBUTE,
|
||||||
TemplateAttributeType.INLINE,
|
|
||||||
entryInfo.url,
|
entryInfo.url,
|
||||||
showEmptyFields)
|
showEmptyFields)
|
||||||
populateDateTimeView(FIELD_EXPIRES_TAG,
|
populateDateTimeView(FIELD_EXPIRES_TAG,
|
||||||
TemplateField.LABEL_EXPIRATION,
|
Template.EXPIRATION_ATTRIBUTE,
|
||||||
TemplateAttributeType.DATETIME,
|
|
||||||
entryInfo.expires,
|
entryInfo.expires,
|
||||||
entryInfo.expiryTime,
|
entryInfo.expiryTime,
|
||||||
showEmptyFields)
|
showEmptyFields)
|
||||||
populateEntryFieldView(FIELD_NOTES_TAG,
|
populateEntryFieldView(FIELD_NOTES_TAG,
|
||||||
TemplateField.LABEL_NOTES,
|
Template.NOTES_ATTRIBUTE,
|
||||||
TemplateAttributeType.MULTILINE,
|
|
||||||
entryInfo.notes,
|
entryInfo.notes,
|
||||||
showEmptyFields)
|
showEmptyFields)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user