diff --git a/Skyflow/build.gradle b/Skyflow/build.gradle index 405af66..c24cb19 100644 --- a/Skyflow/build.gradle +++ b/Skyflow/build.gradle @@ -10,7 +10,7 @@ ext { mGroupId = "com.skyflowapi.android" mArtifactId = "skyflow-android-sdk" mVersionCode = 1 - mVersionName = "1.25.0" + mVersionName = "1.25.0-dev.7d29da5" mLibraryName = "skyflow-android" mLibraryDescription = "Skyflow’s android SDK can be used to securely collect, tokenize, and display sensitive data in the mobile without exposing your front-end infrastructure to sensitive data." diff --git a/Skyflow/src/main/kotlin/Skyflow/TextField.kt b/Skyflow/src/main/kotlin/Skyflow/TextField.kt index bb1884c..b7b1e7d 100644 --- a/Skyflow/src/main/kotlin/Skyflow/TextField.kt +++ b/Skyflow/src/main/kotlin/Skyflow/TextField.kt @@ -84,6 +84,7 @@ class TextField @JvmOverloads constructor( internal var cardType = CardType.EMPTY internal var isCustomCardBrandSelected = false + private var isCardMetadataUpdated = false private var dAWidth = 0 private var cIWidth = 0 @@ -282,6 +283,14 @@ class TextField @JvmOverloads constructor( } } + private fun invokeUserOnChangeListener() { + if (userOnchangeListener !== null) { + userOnchangeListener?.let { + it((state as StateforText).getState(optionsForLogging.env)) + } + } + } + fun on(eventName: EventName, handler: (state: JSONObject) -> Unit) { when (eventName) { EventName.CHANGE -> this.userOnchangeListener = handler @@ -307,8 +316,12 @@ class TextField @JvmOverloads constructor( } fun update(updateCollectOptions: CollectElementOptions) { + isCardMetadataUpdated = true this.options.cardMetadata = updateCollectOptions.cardMetadata this.setupField(this.collectInput, this.options) + if (updateCollectOptions.cardMetadata.scheme.size < 2) { + invokeUserOnChangeListener() + } } @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @@ -358,12 +371,7 @@ class TextField @JvmOverloads constructor( } else if (options.enableCopy) { removeIcon() } - - if (userOnchangeListener !== null) { - userOnchangeListener?.let { - it((state as StateforText).getState(optionsForLogging.env)) - } - } + invokeUserOnChangeListener() onBeginEditing?.invoke() } @@ -412,7 +420,7 @@ class TextField @JvmOverloads constructor( var icons = arrayOf(cardImage) var layerDrawable = LayerDrawable(icons) - if (options.cardMetadata.scheme.size > 1) { + if (isCardMetadataUpdated && options.cardMetadata.scheme.size > 1) { icons = arrayOf(cardImage, dropdownArrow) layerDrawable = LayerDrawable(icons) layerDrawable.setLayerInset(0, 0, 0, dAWidth, 0) @@ -443,6 +451,7 @@ class TextField @JvmOverloads constructor( updateCardChoice(selectedCardType, true) changeCardIcon(selectedCardType) inputField.setSelection(inputField.length()) + invokeUserOnChangeListener() true } diff --git a/samples/src/main/java/com/Skyflow/CardBrandChoiceActivity.kt b/samples/src/main/java/com/Skyflow/CardBrandChoiceActivity.kt index dbe4cb2..b6d3217 100644 --- a/samples/src/main/java/com/Skyflow/CardBrandChoiceActivity.kt +++ b/samples/src/main/java/com/Skyflow/CardBrandChoiceActivity.kt @@ -103,26 +103,24 @@ class CardBrandChoiceActivity : AppCompatActivity() { val cvv = collectContainer.create(this, cvvInput) cardNumber.on(EventName.FOCUS) { state -> - Log.d(TAG, "focus: sate $state") + Log.d(TAG, "focus: state $state") } cardNumber.on(EventName.BLUR) { state -> - Log.d(TAG, "blur: sate $state") + Log.d(TAG, "blur: state $state") } - var calledUpdate = false + var scheme = arrayOf() cardNumber.on(EventName.CHANGE) { state -> - Log.d(TAG, "change: sate $state") + Log.d(TAG, "change: state $state") val value = state.getString("value") - if (value.length < 8 && calledUpdate) { - calledUpdate = false - cardNumber.update(CollectElementOptions(cardMetadata = CardMetadata(arrayOf()))) - } else if (value.length >= 8 && !calledUpdate) { - calledUpdate = true + if (value.length < 8 && scheme.isNotEmpty()) { + scheme = arrayOf() + cardNumber.update(CollectElementOptions(cardMetadata = CardMetadata(scheme))) + } else if (value.length >= 8 && scheme.isEmpty()) { binLookup(value, object : Callback { override fun onSuccess(responseBody: Any) { - println(responseBody as JSONArray) - val scheme = getCardSchemes(responseBody) + scheme = getCardSchemes(responseBody as JSONArray) runOnUiThread(kotlinx.coroutines.Runnable { cardNumber.update( CollectElementOptions(cardMetadata = CardMetadata(scheme)) @@ -138,7 +136,7 @@ class CardBrandChoiceActivity : AppCompatActivity() { } cardNumber.on(EventName.READY) { state -> - Log.d(TAG, "ready: sate $state") + Log.d(TAG, "ready: state $state") } val parent = findViewById(R.id.parent)