@@ -41,7 +41,6 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.accept
41
41
import kotlinx.android.synthetic.main.fragment_attendee.view.amount
42
42
import kotlinx.android.synthetic.main.fragment_attendee.view.attendeeInformation
43
43
import kotlinx.android.synthetic.main.fragment_attendee.view.attendeeRecycler
44
- import kotlinx.android.synthetic.main.fragment_attendee.view.cardSelector
45
44
import kotlinx.android.synthetic.main.fragment_attendee.view.eventName
46
45
import kotlinx.android.synthetic.main.fragment_attendee.view.offlinePayment
47
46
import kotlinx.android.synthetic.main.fragment_attendee.view.offlinePaymentDescription
@@ -50,10 +49,8 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.monthText
50
49
import kotlinx.android.synthetic.main.fragment_attendee.view.moreAttendeeInformation
51
50
import kotlinx.android.synthetic.main.fragment_attendee.view.paymentSelector
52
51
import kotlinx.android.synthetic.main.fragment_attendee.view.paymentSelectorContainer
53
- import kotlinx.android.synthetic.main.fragment_attendee.view.progressBarAttendee
54
52
import kotlinx.android.synthetic.main.fragment_attendee.view.qty
55
53
import kotlinx.android.synthetic.main.fragment_attendee.view.register
56
- import kotlinx.android.synthetic.main.fragment_attendee.view.selectCard
57
54
import kotlinx.android.synthetic.main.fragment_attendee.view.signOut
58
55
import kotlinx.android.synthetic.main.fragment_attendee.view.stripePayment
59
56
import kotlinx.android.synthetic.main.fragment_attendee.view.ticketDetails
@@ -67,6 +64,7 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.acceptCheckbox
67
64
import kotlinx.android.synthetic.main.fragment_attendee.view.countryPicker
68
65
import kotlinx.android.synthetic.main.fragment_attendee.view.countryPickerContainer
69
66
import kotlinx.android.synthetic.main.fragment_attendee.view.billingInfoContainer
67
+ import kotlinx.android.synthetic.main.fragment_attendee.view.billingInfoCheckboxSection
70
68
import kotlinx.android.synthetic.main.fragment_attendee.view.billingEnabledCheckbox
71
69
import kotlinx.android.synthetic.main.fragment_attendee.view.city
72
70
import kotlinx.android.synthetic.main.fragment_attendee.view.company
@@ -102,6 +100,7 @@ import org.fossasia.openevent.general.utils.nullToEmpty
102
100
import org.koin.androidx.viewmodel.ext.android.viewModel
103
101
import org.fossasia.openevent.general.ComplexBackPressFragment
104
102
import org.fossasia.openevent.general.utils.Utils.setToolbar
103
+ import org.fossasia.openevent.general.utils.Utils.show
105
104
import org.fossasia.openevent.general.utils.setRequired
106
105
import org.fossasia.openevent.general.utils.checkEmpty
107
106
import org.fossasia.openevent.general.utils.checkValidEmail
@@ -157,15 +156,11 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
157
156
rootView.longSnackbar(it)
158
157
})
159
158
159
+ val progressDialog = Utils .progressDialog(context, getString(R .string.creating_order_message))
160
160
attendeeViewModel.progress
161
161
.nonNull()
162
162
.observe(viewLifecycleOwner, Observer {
163
- rootView.progressBarAttendee.isVisible = it
164
- rootView.register.isEnabled = ! it
165
- rootView.register.text = if (! it) getString(R .string.register) else " "
166
- rootView.register.backgroundTintList =
167
- if (it) resources.getColorStateList(R .color.grey)
168
- else resources.getColorStateList(R .color.colorAccent)
163
+ progressDialog.show(it)
169
164
})
170
165
171
166
rootView.sameBuyerCheckBox.setOnCheckedChangeListener { _, isChecked ->
@@ -190,7 +185,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
190
185
setupBillingInfo()
191
186
setupCountryOptions()
192
187
setupCardNumber()
193
- setupCardType()
194
188
setupMonthOptions()
195
189
setupYearOptions()
196
190
setupTermsAndCondition()
@@ -214,7 +208,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
214
208
override fun onResume () {
215
209
super .onResume()
216
210
if (! isNetworkConnected(context)) {
217
- rootView.progressBarAttendee.isVisible = false
218
211
rootView.attendeeScrollView.longSnackbar(getString(R .string.no_internet_connection_message))
219
212
}
220
213
}
@@ -324,8 +317,9 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
324
317
.nonNull()
325
318
.observe(viewLifecycleOwner, Observer {
326
319
totalAmount = it
327
- rootView.paymentSelectorContainer.visibility = if (it > 0 ) View .VISIBLE else View .GONE
328
- rootView.countryPickerContainer.visibility = if (it > 0 ) View .VISIBLE else View .GONE
320
+ rootView.paymentSelectorContainer.isVisible = it > 0
321
+ rootView.countryPickerContainer.isVisible = it > 0
322
+ rootView.billingInfoCheckboxSection.isVisible = it > 0
329
323
rootView.amount.text = " Total: ${attendeeViewModel.paymentCurrency}$it "
330
324
})
331
325
@@ -534,32 +528,18 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
534
528
535
529
override fun onTextChanged (s : CharSequence? , start : Int , before : Int , count : Int ) {
536
530
if (s == null || s.length < 3 ) {
537
- setCardSelectorAndError(0 , visibility = true , error = false )
531
+ setCardSelectorAndError(false )
538
532
return
539
533
}
540
534
val card = Utils .getCardType(s.toString())
541
535
if (card == Utils .cardType.NONE ) {
542
- setCardSelectorAndError(0 , visibility = true , error = true )
536
+ setCardSelectorAndError(true )
543
537
return
544
538
}
545
-
546
- val pos: Int = card.let {
547
- when (it) {
548
- Utils .cardType.AMERICAN_EXPRESS -> 1
549
- Utils .cardType.MASTER_CARD -> 2
550
- Utils .cardType.VISA -> 3
551
- Utils .cardType.DISCOVER -> 4
552
- Utils .cardType.DINERS_CLUB -> 5
553
- Utils .cardType.UNIONPAY -> 6
554
- else -> 0
555
- }
556
- }
557
- setCardSelectorAndError(pos, visibility = false , error = false )
539
+ setCardSelectorAndError(false )
558
540
}
559
541
560
- private fun setCardSelectorAndError (pos : Int , visibility : Boolean , error : Boolean ) {
561
- rootView.cardSelector.setSelection(pos, true )
562
- rootView.cardSelector.isVisible = visibility
542
+ private fun setCardSelectorAndError (error : Boolean ) {
563
543
if (error) {
564
544
rootView.cardNumber.error = " Invalid card number"
565
545
return
@@ -627,29 +607,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
627
607
rootView.year.setSelection(attendeeViewModel.yearSelectedPosition)
628
608
}
629
609
630
- private fun setupCardType () {
631
- val cardType = ArrayList <String >()
632
- cardType.add(getString(R .string.american_express_pay_message))
633
- cardType.add(getString(R .string.mastercard_pay_message))
634
- cardType.add(getString(R .string.visa_pay_message))
635
- cardType.add(getString(R .string.discover_pay_message))
636
- cardType.add(getString(R .string.diners_pay_message))
637
- cardType.add(getString(R .string.unionpay_pay_message))
638
-
639
- rootView.cardSelector.adapter = ArrayAdapter (requireContext(), android.R .layout.simple_spinner_dropdown_item,
640
- cardType)
641
- rootView.cardSelector.onItemSelectedListener = object : AdapterView .OnItemSelectedListener {
642
- override fun onNothingSelected (p0 : AdapterView <* >? ) { /* Do nothing */ }
643
-
644
- override fun onItemSelected (p0 : AdapterView <* >? , p1 : View ? , pos : Int , p3 : Long ) {
645
- attendeeViewModel.cardTypePosition = pos
646
- rootView.selectCard.text = cardType[pos]
647
- }
648
- }
649
-
650
- rootView.cardSelector.setSelection(attendeeViewModel.cardTypePosition)
651
- }
652
-
653
610
private fun setupTermsAndCondition () {
654
611
val paragraph = SpannableStringBuilder ()
655
612
val startText = getString(R .string.start_text)
@@ -742,37 +699,30 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
742
699
return @setOnClickListener
743
700
}
744
701
745
- if (! checkRequiredFields()) return @setOnClickListener
702
+ if (! checkRequiredFields()) {
703
+ rootView.snackbar(R .string.fill_required_fields_message)
704
+ return @setOnClickListener
705
+ }
746
706
747
707
if (attendeeViewModel.totalAmount.value != 0F && ! checkPaymentOptions()) return @setOnClickListener
748
708
749
- val builder = AlertDialog .Builder (requireContext())
750
- builder.setTitle(R .string.confirmation_dialog)
751
-
752
- builder.setPositiveButton(android.R .string.yes) { _, _ ->
753
- val attendees = attendeeViewModel.attendees
754
-
755
- if (attendeeViewModel.areAttendeeEmailsValid(attendees)) {
756
- val country = rootView.countryPicker.selectedItem.toString()
757
- val paymentOption =
758
- if (totalAmount != 0F ) getPaymentMode(rootView.paymentSelector.selectedItem.toString())
759
- else PAYMENT_MODE_FREE
760
- val company = rootView.company.text.toString()
761
- val city = rootView.city.text.toString()
762
- val taxId = rootView.taxId.text.toString()
763
- val address = rootView.address.text.toString()
764
- val postalCode = rootView.postalCode.text.toString()
765
- attendeeViewModel.createAttendees(attendees, country, company, taxId, address,
766
- city, postalCode, paymentOption)
767
- } else {
768
- rootView.attendeeScrollView.longSnackbar(getString(R .string.invalid_email_address_message))
769
- }
770
- }
771
-
772
- builder.setNegativeButton(android.R .string.no) { _, _ ->
773
- rootView.snackbar(getString(R .string.order_not_completed))
709
+ val attendees = attendeeViewModel.attendees
710
+
711
+ if (attendeeViewModel.areAttendeeEmailsValid(attendees)) {
712
+ val country = rootView.countryPicker.selectedItem.toString()
713
+ val paymentOption =
714
+ if (totalAmount != 0F ) getPaymentMode(rootView.paymentSelector.selectedItem.toString())
715
+ else PAYMENT_MODE_FREE
716
+ val company = rootView.company.text.toString()
717
+ val city = rootView.city.text.toString()
718
+ val taxId = rootView.taxId.text.toString()
719
+ val address = rootView.address.text.toString()
720
+ val postalCode = rootView.postalCode.text.toString()
721
+ attendeeViewModel.createAttendees(attendees, country, company, taxId, address,
722
+ city, postalCode, paymentOption)
723
+ } else {
724
+ rootView.attendeeScrollView.longSnackbar(getString(R .string.invalid_email_address_message))
774
725
}
775
- builder.show()
776
726
}
777
727
778
728
attendeeViewModel.isAttendeeCreated.observe(viewLifecycleOwner, Observer { isAttendeeCreated ->
@@ -820,9 +770,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
820
770
val card = Card (rootView.cardNumber.text.toString(), attendeeViewModel.monthSelectedPosition,
821
771
attendeeViewModel.yearSelectedPosition, rootView.cvc.text.toString())
822
772
823
- if (card.brand != null && card.brand != " Unknown" )
824
- rootView.selectCard.text = " Pay by ${card.brand} "
825
-
826
773
val validDetails: Boolean? = card.validateCard()
827
774
if (validDetails != null && ! validDetails)
828
775
rootView.snackbar(getString(R .string.invalid_card_data_message))
@@ -848,12 +795,25 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
848
795
attendeeViewModel.paymentCurrency = Currency .getInstance(event.paymentCurrency).symbol
849
796
ticketsRecyclerAdapter.setCurrency(attendeeViewModel.paymentCurrency)
850
797
851
- rootView.eventName.text = " ${event.name} - ${EventUtils .getFormattedDate(startsAt)} "
852
- rootView.time.text = dateString.append(EventUtils .getFormattedDate(startsAt))
853
- .append(" - " )
854
- .append(EventUtils .getFormattedDate(endsAt))
855
- .append(" • " )
856
- .append(EventUtils .getFormattedTime(startsAt))
798
+ rootView.eventName.text = event.name
799
+
800
+ val startDate = EventUtils .getFormattedDate(startsAt)
801
+ val endDate = EventUtils .getFormattedDate(endsAt)
802
+ dateString.append(startDate)
803
+ if (startDate == endDate) {
804
+ dateString.append(" • " )
805
+ .append(EventUtils .getFormattedTime(startsAt))
806
+ .append(" - " )
807
+ .append(EventUtils .getFormattedTime(endsAt))
808
+ } else {
809
+ dateString.append(" - " )
810
+ .append(EventUtils .getFormattedTime(startsAt))
811
+ .append(" • " )
812
+ .append(endDate)
813
+ .append(" - " )
814
+ .append(EventUtils .getFormattedTime(endsAt))
815
+ }
816
+ rootView.time.text = dateString
857
817
}
858
818
859
819
private fun loadUserUI (user : User ) {
0 commit comments