@@ -43,7 +43,12 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.offlinePayment
43
43
import kotlinx.android.synthetic.main.fragment_attendee.view.offlinePaymentDescription
44
44
import kotlinx.android.synthetic.main.fragment_attendee.view.month
45
45
import kotlinx.android.synthetic.main.fragment_attendee.view.monthText
46
- import kotlinx.android.synthetic.main.fragment_attendee.view.paymentSelector
46
+ import kotlinx.android.synthetic.main.fragment_attendee.view.paymentOptionsGroup
47
+ import kotlinx.android.synthetic.main.fragment_attendee.view.paypalRadioButton
48
+ import kotlinx.android.synthetic.main.fragment_attendee.view.stripeRadioButton
49
+ import kotlinx.android.synthetic.main.fragment_attendee.view.onSiteRadioButton
50
+ import kotlinx.android.synthetic.main.fragment_attendee.view.chequeRadioButton
51
+ import kotlinx.android.synthetic.main.fragment_attendee.view.bankRadioButton
47
52
import kotlinx.android.synthetic.main.fragment_attendee.view.paymentSelectorContainer
48
53
import kotlinx.android.synthetic.main.fragment_attendee.view.qty
49
54
import kotlinx.android.synthetic.main.fragment_attendee.view.register
@@ -87,7 +92,6 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.signInText
87
92
import kotlinx.android.synthetic.main.fragment_attendee.view.signInTextLayout
88
93
import kotlinx.android.synthetic.main.fragment_attendee.view.signInLayout
89
94
import kotlinx.android.synthetic.main.fragment_attendee.view.signOutLayout
90
- import kotlinx.android.synthetic.main.fragment_attendee.view.paymentTitle
91
95
import kotlinx.android.synthetic.main.fragment_attendee.view.taxLayout
92
96
import kotlinx.android.synthetic.main.fragment_attendee.view.taxPrice
93
97
import kotlinx.android.synthetic.main.fragment_attendee.view.totalAmountLayout
@@ -340,7 +344,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
340
344
341
345
val currentTickets = attendeeViewModel.tickets.value
342
346
if (currentTickets != null ) {
343
- rootView.paymentSelector .isVisible = safeArgs.amount > 0
347
+ rootView.paymentSelectorContainer .isVisible = safeArgs.amount > 0
344
348
345
349
ticketsRecyclerAdapter.addAll(currentTickets)
346
350
attendeeRecyclerAdapter.addAllTickets(currentTickets)
@@ -528,59 +532,44 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
528
532
}
529
533
530
534
private fun setupPaymentOptions (event : Event ) {
531
- val paymentOptions = ArrayList <String >()
532
- if (event.canPayByPaypal)
533
- paymentOptions.add(getString(R .string.paypal))
534
- if (event.canPayByStripe)
535
- paymentOptions.add(getString(R .string.stripe))
536
- if (event.canPayOnsite)
537
- paymentOptions.add(getString(R .string.on_site))
538
- if (event.canPayByBank)
539
- paymentOptions.add(getString(R .string.bank_transfer))
540
- if (event.canPayByCheque)
541
- paymentOptions.add(getString(R .string.cheque))
542
-
543
- rootView.paymentSelector.adapter = ArrayAdapter (requireContext(), android.R .layout.simple_spinner_dropdown_item,
544
- paymentOptions)
545
- rootView.paymentSelector.onItemSelectedListener = object : AdapterView .OnItemSelectedListener {
546
- override fun onNothingSelected (p0 : AdapterView <* >? ) { /* Do nothing*/ }
547
-
548
- override fun onItemSelected (p0 : AdapterView <* >? , p1 : View ? , position : Int , p3 : Long ) {
549
- attendeeViewModel.selectedPaymentOption = position
550
- when (position) {
551
- paymentOptions.indexOf(getString(R .string.stripe)) -> {
552
- rootView.stripePayment.isVisible = true
553
- rootView.offlinePayment.isVisible = false
554
- }
555
- paymentOptions.indexOf(getString(R .string.on_site)) -> {
556
- rootView.offlinePayment.isVisible = true
557
- rootView.stripePayment.isVisible = false
558
- rootView.offlinePaymentDescription.text = event.onsiteDetails
559
- }
560
- paymentOptions.indexOf(getString(R .string.bank_transfer)) -> {
561
- rootView.offlinePayment.isVisible = true
562
- rootView.stripePayment.isVisible = false
563
- rootView.offlinePaymentDescription.text = event.bankDetails
564
- }
565
- paymentOptions.indexOf(getString(R .string.cheque)) -> {
566
- rootView.offlinePayment.isVisible = true
567
- rootView.stripePayment.isVisible = false
568
- rootView.offlinePaymentDescription.text = event.chequeDetails
569
- }
570
- else -> {
571
- rootView.stripePayment.isVisible = false
572
- rootView.offlinePayment.isVisible = false
573
- }
535
+ rootView.paypalRadioButton.isVisible = event.canPayByPaypal
536
+ rootView.stripeRadioButton.isVisible = event.canPayByStripe
537
+ rootView.chequeRadioButton.isVisible = event.canPayByCheque
538
+ rootView.bankRadioButton.isVisible = event.canPayByBank
539
+ rootView.onSiteRadioButton.isVisible = event.canPayOnsite
540
+
541
+ rootView.paymentOptionsGroup.setOnCheckedChangeListener { group, checkedId ->
542
+ when (checkedId) {
543
+ R .id.stripeRadioButton -> {
544
+ rootView.stripePayment.isVisible = true
545
+ rootView.offlinePayment.isVisible = false
546
+ attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_STRIPE
547
+ }
548
+ R .id.onSiteRadioButton -> {
549
+ rootView.offlinePayment.isVisible = true
550
+ rootView.stripePayment.isVisible = false
551
+ rootView.offlinePaymentDescription.text = event.onsiteDetails
552
+ attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_ONSITE
553
+ }
554
+ R .id.bankRadioButton -> {
555
+ rootView.offlinePayment.isVisible = true
556
+ rootView.stripePayment.isVisible = false
557
+ rootView.offlinePaymentDescription.text = event.bankDetails
558
+ attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_BANK
559
+ }
560
+ R .id.chequeRadioButton -> {
561
+ rootView.offlinePayment.isVisible = true
562
+ rootView.stripePayment.isVisible = false
563
+ rootView.offlinePaymentDescription.text = event.chequeDetails
564
+ attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_CHEQUE
565
+ }
566
+ else -> {
567
+ rootView.stripePayment.isVisible = false
568
+ rootView.offlinePayment.isVisible = false
569
+ attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_PAYPAL
574
570
}
575
571
}
576
572
}
577
- if (attendeeViewModel.selectedPaymentOption != - 1 )
578
- rootView.paymentSelector.setSelection(attendeeViewModel.selectedPaymentOption)
579
-
580
- if (paymentOptions.size == 1 ) {
581
- rootView.paymentSelector.isVisible = false
582
- rootView.paymentTitle.text = " ${getString(R .string.payment)} ${paymentOptions[0 ]} "
583
- }
584
573
}
585
574
586
575
private fun setupCardNumber () {
@@ -674,12 +663,12 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
674
663
}
675
664
676
665
private fun checkPaymentOptions (): Boolean =
677
- when (rootView.paymentSelector.selectedItem.toString() ) {
678
- getString( R .string.paypal) -> {
666
+ when (attendeeViewModel.selectedPaymentMode ) {
667
+ PAYMENT_MODE_PAYPAL -> {
679
668
rootView.attendeeScrollView.longSnackbar(getString(R .string.paypal_payment_not_available))
680
669
false
681
670
}
682
- getString( R .string.stripe) -> {
671
+ PAYMENT_MODE_STRIPE -> {
683
672
card = Card .create(rootView.cardNumber.text.toString(), attendeeViewModel.monthSelectedPosition,
684
673
rootView.year.selectedItem.toString().toInt(), rootView.cvc.text.toString())
685
674
@@ -690,7 +679,11 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
690
679
true
691
680
}
692
681
}
693
- else -> true
682
+ PAYMENT_MODE_CHEQUE , PAYMENT_MODE_ONSITE , PAYMENT_MODE_FREE , PAYMENT_MODE_BANK -> true
683
+ else -> {
684
+ rootView.snackbar(getString(R .string.select_payment_option_message))
685
+ false
686
+ }
694
687
}
695
688
696
689
private fun checkRequiredFields (): Boolean {
@@ -704,7 +697,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
704
697
}
705
698
706
699
var checkStripeInfo = true
707
- if (safeArgs.amount != 0F && rootView.paymentSelector.selectedItem.toString() == getString( R .string.stripe) ) {
700
+ if (safeArgs.amount != 0F && attendeeViewModel.selectedPaymentMode == PAYMENT_MODE_STRIPE ) {
708
701
checkStripeInfo = rootView.cardNumber.checkEmpty() && rootView.cvc.checkEmpty()
709
702
}
710
703
@@ -750,7 +743,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
750
743
if (attendeeViewModel.areAttendeeEmailsValid(attendees)) {
751
744
val country = rootView.countryPicker.selectedItem.toString()
752
745
val paymentOption =
753
- if (safeArgs.amount != 0F ) getPaymentMode(rootView.paymentSelector.selectedItem.toString())
746
+ if (safeArgs.amount != 0F ) attendeeViewModel.selectedPaymentMode
754
747
else PAYMENT_MODE_FREE
755
748
val company = rootView.billingCompany.text.toString()
756
749
val city = rootView.billingCity.text.toString()
@@ -778,16 +771,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
778
771
})
779
772
}
780
773
781
- private fun getPaymentMode (paymentSelectedItem : String ): String =
782
- when (paymentSelectedItem) {
783
- getString(R .string.cheque) -> PAYMENT_MODE_CHEQUE
784
- getString(R .string.bank_transfer) -> PAYMENT_MODE_BANK
785
- getString(R .string.stripe) -> PAYMENT_MODE_STRIPE
786
- getString(R .string.paypal) -> PAYMENT_MODE_PAYPAL
787
- getString(R .string.on_site) -> PAYMENT_MODE_ONSITE
788
- else -> PAYMENT_MODE_FREE
789
- }
790
-
791
774
private fun showTicketSoldOutDialog (show : Boolean ) {
792
775
if (show) {
793
776
val builder = AlertDialog .Builder (requireContext())
0 commit comments