diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 35106e176..b3d02212b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -124,8 +124,7 @@
android:configChanges="keyboardHidden" />
+ android:windowSoftInputMode="adjustResize" />
entryCustomFieldListener?.onNewCustomFieldCanceled(
- newFieldLabel?.text.toString(),
- ProtectedString(
- newFieldProtection?.isChecked == true,
- newFieldValue?.text.toString()
- )
+ newFieldLabel?.text.toString()
)
}
+ val dialogCreated = builder.create()
+
+ newFieldLabel?.requestFocus()
+ newFieldLabel?.imeOptions = EditorInfo.IME_ACTION_DONE
+ newFieldLabel?.setOnEditorActionListener { _, actionId, _ ->
+ if (actionId == EditorInfo.IME_ACTION_DONE) {
+ approveIfValid()
+ }
+ false
+ }
+
+ dialogCreated.window?.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE)
+ return dialogCreated
- return builder.create()
}
return super.onCreateDialog(savedInstanceState)
}
@@ -86,20 +91,20 @@ class EntryCustomFieldDialogFragment: DialogFragment() {
if (d != null) {
val positiveButton = d.getButton(Dialog.BUTTON_POSITIVE) as Button
positiveButton.setOnClickListener {
- if (isValid()) {
- entryCustomFieldListener?.onNewCustomFieldApproved(
- newFieldLabel?.text.toString(),
- ProtectedString(
- newFieldProtection?.isChecked == true,
- newFieldValue?.text.toString()
- )
- )
- d.dismiss()
- }
+ approveIfValid()
}
}
}
+ private fun approveIfValid() {
+ if (isValid()) {
+ entryCustomFieldListener?.onNewCustomFieldApproved(
+ newFieldLabel?.text.toString()
+ )
+ (dialog as AlertDialog?)?.dismiss()
+ }
+ }
+
private fun isValid(): Boolean {
return if (newFieldLabel?.text?.toString()?.isNotEmpty() != true) {
setError(R.string.error_string_key)
@@ -117,8 +122,8 @@ class EntryCustomFieldDialogFragment: DialogFragment() {
}
interface EntryCustomFieldListener {
- fun onNewCustomFieldApproved(label: String, name: ProtectedString)
- fun onNewCustomFieldCanceled(label: String, name: ProtectedString)
+ fun onNewCustomFieldApproved(label: String)
+ fun onNewCustomFieldCanceled(label: String)
}
companion object {
diff --git a/app/src/main/java/com/kunzisoft/keepass/view/EntryEditContentsView.kt b/app/src/main/java/com/kunzisoft/keepass/view/EntryEditContentsView.kt
index bef904bb6..f55d2a07b 100644
--- a/app/src/main/java/com/kunzisoft/keepass/view/EntryEditContentsView.kt
+++ b/app/src/main/java/com/kunzisoft/keepass/view/EntryEditContentsView.kt
@@ -215,35 +215,36 @@ class EntryEditContentsView @JvmOverloads constructor(context: Context,
return customFieldsArray
}
- /**
- * Update a custom field or create a new one if doesn't exists
- */
- fun putCustomField(name: String,
- value: ProtectedString = ProtectedString()) {
- var updateField = false
+ private fun getCustomFieldByLabel(label: String): EntryEditCustomField? {
for (i in 0..entryExtraFieldsContainer.childCount) {
try {
val extraFieldView = entryExtraFieldsContainer.getChildAt(i) as EntryEditCustomField?
- if (extraFieldView?.label == name) {
- extraFieldView.setData(name, value, fontInVisibility)
- updateField = true
- break
+ if (extraFieldView?.label == label) {
+ return extraFieldView
}
} catch(e: Exception) {
// Simply ignore when child view is not a custom field
}
}
- if (!updateField) {
- val entryEditCustomField = EntryEditCustomField(context).apply {
- setData(name, value, fontInVisibility)
- }
- entryExtraFieldsContainer.addView(entryEditCustomField)
- }
+ return null
}
- fun focusLastChild() {
- val lastChildNumber = entryExtraFieldsContainer.childCount - 1
- entryExtraFieldsContainer.getChildAt(lastChildNumber).requestFocus()
+ /**
+ * Update a custom field or create a new one if doesn't exists
+ */
+ fun putCustomField(name: String,
+ value: ProtectedString = ProtectedString())
+ : EntryEditCustomField {
+ var extraFieldView = getCustomFieldByLabel(name)
+ extraFieldView?.setData(name, value, fontInVisibility)
+ // Create new view if not exists
+ if (extraFieldView == null) {
+ extraFieldView = EntryEditCustomField(context).apply {
+ setData(name, value, fontInVisibility)
+ }
+ entryExtraFieldsContainer.addView(extraFieldView)
+ }
+ return extraFieldView
}
/**
diff --git a/app/src/main/res/layout/fragment_entry_new_field.xml b/app/src/main/res/layout/fragment_entry_new_field.xml
index 5e78ccd1e..f877c5b9f 100644
--- a/app/src/main/res/layout/fragment_entry_new_field.xml
+++ b/app/src/main/res/layout/fragment_entry_new_field.xml
@@ -18,63 +18,27 @@
along with KeePassDX. If not, see .
-->
-
+ android:paddingTop="@dimen/default_margin"
+ android:paddingLeft="@dimen/default_margin"
+ android:paddingStart="@dimen/default_margin"
+ android:paddingRight="@dimen/default_margin"
+ android:paddingEnd="@dimen/default_margin"
+ tools:ignore="UnusedAttribute">
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+ android:hint="@string/field_name"
+ android:importantForAccessibility="no"
+ android:importantForAutofill="no"
+ android:inputType="text"
+ android:maxLines="1" />
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/view_entry_custom_field.xml b/app/src/main/res/layout/view_entry_custom_field.xml
index d6a4e79ff..ef668bbb8 100644
--- a/app/src/main/res/layout/view_entry_custom_field.xml
+++ b/app/src/main/res/layout/view_entry_custom_field.xml
@@ -75,13 +75,13 @@
style="@style/KeepassDXStyle.TextAppearance.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:minHeight="48dp"
- android:layout_marginTop="@dimen/default_margin"
+ android:minHeight="24dp"
android:layout_marginStart="@dimen/default_margin"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginEnd="@dimen/default_margin"
android:layout_marginRight="@dimen/default_margin"
- app:layout_constraintTop_toBottomOf="@+id/entry_new_field_delete"
+ android:paddingBottom="@dimen/default_margin"
+ app:layout_constraintTop_toBottomOf="@+id/new_field_value_container"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="@string/protection" />