Skip to content

Commit 526b95c

Browse files
anhanh11001iamareebjamal
authored andcommitted
feat: Turn spinner into radio button for payment options (#2211)
Fixes: #2210
1 parent e662579 commit 526b95c

File tree

9 files changed

+139
-73
lines changed

9 files changed

+139
-73
lines changed

app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeFragment.kt

Lines changed: 52 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.offlinePayment
4343
import kotlinx.android.synthetic.main.fragment_attendee.view.offlinePaymentDescription
4444
import kotlinx.android.synthetic.main.fragment_attendee.view.month
4545
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
4752
import kotlinx.android.synthetic.main.fragment_attendee.view.paymentSelectorContainer
4853
import kotlinx.android.synthetic.main.fragment_attendee.view.qty
4954
import kotlinx.android.synthetic.main.fragment_attendee.view.register
@@ -87,7 +92,6 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.signInText
8792
import kotlinx.android.synthetic.main.fragment_attendee.view.signInTextLayout
8893
import kotlinx.android.synthetic.main.fragment_attendee.view.signInLayout
8994
import kotlinx.android.synthetic.main.fragment_attendee.view.signOutLayout
90-
import kotlinx.android.synthetic.main.fragment_attendee.view.paymentTitle
9195
import kotlinx.android.synthetic.main.fragment_attendee.view.taxLayout
9296
import kotlinx.android.synthetic.main.fragment_attendee.view.taxPrice
9397
import kotlinx.android.synthetic.main.fragment_attendee.view.totalAmountLayout
@@ -340,7 +344,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
340344

341345
val currentTickets = attendeeViewModel.tickets.value
342346
if (currentTickets != null) {
343-
rootView.paymentSelector.isVisible = safeArgs.amount > 0
347+
rootView.paymentSelectorContainer.isVisible = safeArgs.amount > 0
344348

345349
ticketsRecyclerAdapter.addAll(currentTickets)
346350
attendeeRecyclerAdapter.addAllTickets(currentTickets)
@@ -528,59 +532,44 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
528532
}
529533

530534
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
574570
}
575571
}
576572
}
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-
}
584573
}
585574

586575
private fun setupCardNumber() {
@@ -674,12 +663,12 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
674663
}
675664

676665
private fun checkPaymentOptions(): Boolean =
677-
when (rootView.paymentSelector.selectedItem.toString()) {
678-
getString(R.string.paypal) -> {
666+
when (attendeeViewModel.selectedPaymentMode) {
667+
PAYMENT_MODE_PAYPAL -> {
679668
rootView.attendeeScrollView.longSnackbar(getString(R.string.paypal_payment_not_available))
680669
false
681670
}
682-
getString(R.string.stripe) -> {
671+
PAYMENT_MODE_STRIPE -> {
683672
card = Card.create(rootView.cardNumber.text.toString(), attendeeViewModel.monthSelectedPosition,
684673
rootView.year.selectedItem.toString().toInt(), rootView.cvc.text.toString())
685674

@@ -690,7 +679,11 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
690679
true
691680
}
692681
}
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+
}
694687
}
695688

696689
private fun checkRequiredFields(): Boolean {
@@ -704,7 +697,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
704697
}
705698

706699
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) {
708701
checkStripeInfo = rootView.cardNumber.checkEmpty() && rootView.cvc.checkEmpty()
709702
}
710703

@@ -750,7 +743,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
750743
if (attendeeViewModel.areAttendeeEmailsValid(attendees)) {
751744
val country = rootView.countryPicker.selectedItem.toString()
752745
val paymentOption =
753-
if (safeArgs.amount != 0F) getPaymentMode(rootView.paymentSelector.selectedItem.toString())
746+
if (safeArgs.amount != 0F) attendeeViewModel.selectedPaymentMode
754747
else PAYMENT_MODE_FREE
755748
val company = rootView.billingCompany.text.toString()
756749
val city = rootView.billingCity.text.toString()
@@ -778,16 +771,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
778771
})
779772
}
780773

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-
791774
private fun showTicketSoldOutDialog(show: Boolean) {
792775
if (show) {
793776
val builder = AlertDialog.Builder(requireContext())

app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class AttendeeViewModel(
9696
// Retained information
9797
var countryPosition: Int = -1
9898
var ticketIdAndQty: List<Triple<Int, Int, Float>>? = null
99-
var selectedPaymentOption: Int = -1
99+
var selectedPaymentMode: String = ""
100100
var singleTicket = false
101101
var monthSelectedPosition: Int = 0
102102
var yearSelectedPosition: Int = 0

app/src/main/res/drawable/ic_bank.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<vector android:height="24dp" android:viewportHeight="40"
2+
android:viewportWidth="40" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<path android:fillColor="@color/greyMore" android:pathData="M20.39,0.08l13.38,6L38.9,8.39a1.8,1.8 0,0 1,1.15 2,1.83 1.83,0 0,1 -1.93,1.48H24.6c-7.41,0 -14.81,0 -22.22,0a2.11,2.11 0,0 1,-2.3 -1.44V9.69a2.44,2.44 0,0 1,1.5 -1.46c2.64,-1.16 5.27,-2.36 7.9,-3.54L19.77,0.08Z"/>
4+
<path android:fillColor="@color/greyMore" android:pathData="M0.08,37.89a2.06,2.06 0,0 1,2.24 -1.48q17.81,0 35.62,0a3,3 0,0 1,0.92 0.12,1.8 1.8,0 0,1 1.2,1.89 1.84,1.84 0,0 1,-1.68 1.63H37.9q-17.73,0 -35.46,0A2.19,2.19 0,0 1,0.08 38.67Z"/>
5+
<path android:fillColor="@color/greyMore" android:pathData="M20.08,35.33L4.34,35.33a1.81,1.81 0,1 1,-0.2 -3.61c0.41,0 0.49,-0.14 0.49,-0.52q0,-7.69 0,-15.39c0,-0.37 -0.09,-0.5 -0.47,-0.49a0.86,0.86 0,0 1,-0.89 -0.85,0.9 0.9,0 0,1 0.86,-0.93 4.11,4.11 0,0 1,0.43 0h31a2.88,2.88 0,0 1,0.58 0,0.87 0.87,0 0,1 0.69,0.92 0.89,0.89 0,0 1,-0.79 0.84c-0.57,0.07 -0.57,0.07 -0.57,0.66q0,7.61 0,15.23c0,0.35 0.06,0.5 0.46,0.5a1.81,1.81 0,1 1,-0.07 3.61L20.08,35.3ZM8.28,15.33c0,0.17 0,0.29 0,0.4q0,7.79 0,15.57c0,0.31 0.09,0.4 0.4,0.4q2.34,0 4.68,0c0.32,0 0.39,-0.11 0.39,-0.41q0,-7.79 0,-15.57c0,-0.31 -0.09,-0.4 -0.4,-0.4 -1.43,0 -2.86,0 -4.29,0ZM17.37,15.33L17.37,31.67l0.17,0h5c0.3,0 0.29,-0.17 0.29,-0.38q0,-7.81 0,-15.61c0,-0.33 -0.12,-0.39 -0.41,-0.38 -1.33,0 -2.65,0 -4,0ZM26.44,31.67 L26.83,31.67c1.55,0 3.1,0 4.65,0 0.33,0 0.41,-0.11 0.41,-0.42q0,-7.77 0,-15.54c0,-0.33 -0.1,-0.42 -0.42,-0.42 -1.55,0 -3.1,0 -4.65,0l-0.38,0Z"/>
6+
</vector>

app/src/main/res/drawable/ic_cash.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<vector android:height="24dp" android:viewportHeight="40"
2+
android:viewportWidth="40" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<path android:fillColor="@color/greyMore" android:pathData="M0.08,13.75l0.47,0H40.05v20H0.62l-0.54,0ZM38.24,31.9c0,-0.2 0,-0.32 0,-0.45q0,-7.73 0,-15.47c0,-0.37 -0.11,-0.45 -0.46,-0.45H2.34l-0.45,0v0.5q0,7.65 0,15.31c0,0.52 0,0.52 0.53,0.52H38.24Z"/>
4+
<path android:fillColor="@color/greyMore" android:pathData="M1.95,10.09H38.26c0,0.55 0,1.09 0,1.63 0,0.06 -0.13,0.14 -0.21,0.16a1.4,1.4 0,0 1,-0.35 0H2.46c-0.57,0 -0.57,0 -0.57,-0.57 0,-0.38 0,-0.75 0,-1.13A0.47,0.47 0,0 1,1.95 10.09Z"/>
5+
<path android:fillColor="@color/greyMore" android:pathData="M36.41,6.48V8.24H3.75V6.48Z"/>
6+
<path android:fillColor="@color/greyMore" android:pathData="M20.29,18.57a2.7,2.7 0,0 1,2.08 1.59l-1.16,0.66 -0.29,-0.37a1.44,1.44 0,0 0,-1.6 -0.53,1.06 1.06,0 0,0 -0.8,0.87 1,1 0,0 0,0.44 1c0.39,0.25 0.82,0.45 1.23,0.67s0.72,0.36 1.06,0.57a2.63,2.63 0,0 1,1.31 2.71,2.75 2.75,0 0,1 -1.76,2.35c-0.44,0.18 -0.57,0.4 -0.51,0.83 0,0.09 0,0.18 0,0.27 0,0.32 -0.1,0.4 -0.4,0.39 -0.81,0 -0.7,0.07 -0.68,-0.69 0,-0.43 -0.12,-0.59 -0.54,-0.7a2.9,2.9 0,0 1,-2.2 -2.67l1.26,-0.27c0.17,0.35 0.29,0.68 0.47,1a1.61,1.61 0,0 0,2 0.61,1.48 1.48,0 0,0 0.9,-1.79 1.56,1.56 0,0 0,-0.54 -0.77,11.54 11.54,0 0,0 -1.35,-0.77c-0.3,-0.16 -0.6,-0.31 -0.89,-0.48a2.28,2.28 0,0 1,-1.22 -2.23,2.19 2.19,0 0,1 1.52,-2.07 0.74,0.74 0,0 0,0.58 -0.89c0,-0.54 0,-0.54 0.54,-0.54h0.52Z"/>
7+
</vector>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<vector android:height="24dp" android:viewportHeight="40"
2+
android:viewportWidth="40" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<path android:fillColor="@color/greyMore" android:pathData="M0.08,4.22H39v0.44q0,5.76 0,11.52a0.54,0.54 0,0 1,-0.35 0.56c-0.6,0.3 -1.19,0.62 -1.86,1V8.8H2.31V25.32H30.65c-0.53,0.69 -1,1.38 -1.58,2.06a0.57,0.57 0,0 1,-0.29 0.14,1.06 1.06,0 0,1 -0.27,0H0.54l-0.47,0Z"/>
4+
<path android:fillColor="@color/greyMore" android:pathData="M4.23,17.87V15.49H32v2.38Z"/>
5+
<path android:fillColor="@color/greyMore" android:pathData="M31,35.93 L26.8,33.1c0.06,-0.11 0.11,-0.21 0.17,-0.3l3.2,-4.8a7,7 0,0 1,2.12 -1.81,0.36 0.36,0 0,1 0.31,0.05c0.86,0.56 1.72,1.13 2.56,1.71a0.44,0.44 0,0 1,0.14 0.37,7.62 7.62,0 0,1 -1.18,3c-1,1.39 -1.9,2.83 -2.84,4.24Z"/>
6+
<path android:fillColor="@color/greyMore" android:pathData="M4.23,13.58V11.19H19.5v2.39Z"/>
7+
<path android:fillColor="@color/greyMore" android:pathData="M35.92,27.58l-1.36,-0.9 0.21,-0.34 2.68,-4A0.66,0.66 0,0 1,38 22a0.76,0.76 0,0 0,0.62 -0.89,0.81 0.81,0 0,0 -0.92,-0.66 0.74,0.74 0,0 0,-0.64 0.91,0.8 0.8,0 0,1 -0.19,0.77L34.24,26l-0.24,0.34c-0.39,-0.26 -0.78,-0.5 -1.14,-0.77a0.36,0.36 0,0 1,-0.1 -0.31q0.64,-2 1.3,-4.08a0.43,0.43 0,0 1,0.19 -0.22l5.68,-3a0.49,0.49 0,0 1,0.14 0c-0.08,1 -0.16,2 -0.25,3s-0.19,2.26 -0.3,3.38a0.72,0.72 0,0 1,-0.16 0.45C38.22,25.69 37.08,26.62 35.92,27.58Z"/>
8+
</vector>

0 commit comments

Comments
 (0)