diff --git a/buildSrc/src/main/kotlin/ComponentVersions.kt b/buildSrc/src/main/kotlin/ComponentVersions.kt index fa8f2a03..c27a4b6d 100644 --- a/buildSrc/src/main/kotlin/ComponentVersions.kt +++ b/buildSrc/src/main/kotlin/ComponentVersions.kt @@ -6,7 +6,7 @@ object ComponentVersions { const val imageSliderVersion = "1.0.8" const val phoneNumberVersion = "1.0.2" const val dialogsVersion = "1.2.5" - const val cardInputViewVersion = "1.1.2" + const val cardInputViewVersion = "1.1.3" const val quantityPickerViewVersion = "1.2.4" const val timelineViewVersion = "1.0.0" const val touchDelegatorVersion = "1.0.0" diff --git a/libraries/card-input-view/README.md b/libraries/card-input-view/README.md index 2cc26fd8..5e49665e 100644 --- a/libraries/card-input-view/README.md +++ b/libraries/card-input-view/README.md @@ -43,6 +43,8 @@ To validate inputs, call `CardInputView.validate()`. If you want to get created To reset all inputs, call `CardInputView.reset()`. +To clear all inputs' errors, call `CardInputView.clearErrors()`. + To focus and show soft keyboard on card number field call `CardInputView.focusToCardNumberField()`, to focus CVV field call `CardInputView.focusToCvvField()`. For expire month and year selection, you need to open custom dialog or input field, we suggest you to use **Dialogs**, to more information about **Dialogs**, [click here](https://github.com/Trendyol/android-ui-components/tree/master/libraries/dialogs). diff --git a/libraries/card-input-view/src/main/java/com/trendyol/cardinputview/CardInputView.kt b/libraries/card-input-view/src/main/java/com/trendyol/cardinputview/CardInputView.kt index 2468fb0f..6b668638 100644 --- a/libraries/card-input-view/src/main/java/com/trendyol/cardinputview/CardInputView.kt +++ b/libraries/card-input-view/src/main/java/com/trendyol/cardinputview/CardInputView.kt @@ -79,7 +79,8 @@ class CardInputView : ConstraintLayout { cardNumberValid = isCardNumberValid, expiryMonthValid = isExpiryMonthValid, expiryYearValid = isExpiryYearValid, - cvvValid = isCvvValid + cvvValid = isCvvValid, + shouldShowErrors = true ) binding.executePendingBindings() @@ -108,6 +109,16 @@ class CardInputView : ConstraintLayout { binding.executePendingBindings() } + /** + * + * Clears all input fields' error states + * it will immediately sets all fields backgrounds with [CardInputViewState.inputBackgroundDrawable]. + */ + fun clearErrors() { + binding.viewState = binding.viewState?.copy(shouldShowErrors = false) + binding.executePendingBindings() + } + /** * * Card number field will be focused and keyboard will open. diff --git a/libraries/card-input-view/src/main/java/com/trendyol/cardinputview/CardInputViewState.kt b/libraries/card-input-view/src/main/java/com/trendyol/cardinputview/CardInputViewState.kt index 5509716b..fee314da 100644 --- a/libraries/card-input-view/src/main/java/com/trendyol/cardinputview/CardInputViewState.kt +++ b/libraries/card-input-view/src/main/java/com/trendyol/cardinputview/CardInputViewState.kt @@ -24,6 +24,7 @@ data class CardInputViewState( private val expiryMonthValid: Boolean = true, private val expiryYearValid: Boolean = true, private val cvvValid: Boolean = true, + private val shouldShowErrors: Boolean = true, var cardInformation: CardInformation = CardInformation() ) { @@ -52,25 +53,25 @@ data class CardInputViewState( val dividerVisibility: Int = if (cardBankLogoDrawable != null) View.VISIBLE else View.GONE val cvvInfoButtonVisibility: Int = if (showCvvInfoButton) View.VISIBLE else View.GONE val cardNumberBackground: Drawable? = - if (cardNumberValid) { + if (!shouldShowErrors || cardNumberValid) { inputBackgroundDrawable } else { inputErrorBackgroundDrawable }?.constantState?.newDrawable() val expiryMonthBackground: Drawable? = - if (expiryMonthValid) { + if (!shouldShowErrors || expiryMonthValid) { inputBackgroundDrawable } else { inputErrorBackgroundDrawable }?.constantState?.newDrawable() val expiryYearBackground: Drawable? = - if (expiryYearValid) { + if (!shouldShowErrors || expiryYearValid) { inputBackgroundDrawable } else { inputErrorBackgroundDrawable }?.constantState?.newDrawable() val cvvBackground: Drawable? = - if (cvvValid) { + if (!shouldShowErrors || cvvValid) { inputBackgroundDrawable } else { inputErrorBackgroundDrawable @@ -83,6 +84,7 @@ data class CardInputViewState( cardNumberValid = true, expiryMonthValid = true, expiryYearValid = true, - cvvValid = true + cvvValid = true, + shouldShowErrors = true ) } diff --git a/sample/src/main/java/com/trendyol/uicomponents/CardInputViewActivity.kt b/sample/src/main/java/com/trendyol/uicomponents/CardInputViewActivity.kt index 210b1e81..922f63b2 100644 --- a/sample/src/main/java/com/trendyol/uicomponents/CardInputViewActivity.kt +++ b/sample/src/main/java/com/trendyol/uicomponents/CardInputViewActivity.kt @@ -22,6 +22,7 @@ class CardInputViewActivity : AppCompatActivity() { private val buttonValidate by lazy { findViewById