Skip to content

Commit

Permalink
Show payId views based on the selected type
Browse files Browse the repository at this point in the history
COAND-1058
  • Loading branch information
araratthehero committed Feb 13, 2025
1 parent f16a5fc commit 77d4fb0
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.adyen.checkout.core.internal.util.adyenLog
import com.adyen.checkout.payto.R
import com.adyen.checkout.payto.databinding.PaytoViewBinding
import com.adyen.checkout.payto.internal.ui.PayToDelegate
import com.adyen.checkout.payto.internal.ui.model.PayIdType
import com.adyen.checkout.payto.internal.ui.model.PayIdTypeModel
import com.adyen.checkout.payto.internal.ui.model.PayToMode
import com.adyen.checkout.ui.core.internal.ui.ComponentView
Expand Down Expand Up @@ -141,9 +142,9 @@ internal class PayToView @JvmOverloads constructor(
}

private fun initPayIdTypeSelector() {
val getPayIdTypes = delegate.getPayIdTypes()
val payIdTypes = delegate.getPayIdTypes()
val payIdTypeAdapter = PayIdTypeAdapter(context, localizedContext)
payIdTypeAdapter.setItems(getPayIdTypes)
payIdTypeAdapter.setItems(payIdTypes)

binding.autoCompleteTextViewPayIdType.apply {
inputType = 0
Expand All @@ -155,17 +156,25 @@ internal class PayToView @JvmOverloads constructor(
}
}

getPayIdTypes.firstOrNull()?.let { payIdTypeModel ->
payIdTypes.firstOrNull()?.let { payIdTypeModel ->
val name = localizedContext.getString(payIdTypeModel.nameResId)
binding.autoCompleteTextViewPayIdType.setText(name)
onPayIdTypeSelected(payIdTypeModel)
}
}

private fun onPayIdTypeSelected(payIdTypeModel: PayIdTypeModel) {
togglePayIdTypeViews(payIdTypeModel)
delegate.updateInputData { this.payIdTypeModel = payIdTypeModel }
}

private fun togglePayIdTypeViews(payIdTypeModel: PayIdTypeModel) = with(binding) {
textInputLayoutPayIdPhoneNumber.isVisible = payIdTypeModel.type == PayIdType.MOBILE
textInputLayoutPayIdEmail.isVisible = payIdTypeModel.type == PayIdType.EMAIL
textInputLayoutPayIdAbn.isVisible = payIdTypeModel.type == PayIdType.ABN
textInputLayoutPayIdOrganizationId.isVisible = payIdTypeModel.type == PayIdType.ORGANIZATION_ID
}

override fun highlightValidationErrors() {
adyenLog(AdyenLogLevel.DEBUG) { "highlightValidationErrors" }
// TODO Do validation
Expand Down

0 comments on commit 77d4fb0

Please sign in to comment.