mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-04 07:42:30 -08:00
First pass to prepare templates
This commit is contained in:
1 parent
c669d5657a
commit
c0d4ad2042
16 files changed
+74
-145
No files matched your search
@@ -49,7 +49,7 @@ import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.education.EntryActivityEducation
|
||||
import com.kunzisoft.keepass.magikeyboard.MagikIME
|
||||
import com.kunzisoft.keepass.model.CreditCardCustomFields
|
||||
import com.kunzisoft.keepass.model.TemplatesCustomFields
|
||||
import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.model.StreamDirection
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
@@ -323,7 +323,6 @@ class EntryActivity : LockingActivity() {
|
||||
// Assign custom fields
|
||||
if (mDatabase?.allowEntryCustomFields() == true) {
|
||||
entryContentsView?.clearExtraFields()
|
||||
entryContentsView?.clearCreditCardFields()
|
||||
entryInfo.customFields.forEach { field ->
|
||||
val label = field.name
|
||||
// OTP field is already managed in dedicated view
|
||||
@@ -334,7 +333,8 @@ class EntryActivity : LockingActivity() {
|
||||
entryContentsView?.addExtraField(label, value, allowCopyProtectedField) {
|
||||
clipboardHelper?.timeoutCopyToClipboard(
|
||||
value.toString(),
|
||||
getString(R.string.copy_field, CreditCardCustomFields.getLocalizedName(applicationContext, field.name))
|
||||
getString(R.string.copy_field,
|
||||
TemplatesCustomFields.getLocalizedName(applicationContext, field.name))
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -412,15 +412,15 @@ class EntryEditActivity : LockingActivity(),
|
||||
var expiration: String? = null
|
||||
var cvv: String? = null
|
||||
|
||||
entryEditFragment?.getExtraFields()?.forEach() { field ->
|
||||
entryEditFragment?.getExtraFields()?.forEach { field ->
|
||||
when (field.name) {
|
||||
CreditCardCustomFields.CC_CARDHOLDER_FIELD_NAME ->
|
||||
TemplatesCustomFields.CC_CARDHOLDER_FIELD_NAME ->
|
||||
cardholder = field.protectedValue.stringValue
|
||||
CreditCardCustomFields.CC_NUMBER_FIELD_NAME ->
|
||||
TemplatesCustomFields.CC_NUMBER_FIELD_NAME ->
|
||||
number = field.protectedValue.stringValue
|
||||
CreditCardCustomFields.CC_EXP_FIELD_NAME ->
|
||||
TemplatesCustomFields.CC_EXP_FIELD_NAME ->
|
||||
expiration = field.protectedValue.stringValue
|
||||
CreditCardCustomFields.CC_CVV_FIELD_NAME ->
|
||||
TemplatesCustomFields.CC_CVV_FIELD_NAME ->
|
||||
cvv = field.protectedValue.stringValue
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.model.CreditCard
|
||||
import com.kunzisoft.keepass.model.CreditCardCustomFields.buildAllFields
|
||||
import com.kunzisoft.keepass.model.TemplatesCustomFields.buildAllFields
|
||||
import com.kunzisoft.keepass.model.Field
|
||||
import java.util.*
|
||||
|
||||
@@ -140,7 +140,7 @@ class CreditCardDetailsDialogFragment : DialogFragment() {
|
||||
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
|
||||
builder.setView(root).setTitle(R.string.entry_setup_cc)
|
||||
builder.setView(root).setTitle(R.string.entry_setup_credit_card)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.setNegativeButton(android.R.string.cancel) { _, _ -> }
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.education.EntryEditActivityEducation
|
||||
import com.kunzisoft.keepass.icons.IconDrawableFactory
|
||||
import com.kunzisoft.keepass.model.*
|
||||
import com.kunzisoft.keepass.model.CreditCardCustomFields
|
||||
import com.kunzisoft.keepass.model.TemplatesCustomFields
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.view.ExpirationView
|
||||
@@ -319,15 +319,7 @@ class EntryEditFragment : StylishFragment() {
|
||||
val extraFieldValueContainer: TextInputLayout? = itemView?.findViewById(R.id.entry_extra_field_value_container)
|
||||
extraFieldValueContainer?.endIconMode = if (extraField.protectedValue.isProtected)
|
||||
TextInputLayout.END_ICON_PASSWORD_TOGGLE else TextInputLayout.END_ICON_NONE
|
||||
|
||||
when (extraField.name) {
|
||||
CreditCardCustomFields.CC_CARDHOLDER_FIELD_NAME -> extraFieldValueContainer?.hint = context?.getString(R.string.cc_cardholder)
|
||||
CreditCardCustomFields.CC_EXP_FIELD_NAME -> extraFieldValueContainer?.hint = context?.getString(R.string.cc_expiration)
|
||||
CreditCardCustomFields.CC_NUMBER_FIELD_NAME -> extraFieldValueContainer?.hint = context?.getString(R.string.cc_number)
|
||||
CreditCardCustomFields.CC_CVV_FIELD_NAME -> extraFieldValueContainer?.hint = context?.getString(R.string.cc_security_code)
|
||||
else -> extraFieldValueContainer?.hint = extraField.name
|
||||
}
|
||||
|
||||
extraFieldValueContainer?.hint = TemplatesCustomFields.getLocalizedName(context, extraField.name)
|
||||
extraFieldValueContainer?.id = View.NO_ID
|
||||
|
||||
val extraFieldValue: TextInputEditText? = itemView?.findViewById(R.id.entry_extra_field_value)
|
||||
|
||||
@@ -48,7 +48,7 @@ import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.model.SearchInfo
|
||||
import com.kunzisoft.keepass.model.CreditCardCustomFields
|
||||
import com.kunzisoft.keepass.model.TemplatesCustomFields
|
||||
import com.kunzisoft.keepass.settings.AutofillSettingsActivity
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import java.util.*
|
||||
@@ -122,17 +122,17 @@ object AutofillHelper {
|
||||
}
|
||||
|
||||
for (field in entryInfo.customFields) {
|
||||
if (field.name == CreditCardCustomFields.CC_CARDHOLDER_FIELD_NAME) {
|
||||
if (field.name == TemplatesCustomFields.CC_CARDHOLDER_FIELD_NAME) {
|
||||
struct.ccNameId?.let { ccNameId ->
|
||||
builder.setValue(ccNameId, AutofillValue.forText(field.protectedValue.stringValue))
|
||||
}
|
||||
}
|
||||
if (field.name == CreditCardCustomFields.CC_NUMBER_FIELD_NAME) {
|
||||
if (field.name == TemplatesCustomFields.CC_NUMBER_FIELD_NAME) {
|
||||
struct.ccnId?.let { ccnId ->
|
||||
builder.setValue(ccnId, AutofillValue.forText(field.protectedValue.stringValue))
|
||||
}
|
||||
}
|
||||
if (field.name == CreditCardCustomFields.CC_EXP_FIELD_NAME) {
|
||||
if (field.name == TemplatesCustomFields.CC_EXP_FIELD_NAME) {
|
||||
// the database stores the expiration month and year as a String
|
||||
// of length four in the format MMYY
|
||||
if (field.protectedValue.stringValue.length != 4) continue
|
||||
@@ -194,7 +194,7 @@ object AutofillHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (field.name == CreditCardCustomFields.CC_CVV_FIELD_NAME) {
|
||||
if (field.name == TemplatesCustomFields.CC_CVV_FIELD_NAME) {
|
||||
struct.cvvId?.let { cvvId ->
|
||||
builder.setValue(cvvId, AutofillValue.forText(field.protectedValue.stringValue))
|
||||
}
|
||||
@@ -309,7 +309,7 @@ object AutofillHelper {
|
||||
|
||||
return try {
|
||||
responseBuilder.build()
|
||||
} catch (e: java.lang.Exception) {
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,19 +142,20 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
Log.d(TAG, "Autofill password hint")
|
||||
return true
|
||||
}
|
||||
it == "cc-name" -> {
|
||||
Log.d(TAG, "AUTOFILL cc-name hint")
|
||||
it.contains("cc-name", true) -> {
|
||||
Log.d(TAG, "Autofill credit card name hint")
|
||||
result?.ccNameId = autofillId
|
||||
result?.ccName = node.autofillValue?.textValue?.toString()
|
||||
}
|
||||
it == View.AUTOFILL_HINT_CREDIT_CARD_NUMBER || it == "cc-number" -> {
|
||||
Log.d(TAG, "AUTOFILL_HINT_CREDIT_CARD_NUMBER hint")
|
||||
it.contains(View.AUTOFILL_HINT_CREDIT_CARD_NUMBER, true)
|
||||
|| it.contains("cc-number", true) -> {
|
||||
Log.d(TAG, "Autofill credit card number hint")
|
||||
result?.ccnId = autofillId
|
||||
result?.ccNumber = node.autofillValue?.textValue?.toString()
|
||||
}
|
||||
// expect date string as defined in https://html.spec.whatwg.org, e.g. 2014-12
|
||||
it == "cc-exp" -> {
|
||||
Log.d(TAG, "AUTOFILL cc-exp hint")
|
||||
it.contains("cc-exp", true) -> {
|
||||
Log.d(TAG, "Autofill credit card expiration date hint")
|
||||
result?.ccExpDateId = autofillId
|
||||
node.autofillValue?.let { value ->
|
||||
if (value.isText && value.textValue.length == 7) {
|
||||
@@ -164,8 +165,8 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
}
|
||||
}
|
||||
}
|
||||
it == View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE -> {
|
||||
Log.d(TAG, "AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE hint")
|
||||
it.contains(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE, true) -> {
|
||||
Log.d(TAG, "Autofill credit card expiration date hint")
|
||||
result?.ccExpDateId = autofillId
|
||||
node.autofillValue?.let { value ->
|
||||
if (value.isDate) {
|
||||
@@ -178,8 +179,9 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
}
|
||||
}
|
||||
}
|
||||
it == View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR || it == "cc-exp-year" -> {
|
||||
Log.d(TAG, "AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR hint")
|
||||
it.contains(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR, true)
|
||||
|| it.contains("cc-exp-year", true) -> {
|
||||
Log.d(TAG, "Autofill credit card expiration year hint")
|
||||
result?.ccExpDateYearId = autofillId
|
||||
if (node.autofillOptions != null) {
|
||||
result?.ccExpYearOptions = node.autofillOptions
|
||||
@@ -199,7 +201,8 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
result?.ccExpDateYearValue = year % 100
|
||||
}
|
||||
}
|
||||
it == View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH || it == "cc-exp-month" -> {
|
||||
it.contains(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH, true)
|
||||
|| it.contains("cc-exp-month", true) -> {
|
||||
Log.d(TAG, "AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH hint")
|
||||
result?.ccExpDateMonthId = autofillId
|
||||
if (node.autofillOptions != null) {
|
||||
@@ -208,10 +211,10 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
node.autofillValue?.let { value ->
|
||||
var month = 0
|
||||
if (value.isText) {
|
||||
try {
|
||||
month = value.textValue.toString().toInt()
|
||||
month = try {
|
||||
value.textValue.toString().toInt()
|
||||
} catch (e: Exception) {
|
||||
month = 0
|
||||
0
|
||||
}
|
||||
}
|
||||
if (value.isList) {
|
||||
@@ -221,7 +224,8 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
result?.ccExpDateMonthValue = month
|
||||
}
|
||||
}
|
||||
it == View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE || it == "cc-csc" -> {
|
||||
it.contains(View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE, true)
|
||||
|| it.contains("cc-csc", true) -> {
|
||||
Log.d(TAG, "AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE hint")
|
||||
result?.cvvId = autofillId
|
||||
result?.cvv = node.autofillValue?.textValue?.toString()
|
||||
|
||||
@@ -166,19 +166,19 @@ class EntryInfo : NodeInfo {
|
||||
creditCard?.let { cc ->
|
||||
cc.cardholder?.let {
|
||||
val v = ProtectedString(false, it)
|
||||
addUniqueField(Field(CreditCardCustomFields.CC_CARDHOLDER_FIELD_NAME, v))
|
||||
addUniqueField(Field(TemplatesCustomFields.CC_CARDHOLDER_FIELD_NAME, v))
|
||||
}
|
||||
cc.expiration?.let {
|
||||
val v = ProtectedString(false, it)
|
||||
addUniqueField(Field(CreditCardCustomFields.CC_EXP_FIELD_NAME, v))
|
||||
addUniqueField(Field(TemplatesCustomFields.CC_EXP_FIELD_NAME, v))
|
||||
}
|
||||
cc.number?.let {
|
||||
val v = ProtectedString(false, it)
|
||||
addUniqueField(Field(CreditCardCustomFields.CC_NUMBER_FIELD_NAME, v))
|
||||
addUniqueField(Field(TemplatesCustomFields.CC_NUMBER_FIELD_NAME, v))
|
||||
}
|
||||
cc.cvv?.let {
|
||||
val v = ProtectedString(true, it)
|
||||
addUniqueField(Field(CreditCardCustomFields.CC_CVV_FIELD_NAME, v))
|
||||
addUniqueField(Field(TemplatesCustomFields.CC_CVV_FIELD_NAME, v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-6
@@ -4,7 +4,7 @@ import android.content.Context
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
|
||||
object CreditCardCustomFields {
|
||||
object TemplatesCustomFields {
|
||||
const val CC_CARDHOLDER_FIELD_NAME = "CREDIT_CARD_CARDHOLDER"
|
||||
const val CC_NUMBER_FIELD_NAME = "CREDIT_CARD_NUMBER"
|
||||
const val CC_EXP_FIELD_NAME = "CREDIT_CARD_EXPIRATION"
|
||||
@@ -13,12 +13,14 @@ object CreditCardCustomFields {
|
||||
val CC_CUSTOM_FIELDS = arrayOf(CC_CARDHOLDER_FIELD_NAME, CC_NUMBER_FIELD_NAME,
|
||||
CC_EXP_FIELD_NAME, CC_CVV_FIELD_NAME)
|
||||
|
||||
fun getLocalizedName(context: Context, fieldName: String): String {
|
||||
fun getLocalizedName(context: Context?, fieldName: String): String {
|
||||
if (context == null)
|
||||
return fieldName
|
||||
return when (fieldName) {
|
||||
CC_CARDHOLDER_FIELD_NAME -> context.getString(R.string.cc_cardholder)
|
||||
CC_NUMBER_FIELD_NAME -> context.getString(R.string.cc_number)
|
||||
CC_EXP_FIELD_NAME -> context.getString(R.string.cc_expiration)
|
||||
CC_CVV_FIELD_NAME -> context.getString(R.string.cc_security_code)
|
||||
CC_CARDHOLDER_FIELD_NAME -> context.getString(R.string.credit_card_cardholder)
|
||||
CC_NUMBER_FIELD_NAME -> context.getString(R.string.credit_card_number)
|
||||
CC_EXP_FIELD_NAME -> context.getString(R.string.credit_card_expiration)
|
||||
CC_CVV_FIELD_NAME -> context.getString(R.string.credit_card_security_code)
|
||||
else -> fieldName
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.utils.UuidUtil
|
||||
import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.model.StreamDirection
|
||||
import com.kunzisoft.keepass.model.CreditCardCustomFields
|
||||
import com.kunzisoft.keepass.model.TemplatesCustomFields
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpType
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
@@ -69,9 +69,6 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
|
||||
private val extraFieldsContainerView: View
|
||||
private val extraFieldsListView: ViewGroup
|
||||
|
||||
private val creditCardContainerView: View
|
||||
private val creditCardFieldsListView: ViewGroup
|
||||
|
||||
private val creationDateView: TextView
|
||||
private val modificationDateView: TextView
|
||||
private val expiresImageView: ImageView
|
||||
@@ -116,9 +113,6 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
|
||||
extraFieldsContainerView = findViewById(R.id.extra_fields_container)
|
||||
extraFieldsListView = findViewById(R.id.extra_fields_list)
|
||||
|
||||
creditCardContainerView = findViewById(R.id.credit_card_container)
|
||||
creditCardFieldsListView = findViewById(R.id.credit_card_fields_list)
|
||||
|
||||
attachmentsContainerView = findViewById(R.id.entry_attachments_container)
|
||||
attachmentsListView = findViewById(R.id.entry_attachments_list)
|
||||
attachmentsListView?.apply {
|
||||
@@ -313,69 +307,28 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
|
||||
extraFieldsContainerView.visibility = if (hide) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
private fun showOrHideCreditCardContainer(hide: Boolean) {
|
||||
creditCardContainerView.visibility = if (hide) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
fun addExtraField(title: String,
|
||||
value: ProtectedString,
|
||||
allowCopy: Boolean,
|
||||
onCopyButtonClickListener: OnClickListener?) {
|
||||
|
||||
if (title in CreditCardCustomFields.CC_CUSTOM_FIELDS) {
|
||||
return addExtraCCField(title, value, allowCopy, onCopyButtonClickListener)
|
||||
}
|
||||
|
||||
val entryCustomField: EntryField? = EntryField(context)
|
||||
entryCustomField?.apply {
|
||||
setLabel(title)
|
||||
extraFieldsListView.addView(EntryField(context).apply {
|
||||
setLabel(TemplatesCustomFields.getLocalizedName(context, title))
|
||||
setValue(value.toString(), value.isProtected)
|
||||
setAutoLink()
|
||||
activateCopyButton(allowCopy)
|
||||
assignCopyButtonClickListener(onCopyButtonClickListener)
|
||||
applyFontVisibility(fontInVisibility)
|
||||
}
|
||||
|
||||
entryCustomField?.let {
|
||||
extraFieldsListView.addView(it)
|
||||
}
|
||||
})
|
||||
|
||||
showOrHideExtraFieldsContainer(false)
|
||||
}
|
||||
|
||||
private fun addExtraCCField(fieldName: String,
|
||||
value: ProtectedString,
|
||||
allowCopy: Boolean,
|
||||
onCopyButtonClickListener: OnClickListener?) {
|
||||
|
||||
val label = CreditCardCustomFields.getLocalizedName(context, fieldName)
|
||||
|
||||
val entryCustomField: EntryField? = EntryField(context)
|
||||
entryCustomField?.apply {
|
||||
setLabel(label)
|
||||
setValue(value.toString(), value.isProtected)
|
||||
activateCopyButton(allowCopy)
|
||||
assignCopyButtonClickListener(onCopyButtonClickListener)
|
||||
applyFontVisibility(fontInVisibility)
|
||||
}
|
||||
|
||||
entryCustomField?.let {
|
||||
creditCardFieldsListView.addView(it)
|
||||
}
|
||||
|
||||
showOrHideCreditCardContainer(false)
|
||||
}
|
||||
|
||||
fun clearExtraFields() {
|
||||
extraFieldsListView.removeAllViews()
|
||||
showOrHideExtraFieldsContainer(true)
|
||||
}
|
||||
|
||||
fun clearCreditCardFields() {
|
||||
creditCardFieldsListView.removeAllViews()
|
||||
showOrHideCreditCardContainer(true)
|
||||
}
|
||||
|
||||
/* -------------
|
||||
* Attachments
|
||||
* -------------
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package com.kunzisoft.keepass.view
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.text.util.Linkify
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
@@ -32,7 +31,6 @@ import androidx.annotation.StringRes
|
||||
import androidx.core.text.util.LinkifyCompat
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.model.EntryInfo.Companion.APPLICATION_ID_FIELD_NAME
|
||||
import com.kunzisoft.keepass.model.CreditCardCustomFields
|
||||
import com.kunzisoft.keepass.utils.UriUtil
|
||||
|
||||
class EntryField @JvmOverloads constructor(context: Context,
|
||||
|
||||
Reference in new issue
Block a user