From 74d4253297513010b5ca1ffb3e0250d60924637f Mon Sep 17 00:00:00 2001 From: Michael Shafrir Date: Thu, 20 Feb 2020 10:03:17 -0500 Subject: [PATCH] Add CardInputWidget#setPostalCodeTextWatcher --- .../stripe/android/view/CardInputWidget.kt | 19 +++++++++++------ .../android/view/CardMultilineWidget.kt | 16 +++++++------- .../com/stripe/android/view/CardWidget.kt | 21 +++++++++++++++++++ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/view/CardInputWidget.kt b/stripe/src/main/java/com/stripe/android/view/CardInputWidget.kt index 415d25559fc..a1f59fb1436 100644 --- a/stripe/src/main/java/com/stripe/android/view/CardInputWidget.kt +++ b/stripe/src/main/java/com/stripe/android/view/CardInputWidget.kt @@ -379,26 +379,33 @@ class CardInputWidget @JvmOverloads constructor( } /** - * Expose a text watcher to receive updates when the card number is changed. + * Set a `TextWatcher` to receive card number changes. */ - fun setCardNumberTextWatcher(cardNumberTextWatcher: TextWatcher?) { + override fun setCardNumberTextWatcher(cardNumberTextWatcher: TextWatcher?) { cardNumberEditText.addTextChangedListener(cardNumberTextWatcher) } /** - * Expose a text watcher to receive updates when the expiry date is changed. + * Set a `TextWatcher` to receive expiration date changes. */ - fun setExpiryDateTextWatcher(expiryDateTextWatcher: TextWatcher?) { + override fun setExpiryDateTextWatcher(expiryDateTextWatcher: TextWatcher?) { expiryDateEditText.addTextChangedListener(expiryDateTextWatcher) } /** - * Expose a text watcher to receive updates when the cvc number is changed. + * Set a `TextWatcher` to receive CVC value changes. */ - fun setCvcNumberTextWatcher(cvcNumberTextWatcher: TextWatcher?) { + override fun setCvcNumberTextWatcher(cvcNumberTextWatcher: TextWatcher?) { cvcNumberEditText.addTextChangedListener(cvcNumberTextWatcher) } + /** + * Set a `TextWatcher` to receive postal code changes. + */ + override fun setPostalCodeTextWatcher(postalCodeTextWatcher: TextWatcher?) { + postalCodeEditText.addTextChangedListener(postalCodeTextWatcher) + } + /** * Override of [View.isEnabled] that returns `true` only * if all three sub-controls are enabled. diff --git a/stripe/src/main/java/com/stripe/android/view/CardMultilineWidget.kt b/stripe/src/main/java/com/stripe/android/view/CardMultilineWidget.kt index 814d57027d7..72ebf8548b2 100644 --- a/stripe/src/main/java/com/stripe/android/view/CardMultilineWidget.kt +++ b/stripe/src/main/java/com/stripe/android/view/CardMultilineWidget.kt @@ -413,30 +413,30 @@ class CardMultilineWidget @JvmOverloads constructor( } /** - * Expose a text watcher to receive updates when the card number is changed. + * Set a `TextWatcher` to receive card number changes. */ - fun setCardNumberTextWatcher(cardNumberTextWatcher: TextWatcher?) { + override fun setCardNumberTextWatcher(cardNumberTextWatcher: TextWatcher?) { cardNumberEditText.addTextChangedListener(cardNumberTextWatcher) } /** - * Expose a text watcher to receive updates when the expiry date is changed. + * Set a `TextWatcher` to receive expiration date changes. */ - fun setExpiryDateTextWatcher(expiryDateTextWatcher: TextWatcher?) { + override fun setExpiryDateTextWatcher(expiryDateTextWatcher: TextWatcher?) { expiryDateEditText.addTextChangedListener(expiryDateTextWatcher) } /** - * Expose a text watcher to receive updates when the cvc number is changed. + * Set a `TextWatcher` to receive CVC value changes. */ - fun setCvcNumberTextWatcher(cvcNumberTextWatcher: TextWatcher?) { + override fun setCvcNumberTextWatcher(cvcNumberTextWatcher: TextWatcher?) { cvcEditText.addTextChangedListener(cvcNumberTextWatcher) } /** - * Expose a text watcher to receive updates when the cvc number is changed. + * Set a `TextWatcher` to receive postal code changes. */ - fun setPostalCodeTextWatcher(postalCodeTextWatcher: TextWatcher?) { + override fun setPostalCodeTextWatcher(postalCodeTextWatcher: TextWatcher?) { postalCodeEditText.addTextChangedListener(postalCodeTextWatcher) } diff --git a/stripe/src/main/java/com/stripe/android/view/CardWidget.kt b/stripe/src/main/java/com/stripe/android/view/CardWidget.kt index 304f37ae190..c1f51644794 100644 --- a/stripe/src/main/java/com/stripe/android/view/CardWidget.kt +++ b/stripe/src/main/java/com/stripe/android/view/CardWidget.kt @@ -1,5 +1,6 @@ package com.stripe.android.view +import android.text.TextWatcher import androidx.annotation.IntRange import com.stripe.android.model.Card import com.stripe.android.model.PaymentMethodCreateParams @@ -28,6 +29,26 @@ internal interface CardWidget { fun setCardInputListener(listener: CardInputListener?) + /** + * Set a `TextWatcher` to receive card number changes. + */ + fun setCardNumberTextWatcher(cardNumberTextWatcher: TextWatcher?) + + /** + * Set a `TextWatcher` to receive expiration date changes. + */ + fun setExpiryDateTextWatcher(expiryDateTextWatcher: TextWatcher?) + + /** + * Set a `TextWatcher` to receive CVC value changes. + */ + fun setCvcNumberTextWatcher(cvcNumberTextWatcher: TextWatcher?) + + /** + * Set a `TextWatcher` to receive postal code changes. + */ + fun setPostalCodeTextWatcher(postalCodeTextWatcher: TextWatcher?) + fun setCardHint(cardHint: String) fun clear()