mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add expiration day
This commit is contained in:
@@ -124,10 +124,9 @@ object AutofillHelper {
|
||||
}
|
||||
|
||||
if (entryInfo.expires) {
|
||||
// get month (month in database entry is stored as String in the format MM)
|
||||
val month = entryInfo.expiryTime.getMonthInt()
|
||||
// get year (year in database entry is stored as String in the format YY)
|
||||
val year = entryInfo.expiryTime.getYearInt()
|
||||
val month = entryInfo.expiryTime.getMonthInt()
|
||||
val day = entryInfo.expiryTime.getDay()
|
||||
|
||||
struct.creditCardExpirationDateId?.let {
|
||||
if (struct.isWebView) {
|
||||
@@ -137,18 +136,6 @@ object AutofillHelper {
|
||||
builder.setValue(it, AutofillValue.forDate(entryInfo.expiryTime.date.time))
|
||||
}
|
||||
}
|
||||
struct.creditCardExpirationMonthId?.let {
|
||||
if (struct.isWebView) {
|
||||
builder.setValue(it, AutofillValue.forText(month.toString()))
|
||||
} else {
|
||||
if (struct.creditCardExpirationMonthOptions != null) {
|
||||
// index starts at 0
|
||||
builder.setValue(it, AutofillValue.forList(month - 1))
|
||||
} else {
|
||||
builder.setValue(it, AutofillValue.forText(month.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
struct.creditCardExpirationYearId?.let {
|
||||
var autofillValue: AutofillValue? = null
|
||||
|
||||
@@ -168,6 +155,29 @@ object AutofillHelper {
|
||||
builder.setValue(it, AutofillValue.forText(year.toString()))
|
||||
}
|
||||
}
|
||||
struct.creditCardExpirationMonthId?.let {
|
||||
if (struct.isWebView) {
|
||||
builder.setValue(it, AutofillValue.forText(month.toString()))
|
||||
} else {
|
||||
if (struct.creditCardExpirationMonthOptions != null) {
|
||||
// index starts at 0
|
||||
builder.setValue(it, AutofillValue.forList(month - 1))
|
||||
} else {
|
||||
builder.setValue(it, AutofillValue.forText(month.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
struct.creditCardExpirationDayId?.let {
|
||||
if (struct.isWebView) {
|
||||
builder.setValue(it, AutofillValue.forText(day.toString()))
|
||||
} else {
|
||||
if (struct.creditCardExpirationDayOptions != null) {
|
||||
builder.setValue(it, AutofillValue.forList(day - 1))
|
||||
} else {
|
||||
builder.setValue(it, AutofillValue.forText(day.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (field in entryInfo.customFields) {
|
||||
if (field.name == TemplateField.LABEL_HOLDER) {
|
||||
|
||||
@@ -259,6 +259,9 @@ class KeeAutofillService : AutofillService() {
|
||||
expiration = DateTime()
|
||||
.withYear(parseResult.creditCardExpirationYearValue)
|
||||
.withMonthOfYear(parseResult.creditCardExpirationMonthValue)
|
||||
if (parseResult.creditCardExpirationDayValue != 0) {
|
||||
expiration = expiration.withDayOfMonth(parseResult.creditCardExpirationDayValue)
|
||||
}
|
||||
}
|
||||
|
||||
// Show UI to save data
|
||||
|
||||
@@ -198,7 +198,7 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
year = node.autofillOptions?.get(value.listValue).toString().toInt()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
year = 0
|
||||
Log.e(TAG, "Unable to retrieve expiration year", e)
|
||||
}
|
||||
result?.creditCardExpirationYearValue = year % 100
|
||||
}
|
||||
@@ -212,20 +212,42 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
}
|
||||
node.autofillValue?.let { value ->
|
||||
var month = 0
|
||||
if (value.isText) {
|
||||
month = try {
|
||||
value.textValue.toString().toInt()
|
||||
} catch (e: Exception) {
|
||||
0
|
||||
try {
|
||||
if (value.isText) {
|
||||
month = value.textValue.toString().toInt()
|
||||
}
|
||||
}
|
||||
if (value.isList) {
|
||||
// assume list starts with January (index 0)
|
||||
month = value.listValue + 1
|
||||
if (value.isList) {
|
||||
// assume list starts with January (index 0)
|
||||
month = value.listValue + 1
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to retrieve expiration month", e)
|
||||
}
|
||||
result?.creditCardExpirationMonthValue = month
|
||||
}
|
||||
}
|
||||
it.contains(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY, true)
|
||||
|| it.contains("cc-exp-day", true) -> {
|
||||
Log.d(TAG, "Autofill credit card expiration day hint")
|
||||
result?.creditCardExpirationDayId = autofillId
|
||||
if (node.autofillOptions != null) {
|
||||
result?.creditCardExpirationDayOptions = node.autofillOptions
|
||||
}
|
||||
node.autofillValue?.let { value ->
|
||||
var day = 0
|
||||
try {
|
||||
if (value.isText) {
|
||||
day = value.textValue.toString().toInt()
|
||||
}
|
||||
if (value.isList) {
|
||||
day = node.autofillOptions?.get(value.listValue).toString().toInt()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to retrieve expiration day", e)
|
||||
}
|
||||
result?.creditCardExpirationDayValue = day
|
||||
}
|
||||
}
|
||||
it.contains(View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE, true)
|
||||
|| it.contains("cc-csc", true) -> {
|
||||
Log.d(TAG, "Autofill card security code hint")
|
||||
@@ -392,8 +414,9 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
|
||||
// if the user selects the credit card expiration date from a list of options
|
||||
// all options are stored here
|
||||
var creditCardExpirationMonthOptions: Array<CharSequence>? = null
|
||||
var creditCardExpirationYearOptions: Array<CharSequence>? = null
|
||||
var creditCardExpirationMonthOptions: Array<CharSequence>? = null
|
||||
var creditCardExpirationDayOptions: Array<CharSequence>? = null
|
||||
|
||||
var usernameId: AutofillId? = null
|
||||
set(value) {
|
||||
@@ -437,6 +460,12 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
field = value
|
||||
}
|
||||
|
||||
var creditCardExpirationDayId: AutofillId? = null
|
||||
set(value) {
|
||||
if (field == null)
|
||||
field = value
|
||||
}
|
||||
|
||||
var cardVerificationValueId: AutofillId? = null
|
||||
set(value) {
|
||||
if (field == null)
|
||||
@@ -511,6 +540,12 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
field = value
|
||||
}
|
||||
|
||||
var creditCardExpirationDayValue = 0
|
||||
set(value) {
|
||||
if (allowSaveValues)
|
||||
field = value
|
||||
}
|
||||
|
||||
// the security code for the credit card (also called CVV)
|
||||
var cardVerificationValue: String? = null
|
||||
set(value) {
|
||||
|
||||
@@ -140,13 +140,18 @@ class DateInstant : Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
fun getYearInt(): Int {
|
||||
val dateFormat = SimpleDateFormat("yyyy", Locale.ENGLISH)
|
||||
return dateFormat.format(date).toInt()
|
||||
}
|
||||
|
||||
fun getMonthInt(): Int {
|
||||
val dateFormat = SimpleDateFormat("MM", Locale.ENGLISH)
|
||||
return dateFormat.format(date).toInt()
|
||||
}
|
||||
|
||||
fun getYearInt(): Int {
|
||||
val dateFormat = SimpleDateFormat("yyyy", Locale.ENGLISH)
|
||||
fun getDay(): Int {
|
||||
val dateFormat = SimpleDateFormat("dd", Locale.ENGLISH)
|
||||
return dateFormat.format(date).toInt()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user