Skip to content

Commit f8d45aa

Browse files
anhanh11001iamareebjamal
authored andcommitted
feat: Add searchable spinner for country name (#2130)
Fixes: #2125
1 parent c6460e3 commit f8d45aa

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ dependencies {
217217
implementation "androidx.paging:paging-runtime:$paging_version"
218218
implementation "androidx.paging:paging-rxjava2:$paging_version"
219219

220+
// Searchable Spinner
221+
implementation 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'
222+
220223

221224
testImplementation 'junit:junit:4.12'
222225
testImplementation 'org.threeten:threetenbp:1.4.0'

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.yearText
5858
import kotlinx.android.synthetic.main.fragment_attendee.view.cardNumber
5959
import kotlinx.android.synthetic.main.fragment_attendee.view.acceptCheckbox
6060
import kotlinx.android.synthetic.main.fragment_attendee.view.countryPicker
61-
import kotlinx.android.synthetic.main.fragment_attendee.view.countryPickerContainer
6261
import kotlinx.android.synthetic.main.fragment_attendee.view.billingInfoContainer
6362
import kotlinx.android.synthetic.main.fragment_attendee.view.billingInfoCheckboxSection
6463
import kotlinx.android.synthetic.main.fragment_attendee.view.billingEnabledCheckbox
@@ -90,6 +89,7 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.signInText
9089
import kotlinx.android.synthetic.main.fragment_attendee.view.signInTextLayout
9190
import kotlinx.android.synthetic.main.fragment_attendee.view.signInLayout
9291
import kotlinx.android.synthetic.main.fragment_attendee.view.signOutLayout
92+
import kotlinx.android.synthetic.main.fragment_attendee.view.paymentTitle
9393
import org.fossasia.openevent.general.BuildConfig
9494
import org.fossasia.openevent.general.R
9595
import org.fossasia.openevent.general.auth.User
@@ -284,7 +284,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
284284
}
285285

286286
private fun setupCountDownTimer(orderExpiryTime: Int) {
287-
rootView.timeoutCounterLayout.visibility = View.VISIBLE
287+
rootView.timeoutCounterLayout.isVisible = true
288288
rootView.timeoutInfoTextView.text =
289289
getString(R.string.ticket_timeout_info_message, orderExpiryTime.toString())
290290

@@ -320,7 +320,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
320320

321321
attendeeViewModel.totalAmount.value = safeArgs.amount
322322
rootView.paymentSelectorContainer.isVisible = safeArgs.amount > 0
323-
rootView.countryPickerContainer.isVisible = safeArgs.amount > 0
324323
rootView.billingInfoCheckboxSection.isVisible = safeArgs.amount > 0
325324
rootView.amount.text = "Total: ${attendeeViewModel.paymentCurrency}${safeArgs.amount}"
326325

@@ -334,7 +333,7 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
334333
val currentTickets = attendeeViewModel.tickets.value
335334
val currentTotalPrice = safeArgs.amount
336335
if (currentTickets != null && currentTotalPrice != null) {
337-
rootView.paymentSelector.visibility = if (currentTotalPrice > 0) View.VISIBLE else View.GONE
336+
rootView.paymentSelector.isVisible = currentTotalPrice > 0
338337
rootView.amount.text = "Total: ${attendeeViewModel.paymentCurrency}$currentTotalPrice"
339338

340339
ticketsRecyclerAdapter.addAll(currentTickets)
@@ -524,7 +523,6 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
524523
attendeeViewModel.countryPosition = position
525524
}
526525
}
527-
rootView.countryPickerContainer.visibility = if (attendeeViewModel.singleTicket) View.VISIBLE else View.GONE
528526
}
529527

530528
private fun setupPaymentOptions(event: Event) {
@@ -549,33 +547,38 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
549547
attendeeViewModel.selectedPaymentOption = position
550548
when (position) {
551549
paymentOptions.indexOf(getString(R.string.stripe)) -> {
552-
rootView.stripePayment.visibility = View.VISIBLE
553-
rootView.offlinePayment.visibility = View.GONE
550+
rootView.stripePayment.isVisible = true
551+
rootView.offlinePayment.isVisible = false
554552
}
555553
paymentOptions.indexOf(getString(R.string.on_site)) -> {
556-
rootView.offlinePayment.visibility = View.VISIBLE
557-
rootView.stripePayment.visibility = View.GONE
554+
rootView.offlinePayment.isVisible = true
555+
rootView.stripePayment.isVisible = false
558556
rootView.offlinePaymentDescription.text = event.onsiteDetails
559557
}
560558
paymentOptions.indexOf(getString(R.string.bank_transfer)) -> {
561-
rootView.offlinePayment.visibility = View.VISIBLE
562-
rootView.stripePayment.visibility = View.GONE
559+
rootView.offlinePayment.isVisible = true
560+
rootView.stripePayment.isVisible = false
563561
rootView.offlinePaymentDescription.text = event.bankDetails
564562
}
565563
paymentOptions.indexOf(getString(R.string.cheque)) -> {
566-
rootView.offlinePayment.visibility = View.VISIBLE
567-
rootView.stripePayment.visibility = View.GONE
564+
rootView.offlinePayment.isVisible = true
565+
rootView.stripePayment.isVisible = false
568566
rootView.offlinePaymentDescription.text = event.chequeDetails
569567
}
570568
else -> {
571-
rootView.stripePayment.visibility = View.GONE
572-
rootView.offlinePayment.visibility = View.GONE
569+
rootView.stripePayment.isVisible = false
570+
rootView.offlinePayment.isVisible = false
573571
}
574572
}
575573
}
576574
}
577575
if (attendeeViewModel.selectedPaymentOption != -1)
578576
rootView.paymentSelector.setSelection(attendeeViewModel.selectedPaymentOption)
577+
578+
if (paymentOptions.size == 1) {
579+
rootView.paymentSelector.isVisible = false
580+
rootView.paymentTitle.text = "${getString(R.string.payment)} ${paymentOptions[0]}"
581+
}
579582
}
580583

581584
private fun setupCardNumber() {
@@ -605,20 +608,21 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
605608
}
606609

607610
private fun setupMonthOptions() {
608-
val month = ArrayList<String>()
609-
month.add(getString(R.string.month_string))
610-
month.add(getString(R.string.january))
611-
month.add(getString(R.string.february))
612-
month.add(getString(R.string.march))
613-
month.add(getString(R.string.april))
614-
month.add(getString(R.string.may))
615-
month.add(getString(R.string.june))
616-
month.add(getString(R.string.july))
617-
month.add(getString(R.string.august))
618-
month.add(getString(R.string.september))
619-
month.add(getString(R.string.october))
620-
month.add(getString(R.string.november))
621-
month.add(getString(R.string.december))
611+
val month = mutableListOf(
612+
getString(R.string.month_string),
613+
getString(R.string.january),
614+
getString(R.string.february),
615+
getString(R.string.march),
616+
getString(R.string.april),
617+
getString(R.string.may),
618+
getString(R.string.june),
619+
getString(R.string.july),
620+
getString(R.string.august),
621+
getString(R.string.september),
622+
getString(R.string.october),
623+
getString(R.string.november),
624+
getString(R.string.december)
625+
)
622626

623627
rootView.month.adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_dropdown_item,
624628
month)
@@ -844,10 +848,10 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
844848

845849
private fun loadTicketDetailsTableUI(show: Boolean) {
846850
if (show) {
847-
rootView.ticketDetails.visibility = View.VISIBLE
851+
rootView.ticketDetails.isVisible = true
848852
rootView.ticketTableDetails.text = context?.getString(R.string.hide)
849853
} else {
850-
rootView.ticketDetails.visibility = View.GONE
854+
rootView.ticketDetails.isVisible = false
851855
rootView.ticketTableDetails.text = context?.getString(R.string.view)
852856
}
853857
}

app/src/main/res/layout/fragment_attendee.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@
476476
android:layout_height="wrap_content"
477477
android:textSize="@dimen/text_size_small"
478478
android:text="@string/country"/>
479-
<androidx.appcompat.widget.AppCompatSpinner
479+
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
480480
android:id="@+id/countryPicker"
481481
android:layout_width="match_parent"
482482
android:layout_height="wrap_content"
@@ -492,6 +492,7 @@
492492
android:layout_marginTop="@dimen/layout_margin_small"
493493
android:layout_marginBottom="@dimen/layout_margin_small">
494494
<TextView
495+
android:id="@+id/paymentTitle"
495496
android:layout_width="wrap_content"
496497
android:layout_height="wrap_content"
497498
android:textColor="@color/black"

0 commit comments

Comments
 (0)