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

SK-1691/Release/24.9.3 #174

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Skyflow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
23 changes: 16 additions & 7 deletions Skyflow/src/main/kotlin/Skyflow/TextField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -443,6 +451,7 @@ class TextField @JvmOverloads constructor(
updateCardChoice(selectedCardType, true)
changeCardIcon(selectedCardType)
inputField.setSelection(inputField.length())
invokeUserOnChangeListener()
true
}

Expand Down
22 changes: 10 additions & 12 deletions samples/src/main/java/com/Skyflow/CardBrandChoiceActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<CardType>()
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))
Expand All @@ -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<LinearLayout>(R.id.parent)
Expand Down
Loading