diff --git a/app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeFragment.kt b/app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeFragment.kt index 578fdcc804..d1db793a10 100644 --- a/app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeFragment.kt +++ b/app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeFragment.kt @@ -43,7 +43,12 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.offlinePayment import kotlinx.android.synthetic.main.fragment_attendee.view.offlinePaymentDescription import kotlinx.android.synthetic.main.fragment_attendee.view.month import kotlinx.android.synthetic.main.fragment_attendee.view.monthText -import kotlinx.android.synthetic.main.fragment_attendee.view.paymentSelector +import kotlinx.android.synthetic.main.fragment_attendee.view.paymentOptionsGroup +import kotlinx.android.synthetic.main.fragment_attendee.view.paypalRadioButton +import kotlinx.android.synthetic.main.fragment_attendee.view.stripeRadioButton +import kotlinx.android.synthetic.main.fragment_attendee.view.onSiteRadioButton +import kotlinx.android.synthetic.main.fragment_attendee.view.chequeRadioButton +import kotlinx.android.synthetic.main.fragment_attendee.view.bankRadioButton import kotlinx.android.synthetic.main.fragment_attendee.view.paymentSelectorContainer import kotlinx.android.synthetic.main.fragment_attendee.view.qty import kotlinx.android.synthetic.main.fragment_attendee.view.register @@ -87,7 +92,6 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.signInText import kotlinx.android.synthetic.main.fragment_attendee.view.signInTextLayout import kotlinx.android.synthetic.main.fragment_attendee.view.signInLayout import kotlinx.android.synthetic.main.fragment_attendee.view.signOutLayout -import kotlinx.android.synthetic.main.fragment_attendee.view.paymentTitle import kotlinx.android.synthetic.main.fragment_attendee.view.taxLayout import kotlinx.android.synthetic.main.fragment_attendee.view.taxPrice import kotlinx.android.synthetic.main.fragment_attendee.view.totalAmountLayout @@ -340,7 +344,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment { val currentTickets = attendeeViewModel.tickets.value if (currentTickets != null) { - rootView.paymentSelector.isVisible = safeArgs.amount > 0 + rootView.paymentSelectorContainer.isVisible = safeArgs.amount > 0 ticketsRecyclerAdapter.addAll(currentTickets) attendeeRecyclerAdapter.addAllTickets(currentTickets) @@ -528,59 +532,44 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment { } private fun setupPaymentOptions(event: Event) { - val paymentOptions = ArrayList() - if (event.canPayByPaypal) - paymentOptions.add(getString(R.string.paypal)) - if (event.canPayByStripe) - paymentOptions.add(getString(R.string.stripe)) - if (event.canPayOnsite) - paymentOptions.add(getString(R.string.on_site)) - if (event.canPayByBank) - paymentOptions.add(getString(R.string.bank_transfer)) - if (event.canPayByCheque) - paymentOptions.add(getString(R.string.cheque)) - - rootView.paymentSelector.adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_dropdown_item, - paymentOptions) - rootView.paymentSelector.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onNothingSelected(p0: AdapterView<*>?) { /*Do nothing*/ } - - override fun onItemSelected(p0: AdapterView<*>?, p1: View?, position: Int, p3: Long) { - attendeeViewModel.selectedPaymentOption = position - when (position) { - paymentOptions.indexOf(getString(R.string.stripe)) -> { - rootView.stripePayment.isVisible = true - rootView.offlinePayment.isVisible = false - } - paymentOptions.indexOf(getString(R.string.on_site)) -> { - rootView.offlinePayment.isVisible = true - rootView.stripePayment.isVisible = false - rootView.offlinePaymentDescription.text = event.onsiteDetails - } - paymentOptions.indexOf(getString(R.string.bank_transfer)) -> { - rootView.offlinePayment.isVisible = true - rootView.stripePayment.isVisible = false - rootView.offlinePaymentDescription.text = event.bankDetails - } - paymentOptions.indexOf(getString(R.string.cheque)) -> { - rootView.offlinePayment.isVisible = true - rootView.stripePayment.isVisible = false - rootView.offlinePaymentDescription.text = event.chequeDetails - } - else -> { - rootView.stripePayment.isVisible = false - rootView.offlinePayment.isVisible = false - } + rootView.paypalRadioButton.isVisible = event.canPayByPaypal + rootView.stripeRadioButton.isVisible = event.canPayByStripe + rootView.chequeRadioButton.isVisible = event.canPayByCheque + rootView.bankRadioButton.isVisible = event.canPayByBank + rootView.onSiteRadioButton.isVisible = event.canPayOnsite + + rootView.paymentOptionsGroup.setOnCheckedChangeListener { group, checkedId -> + when (checkedId) { + R.id.stripeRadioButton -> { + rootView.stripePayment.isVisible = true + rootView.offlinePayment.isVisible = false + attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_STRIPE + } + R.id.onSiteRadioButton -> { + rootView.offlinePayment.isVisible = true + rootView.stripePayment.isVisible = false + rootView.offlinePaymentDescription.text = event.onsiteDetails + attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_ONSITE + } + R.id.bankRadioButton -> { + rootView.offlinePayment.isVisible = true + rootView.stripePayment.isVisible = false + rootView.offlinePaymentDescription.text = event.bankDetails + attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_BANK + } + R.id.chequeRadioButton -> { + rootView.offlinePayment.isVisible = true + rootView.stripePayment.isVisible = false + rootView.offlinePaymentDescription.text = event.chequeDetails + attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_CHEQUE + } + else -> { + rootView.stripePayment.isVisible = false + rootView.offlinePayment.isVisible = false + attendeeViewModel.selectedPaymentMode = PAYMENT_MODE_PAYPAL } } } - if (attendeeViewModel.selectedPaymentOption != -1) - rootView.paymentSelector.setSelection(attendeeViewModel.selectedPaymentOption) - - if (paymentOptions.size == 1) { - rootView.paymentSelector.isVisible = false - rootView.paymentTitle.text = "${getString(R.string.payment)} ${paymentOptions[0]}" - } } private fun setupCardNumber() { @@ -674,12 +663,12 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment { } private fun checkPaymentOptions(): Boolean = - when (rootView.paymentSelector.selectedItem.toString()) { - getString(R.string.paypal) -> { + when (attendeeViewModel.selectedPaymentMode) { + PAYMENT_MODE_PAYPAL -> { rootView.attendeeScrollView.longSnackbar(getString(R.string.paypal_payment_not_available)) false } - getString(R.string.stripe) -> { + PAYMENT_MODE_STRIPE -> { card = Card.create(rootView.cardNumber.text.toString(), attendeeViewModel.monthSelectedPosition, rootView.year.selectedItem.toString().toInt(), rootView.cvc.text.toString()) @@ -690,7 +679,11 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment { true } } - else -> true + PAYMENT_MODE_CHEQUE, PAYMENT_MODE_ONSITE, PAYMENT_MODE_FREE, PAYMENT_MODE_BANK -> true + else -> { + rootView.snackbar(getString(R.string.select_payment_option_message)) + false + } } private fun checkRequiredFields(): Boolean { @@ -704,7 +697,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment { } var checkStripeInfo = true - if (safeArgs.amount != 0F && rootView.paymentSelector.selectedItem.toString() == getString(R.string.stripe)) { + if (safeArgs.amount != 0F && attendeeViewModel.selectedPaymentMode == PAYMENT_MODE_STRIPE) { checkStripeInfo = rootView.cardNumber.checkEmpty() && rootView.cvc.checkEmpty() } @@ -750,7 +743,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment { if (attendeeViewModel.areAttendeeEmailsValid(attendees)) { val country = rootView.countryPicker.selectedItem.toString() val paymentOption = - if (safeArgs.amount != 0F) getPaymentMode(rootView.paymentSelector.selectedItem.toString()) + if (safeArgs.amount != 0F) attendeeViewModel.selectedPaymentMode else PAYMENT_MODE_FREE val company = rootView.billingCompany.text.toString() val city = rootView.billingCity.text.toString() @@ -778,16 +771,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment { }) } - private fun getPaymentMode(paymentSelectedItem: String): String = - when (paymentSelectedItem) { - getString(R.string.cheque) -> PAYMENT_MODE_CHEQUE - getString(R.string.bank_transfer) -> PAYMENT_MODE_BANK - getString(R.string.stripe) -> PAYMENT_MODE_STRIPE - getString(R.string.paypal) -> PAYMENT_MODE_PAYPAL - getString(R.string.on_site) -> PAYMENT_MODE_ONSITE - else -> PAYMENT_MODE_FREE - } - private fun showTicketSoldOutDialog(show: Boolean) { if (show) { val builder = AlertDialog.Builder(requireContext()) diff --git a/app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeViewModel.kt b/app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeViewModel.kt index c4b54cdccb..da2fe8e163 100644 --- a/app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeViewModel.kt +++ b/app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeViewModel.kt @@ -96,7 +96,7 @@ class AttendeeViewModel( // Retained information var countryPosition: Int = -1 var ticketIdAndQty: List>? = null - var selectedPaymentOption: Int = -1 + var selectedPaymentMode: String = "" var singleTicket = false var monthSelectedPosition: Int = 0 var yearSelectedPosition: Int = 0 diff --git a/app/src/main/res/drawable/ic_bank.xml b/app/src/main/res/drawable/ic_bank.xml new file mode 100644 index 0000000000..8deb1a15dd --- /dev/null +++ b/app/src/main/res/drawable/ic_bank.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_cash.xml b/app/src/main/res/drawable/ic_cash.xml new file mode 100644 index 0000000000..3f82a81588 --- /dev/null +++ b/app/src/main/res/drawable/ic_cash.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_cheque.xml b/app/src/main/res/drawable/ic_cheque.xml new file mode 100644 index 0000000000..5a5a68a5a0 --- /dev/null +++ b/app/src/main/res/drawable/ic_cheque.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_credit_card.xml b/app/src/main/res/drawable/ic_credit_card.xml new file mode 100644 index 0000000000..da14575092 --- /dev/null +++ b/app/src/main/res/drawable/ic_credit_card.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_paypal.xml b/app/src/main/res/drawable/ic_paypal.xml new file mode 100644 index 0000000000..ee54e8e41c --- /dev/null +++ b/app/src/main/res/drawable/ic_paypal.xml @@ -0,0 +1,5 @@ + + + + diff --git a/app/src/main/res/layout/fragment_attendee.xml b/app/src/main/res/layout/fragment_attendee.xml index 8f43e5fad7..72ce1c0532 100644 --- a/app/src/main/res/layout/fragment_attendee.xml +++ b/app/src/main/res/layout/fragment_attendee.xml @@ -542,10 +542,51 @@ android:textColor="@color/black" android:textSize="@dimen/heading_text_size" android:text="@string/payment"/> - + android:layout_height="wrap_content"> + + + + + + From: %1$s From: %1$s, %2$s by %1$s + Debit/Credit Card + Please select a payment option for this order