Skip to content

Commit

Permalink
Merge pull request #1658 from Adyen/feature/extended-autofill-support
Browse files Browse the repository at this point in the history
Extend autofill support
  • Loading branch information
OscarSpruit authored Jun 19, 2024
2 parents 2e0b76f + a8d1de2 commit f4cce6b
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 38 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
## New
- UPI now supports `upi_intent` payment apps.
- The new iDEAL payment flow where the shopper is redirected to the iDEAL payment page to select their bank and authorize the payment.
- Autofill support for:
- Gift cards number and PIN fields
- UPI Virtual Payments Address field
- Address input fields (improved)

## Changed
- Drop-in navigation improvements:
Expand Down
2 changes: 2 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ext {
// Android Dependencies
annotation_version = "1.8.0"
appcompat_version = "1.6.1"
autofill_version = "1.3.0-alpha01"
browser_version = "1.8.0"
coroutines_version = "1.8.0"
fragment_version = "1.6.2"
Expand Down Expand Up @@ -89,6 +90,7 @@ ext {
androidx : [
annotation : "androidx.annotation:annotation:$annotation_version",
appcompat : "androidx.appcompat:appcompat:$appcompat_version",
autofill : "androidx.autofill:autofill:$autofill_version",
browser : "androidx.browser:browser:$browser_version",
constraintlayout: "androidx.constraintlayout:constraintlayout:$constraintlayout_version",
fragment : "androidx.fragment:fragment-ktx:$fragment_version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@
package com.adyen.checkout.giftcard.internal.ui.view

import android.content.Context
import android.os.Build
import android.text.Editable
import android.text.InputType
import android.text.method.DigitsKeyListener
import android.util.AttributeSet
import androidx.autofill.HintConstants
import com.adyen.checkout.giftcard.internal.util.GiftCardNumberUtils
import com.adyen.checkout.giftcard.internal.util.GiftCardNumberUtils.DIGIT_SEPARATOR
import com.adyen.checkout.giftcard.internal.util.GiftCardNumberUtils.MAXIMUM_GIFT_CARD_NUMBER_LENGTH
import com.adyen.checkout.giftcard.internal.util.GiftCardNumberUtils.MAX_DIGIT_SEPARATOR_COUNT
import com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText

internal class GiftCardNumberInput constructor(
internal class GiftCardNumberInput(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AdyenTextInputEditText(context, attrs, defStyleAttr) {

companion object {
private const val SUPPORTED_DIGITS = "0123456789"
}

constructor(context: Context) : this(context, null, 0)

constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
Expand All @@ -37,6 +35,9 @@ internal class GiftCardNumberInput constructor(
enforceMaxInputLength(MAXIMUM_GIFT_CARD_NUMBER_LENGTH + MAX_DIGIT_SEPARATOR_COUNT)
inputType = InputType.TYPE_CLASS_NUMBER
keyListener = DigitsKeyListener.getInstance(SUPPORTED_DIGITS + DIGIT_SEPARATOR)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setAutofillHints(HintConstants.AUTOFILL_HINT_GIFT_CARD_NUMBER)
}
}

override val rawValue: String
Expand All @@ -50,4 +51,8 @@ internal class GiftCardNumberInput constructor(
}
super.afterTextChanged(editable)
}

companion object {
private const val SUPPORTED_DIGITS = "0123456789"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
package com.adyen.checkout.giftcard.internal.ui.view

import android.content.Context
import android.os.Build
import android.text.Editable
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnFocusChangeListener
import android.widget.LinearLayout
import androidx.autofill.HintConstants
import com.adyen.checkout.components.core.internal.ui.ComponentDelegate
import com.adyen.checkout.components.core.internal.ui.model.Validation
import com.adyen.checkout.core.AdyenLogLevel
Expand Down Expand Up @@ -51,6 +53,10 @@ internal class GiftCardView @JvmOverloads constructor(
orientation = VERTICAL
val padding = resources.getDimension(UICoreR.dimen.standard_margin).toInt()
setPadding(padding, padding, padding, 0)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding.editTextGiftcardPin.setAutofillHints(HintConstants.AUTOFILL_HINT_GIFT_CARD_PIN)
}
}

override fun initView(delegate: ComponentDelegate, coroutineScope: CoroutineScope, localizedContext: Context) {
Expand Down
8 changes: 8 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@
<sha256 value="3677abead5d4e06cf76cbacb954151e051779c2274494451fb424e375aa9e450" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="androidx.autofill" name="autofill" version="1.3.0-alpha01">
<artifact name="autofill-1.3.0-alpha01.aar">
<sha256 value="b06149ef3037f7ff249433e209c51ca9676307f6dd701febe199372ff7918d89" origin="Generated by Gradle"/>
</artifact>
<artifact name="autofill-1.3.0-alpha01.module">
<sha256 value="c043467e6cb56ee796cd3e8c772576991314682763321f4e21f07dd1b3f2ba5a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="androidx.browser" name="browser" version="1.7.0">
<artifact name="browser-1.7.0.aar">
<sha256 value="e03b6ef8c6d7a148886702abcd2995ee1d4bc0492cac5fc6aa49c472fce06b93" origin="Generated by Gradle"/>
Expand Down
1 change: 1 addition & 0 deletions ui-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {

// Dependencies
implementation libraries.androidx.appcompat
api libraries.androidx.autofill
api libraries.androidx.constraintlayout
implementation libraries.androidx.recyclerview
api libraries.material
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
package com.adyen.checkout.ui.core.internal.ui.view

import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View.OnFocusChangeListener
import android.widget.AdapterView
import android.widget.AutoCompleteTextView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.autofill.HintConstants
import com.adyen.checkout.components.core.internal.ui.model.Validation
import com.adyen.checkout.ui.core.R
import com.adyen.checkout.ui.core.internal.ui.AddressDelegate
Expand Down Expand Up @@ -110,6 +112,9 @@ class AddressFormInput @JvmOverloads constructor(
LayoutInflater.from(context).inflate(R.layout.address_form_input, this, true)

autoCompleteTextViewCountry.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setAutofillHints(HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY)
}
inputType = 0
setAdapter(countryAdapter)
onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
Expand Down Expand Up @@ -305,6 +310,9 @@ class AddressFormInput @JvmOverloads constructor(
private fun initStreetInput(styleResId: Int?) {
styleResId?.let { textInputLayoutStreet?.setLocalizedHintFromStyle(it, localizedContext) }
editTextStreet?.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setAutofillHints(HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS)
}
setText(delegate.addressOutputData.street.value)
setOnChangeListener {
delegate.updateAddressInputData { street = it.toString() }
Expand Down Expand Up @@ -343,6 +351,9 @@ class AddressFormInput @JvmOverloads constructor(
private fun initApartmentSuiteInput(styleResId: Int?) {
styleResId?.let { textInputLayoutApartmentSuite?.setLocalizedHintFromStyle(it, localizedContext) }
editTextApartmentSuite?.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setAutofillHints(HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_APT_NUMBER)
}
setText(delegate.addressOutputData.apartmentSuite.value)
setOnChangeListener {
delegate.updateAddressInputData { apartmentSuite = it.toString() }
Expand All @@ -361,6 +372,9 @@ class AddressFormInput @JvmOverloads constructor(
private fun initPostalCodeInput(styleResId: Int?) {
styleResId?.let { textInputLayoutPostalCode?.setLocalizedHintFromStyle(it, localizedContext) }
editTextPostalCode?.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setAutofillHints(HintConstants.AUTOFILL_HINT_POSTAL_CODE)
}
setText(delegate.addressOutputData.postalCode.value)
setOnChangeListener {
delegate.updateAddressInputData { postalCode = it.toString() }
Expand All @@ -380,6 +394,9 @@ class AddressFormInput @JvmOverloads constructor(
private fun initCityInput(styleResId: Int?) {
styleResId?.let { textInputLayoutCity?.setLocalizedHintFromStyle(it, localizedContext) }
editTextCity?.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setAutofillHints(HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY)
}
setText(delegate.addressOutputData.city.value)
setOnChangeListener {
delegate.updateAddressInputData { city = it.toString() }
Expand All @@ -399,6 +416,9 @@ class AddressFormInput @JvmOverloads constructor(
private fun initProvinceTerritoryInput(styleResId: Int?) {
styleResId?.let { textInputLayoutProvinceTerritory?.setLocalizedHintFromStyle(it, localizedContext) }
editTextProvinceTerritory?.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setAutofillHints(HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_REGION)
}
setText(delegate.addressOutputData.stateOrProvince.value)
setOnChangeListener {
delegate.updateAddressInputData { stateOrProvince = it.toString() }
Expand All @@ -418,6 +438,9 @@ class AddressFormInput @JvmOverloads constructor(
private fun initStatesInput(styleResId: Int?) {
styleResId?.let { textInputLayoutState?.setLocalizedHintFromStyle(it, localizedContext) }
autoCompleteTextViewState?.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setAutofillHints(HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_REGION)
}
setText(statesAdapter.getItem { it.selected }?.name)
inputType = 0
setAdapter(statesAdapter)
Expand Down
9 changes: 2 additions & 7 deletions ui-core/src/main/res/layout/address_form_br.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_street"
style="@style/AdyenCheckout.StreetInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_houseNumber"
android:nextFocusForward="@id/editText_houseNumber" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -36,7 +35,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_houseNumber"
style="@style/AdyenCheckout.HouseNumberInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_apartmentSuite"
android:nextFocusForward="@id/editText_apartmentSuite" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -50,7 +48,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_apartmentSuite"
style="@style/AdyenCheckout.ApartmentSuiteInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_postalCode"
android:nextFocusForward="@id/editText_postalCode" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -64,7 +61,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_postalCode"
style="@style/AdyenCheckout.PostalCodeInput"
android:autofillHints="postalCode"
android:nextFocusDown="@id/editText_city"
android:nextFocusForward="@id/editText_city" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -77,8 +73,8 @@

<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_city"
style="@style/AdyenCheckout.CityInput"
android:autofillHints="postalAddress" />
style="@style/AdyenCheckout.CityInput" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
Expand All @@ -92,7 +88,6 @@
style="@style/AdyenCheckout.DropdownTextInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="postalAddress"
android:dropDownAnchor="@id/textInputLayout_state" />
</com.google.android.material.textfield.TextInputLayout>

Expand Down
11 changes: 4 additions & 7 deletions ui-core/src/main/res/layout/address_form_ca.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_street"
style="@style/AdyenCheckout.AddressInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_apartmentSuite"
android:nextFocusForward="@id/editText_apartmentSuite" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -36,7 +35,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_apartmentSuite"
style="@style/AdyenCheckout.ApartmentSuiteInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_city"
android:nextFocusForward="@id/editText_city" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -50,7 +48,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_city"
style="@style/AdyenCheckout.CityInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_postalCode"
android:nextFocusForward="@id/editText_postalCode" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -63,8 +60,8 @@

<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_postalCode"
style="@style/AdyenCheckout.PostalCodeInput"
android:autofillHints="postalCode" />
style="@style/AdyenCheckout.PostalCodeInput" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
Expand All @@ -77,7 +74,7 @@
android:id="@+id/autoCompleteTextView_state"
style="@style/AdyenCheckout.DropdownTextInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="postalAddress" />
android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>
</merge>
8 changes: 1 addition & 7 deletions ui-core/src/main/res/layout/address_form_default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_street"
style="@style/AdyenCheckout.StreetInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_houseNumber"
android:nextFocusForward="@id/editText_houseNumber" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -36,7 +35,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_houseNumber"
style="@style/AdyenCheckout.HouseNumberInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_apartmentSuite"
android:nextFocusForward="@id/editText_apartmentSuite" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -50,7 +48,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_apartmentSuite"
style="@style/AdyenCheckout.ApartmentSuiteInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_postalCode"
android:nextFocusForward="@id/editText_postalCode" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -64,7 +61,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_postalCode"
style="@style/AdyenCheckout.PostalCodeInput"
android:autofillHints="postalCode"
android:nextFocusDown="@id/editText_city"
android:nextFocusForward="@id/editText_city" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -78,7 +74,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_city"
style="@style/AdyenCheckout.CityInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_provinceTerritory"
android:nextFocusForward="@id/editText_provinceTerritory" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -91,7 +86,6 @@

<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_provinceTerritory"
style="@style/AdyenCheckout.ProvinceTerritoryInput"
android:autofillHints="postalAddress" />
style="@style/AdyenCheckout.ProvinceTerritoryInput" />
</com.google.android.material.textfield.TextInputLayout>
</merge>
6 changes: 1 addition & 5 deletions ui-core/src/main/res/layout/address_form_gb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_houseNumber"
style="@style/AdyenCheckout.HouseNumberInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_street"
android:nextFocusForward="@id/editText_street" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -36,7 +35,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_street"
style="@style/AdyenCheckout.StreetInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_city"
android:nextFocusForward="@id/editText_city" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -50,7 +48,6 @@
<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_city"
style="@style/AdyenCheckout.CityTownInput"
android:autofillHints="postalAddress"
android:nextFocusDown="@id/editText_postalCode"
android:nextFocusForward="@id/editText_postalCode" />
</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -63,7 +60,6 @@

<com.adyen.checkout.ui.core.internal.ui.view.AdyenTextInputEditText
android:id="@+id/editText_postalCode"
style="@style/AdyenCheckout.PostalCodeInput"
android:autofillHints="postalCode" />
style="@style/AdyenCheckout.PostalCodeInput" />
</com.google.android.material.textfield.TextInputLayout>
</merge>
2 changes: 1 addition & 1 deletion ui-core/src/main/res/layout/address_form_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
android:layout_height="wrap_content"
android:orientation="vertical" />

</merge>
</merge>
Loading

0 comments on commit f4cce6b

Please sign in to comment.