Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CardInputWidget#setPostalCodeTextWatcher #2207

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions stripe/src/main/java/com/stripe/android/view/CardInputWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
21 changes: 21 additions & 0 deletions stripe/src/main/java/com/stripe/android/view/CardWidget.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down