@@ -71,6 +71,15 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.city
71
71
import kotlinx.android.synthetic.main.fragment_attendee.view.company
72
72
import kotlinx.android.synthetic.main.fragment_attendee.view.taxId
73
73
import kotlinx.android.synthetic.main.fragment_attendee.view.address
74
+ import kotlinx.android.synthetic.main.fragment_attendee.view.firstNameLayout
75
+ import kotlinx.android.synthetic.main.fragment_attendee.view.lastNameLayout
76
+ import kotlinx.android.synthetic.main.fragment_attendee.view.emailLayout
77
+ import kotlinx.android.synthetic.main.fragment_attendee.view.companyLayout
78
+ import kotlinx.android.synthetic.main.fragment_attendee.view.addressLayout
79
+ import kotlinx.android.synthetic.main.fragment_attendee.view.cvcLayout
80
+ import kotlinx.android.synthetic.main.fragment_attendee.view.cityLayout
81
+ import kotlinx.android.synthetic.main.fragment_attendee.view.postalCodeLayout
82
+ import kotlinx.android.synthetic.main.fragment_attendee.view.cardNumberLayout
74
83
import org.fossasia.openevent.general.BuildConfig
75
84
import org.fossasia.openevent.general.R
76
85
import org.fossasia.openevent.general.attendees.forms.CustomForm
@@ -87,6 +96,9 @@ import org.fossasia.openevent.general.utils.extensions.nonNull
87
96
import org.fossasia.openevent.general.utils.nullToEmpty
88
97
import org.koin.androidx.viewmodel.ext.android.viewModel
89
98
import org.fossasia.openevent.general.utils.Utils.setToolbar
99
+ import org.fossasia.openevent.general.utils.setRequired
100
+ import org.fossasia.openevent.general.utils.checkEmpty
101
+ import org.fossasia.openevent.general.utils.checkValidEmail
90
102
import org.jetbrains.anko.design.longSnackbar
91
103
import org.jetbrains.anko.design.snackbar
92
104
import java.util.Calendar
@@ -247,6 +259,9 @@ class AttendeeFragment : Fragment() {
247
259
}
248
260
249
261
private fun setupUser () {
262
+ rootView.firstNameLayout.setRequired()
263
+ rootView.lastNameLayout.setRequired()
264
+ rootView.emailLayout.setRequired()
250
265
attendeeViewModel.user
251
266
.nonNull()
252
267
.observe(viewLifecycleOwner, Observer { user ->
@@ -352,6 +367,10 @@ class AttendeeFragment : Fragment() {
352
367
}
353
368
354
369
private fun setupBillingInfo () {
370
+ rootView.companyLayout.setRequired()
371
+ rootView.addressLayout.setRequired()
372
+ rootView.cityLayout.setRequired()
373
+ rootView.postalCodeLayout.setRequired()
355
374
rootView.billingInfoContainer.isVisible = rootView.billingEnabledCheckbox.isChecked
356
375
attendeeViewModel.billingEnabled = rootView.billingEnabledCheckbox.isChecked
357
376
rootView.billingEnabledCheckbox.setOnCheckedChangeListener { _, isChecked ->
@@ -433,6 +452,8 @@ class AttendeeFragment : Fragment() {
433
452
}
434
453
435
454
private fun setupCardNumber () {
455
+ rootView.cardNumberLayout.setRequired()
456
+ rootView.cvcLayout.setRequired()
436
457
rootView.cardNumber.addTextChangedListener(object : TextWatcher {
437
458
override fun afterTextChanged (s : Editable ? ) { /* Do Nothing*/ }
438
459
override fun beforeTextChanged (s : CharSequence? , start : Int , count : Int , after : Int ) { /* Do Nothing*/ }
@@ -510,7 +531,6 @@ class AttendeeFragment : Fragment() {
510
531
private fun setupYearOptions () {
511
532
val year = ArrayList <String >()
512
533
val currentYear = Calendar .getInstance().get(Calendar .YEAR )
513
- year.add(getString(R .string.year_string))
514
534
val a = currentYear + 20
515
535
for (i in currentYear.. a) {
516
536
year.add(i.toString())
@@ -535,7 +555,6 @@ class AttendeeFragment : Fragment() {
535
555
536
556
private fun setupCardType () {
537
557
val cardType = ArrayList <String >()
538
- cardType.add(getString(R .string.select_card))
539
558
cardType.add(getString(R .string.american_express_pay_message))
540
559
cardType.add(getString(R .string.mastercard_pay_message))
541
560
cardType.add(getString(R .string.visa_pay_message))
@@ -606,13 +625,38 @@ class AttendeeFragment : Fragment() {
606
625
rootView.attendeeScrollView.longSnackbar(getString(R .string.paypal_payment_not_available))
607
626
false
608
627
}
609
- getString(R .string.cheque), getString(R .string.on_site), getString(R .string.bank_transfer) -> {
610
- rootView.attendeeScrollView.longSnackbar(getString(R .string.offline_payment_message))
611
- false
612
- }
613
628
else -> true
614
629
}
615
630
631
+ private fun checkRequiredFields (): Boolean {
632
+ val checkBasicInfo = rootView.firstName.checkEmpty() && rootView.lastName.checkEmpty() &&
633
+ rootView.email.checkEmpty() && rootView.email.checkEmpty() && rootView.email.checkValidEmail()
634
+
635
+ var checkBillingInfo = true
636
+ if (rootView.billingEnabledCheckbox.isChecked) {
637
+ checkBillingInfo = rootView.company.checkEmpty() && rootView.company.checkEmpty() &&
638
+ rootView.address.checkEmpty() && rootView.city.checkEmpty() && rootView.postalCode.checkEmpty()
639
+ }
640
+
641
+ var checkStripeInfo = true
642
+ if (totalAmount != 0F && rootView.paymentSelector.selectedItem.toString() == getString(R .string.stripe)) {
643
+ checkStripeInfo = rootView.cardNumber.checkEmpty() && rootView.cvc.checkEmpty()
644
+ }
645
+
646
+ return checkBasicInfo && checkBillingInfo && checkAttendeesInfo() && checkStripeInfo
647
+ }
648
+
649
+ private fun checkAttendeesInfo (): Boolean {
650
+ var valid = true
651
+ for (pos in 0 .. attendeeRecyclerAdapter.itemCount) {
652
+ val viewHolderItem = rootView.attendeeRecycler.findViewHolderForAdapterPosition(pos)
653
+ if (viewHolderItem is AttendeeViewHolder ) {
654
+ if (! viewHolderItem.checkValidFields()) valid = false
655
+ }
656
+ }
657
+ return valid
658
+ }
659
+
616
660
private fun setupRegisterOrder () {
617
661
rootView.register.setOnClickListener {
618
662
if (! isNetworkConnected(context)) {
@@ -624,6 +668,8 @@ class AttendeeFragment : Fragment() {
624
668
return @setOnClickListener
625
669
}
626
670
671
+ if (! checkRequiredFields()) return @setOnClickListener
672
+
627
673
if (attendeeViewModel.totalAmount.value != 0F && ! checkPaymentOptions()) return @setOnClickListener
628
674
629
675
val builder = AlertDialog .Builder (requireContext())
@@ -634,8 +680,9 @@ class AttendeeFragment : Fragment() {
634
680
635
681
if (attendeeViewModel.areAttendeeEmailsValid(attendees)) {
636
682
val country = rootView.countryPicker.selectedItem.toString()
637
- val paymentOption = if (totalAmount != 0F ) rootView.paymentSelector.selectedItem.toString()
638
- else getString(R .string.free)
683
+ val paymentOption =
684
+ if (totalAmount != 0F ) getPaymentMode(rootView.paymentSelector.selectedItem.toString())
685
+ else PAYMENT_MODE_FREE
639
686
val company = rootView.company.text.toString()
640
687
val city = rootView.city.text.toString()
641
688
val taxId = rootView.taxId.text.toString()
@@ -676,6 +723,16 @@ class AttendeeFragment : Fragment() {
676
723
})
677
724
}
678
725
726
+ private fun getPaymentMode (paymentSelectedItem : String ): String =
727
+ when (paymentSelectedItem) {
728
+ getString(R .string.cheque) -> PAYMENT_MODE_CHEQUE
729
+ getString(R .string.bank_transfer) -> PAYMENT_MODE_BANK
730
+ getString(R .string.stripe) -> PAYMENT_MODE_STRIPE
731
+ getString(R .string.paypal) -> PAYMENT_MODE_PAYPAL
732
+ getString(R .string.on_site) -> PAYMENT_MODE_ONSITE
733
+ else -> PAYMENT_MODE_FREE
734
+ }
735
+
679
736
private fun showTicketSoldOutDialog (show : Boolean ) {
680
737
if (show) {
681
738
val builder = AlertDialog .Builder (requireContext())
0 commit comments