@@ -146,9 +146,7 @@ class AttendeeFragment : Fragment() {
146146 }
147147
148148 override fun onClick (widget : View ) {
149- context?.let {
150- Utils .openUrl(it, getString(R .string.terms_of_service))
151- }
149+ Utils .openUrl(requireContext(), getString(R .string.terms_of_service))
152150 }
153151 }
154152
@@ -159,9 +157,7 @@ class AttendeeFragment : Fragment() {
159157 }
160158
161159 override fun onClick (widget : View ) {
162- context?.let {
163- Utils .openUrl(it, getString(R .string.privacy_policy))
164- }
160+ Utils .openUrl(requireContext(), getString(R .string.privacy_policy))
165161 }
166162 }
167163
@@ -193,7 +189,7 @@ class AttendeeFragment : Fragment() {
193189 paymentOptions.add(getString(R .string.stripe))
194190 attendeeViewModel.paymentSelectorVisibility
195191 .nonNull()
196- .observe(this , Observer {
192+ .observe(viewLifecycleOwner , Observer {
197193 if (it) {
198194 rootView.paymentSelector.visibility = View .VISIBLE
199195 } else {
@@ -255,8 +251,9 @@ class AttendeeFragment : Fragment() {
255251 else -> 0
256252 }
257253 }
258- setCardSelectorAndError(pos, visibility = false , error = false )
254+ setCardSelectorAndError(pos, visibility = false , error = false )
259255 }
256+
260257 fun setCardSelectorAndError (pos : Int , visibility : Boolean , error : Boolean ) {
261258 rootView.cardSelector.setSelection(pos, true )
262259 rootView.cardSelector.isVisible = visibility
@@ -314,7 +311,7 @@ class AttendeeFragment : Fragment() {
314311 }
315312 attendeeViewModel.qtyList
316313 .nonNull()
317- .observe(this , Observer {
314+ .observe(viewLifecycleOwner , Observer {
318315 ticketsRecyclerAdapter.setQty(it)
319316 })
320317
@@ -329,40 +326,40 @@ class AttendeeFragment : Fragment() {
329326
330327 attendeeViewModel.ticketDetailsVisibility
331328 .nonNull()
332- .observe(this , Observer {
329+ .observe(viewLifecycleOwner , Observer {
333330 rootView.view.text = if (it) getString(R .string.hide) else getString(R .string.view)
334331 rootView.ticketDetails.visibility = if (it) View .VISIBLE else View .GONE
335332 })
336333
337334 attendeeViewModel.message
338335 .nonNull()
339- .observe(this , Observer {
336+ .observe(viewLifecycleOwner , Observer {
340337 Snackbar .make(rootView, it, Snackbar .LENGTH_LONG ).show()
341338 })
342339
343340 attendeeViewModel.progress
344341 .nonNull()
345- .observe(this , Observer {
342+ .observe(viewLifecycleOwner , Observer {
346343 rootView.progressBarAttendee.isVisible = it
347344 rootView.register.isEnabled = ! it
348345 })
349346
350347 attendeeViewModel.event
351348 .nonNull()
352- .observe(this , Observer {
349+ .observe(viewLifecycleOwner , Observer {
353350 loadEventDetails(it)
354351 })
355352
356353 attendeeViewModel.totalAmount
357354 .nonNull()
358- .observe(this , Observer {
355+ .observe(viewLifecycleOwner , Observer {
359356 amount = it
360357 })
361358
362359 attendeeRecyclerAdapter.eventId = eventId
363360 attendeeViewModel.tickets
364361 .nonNull()
365- .observe(this , Observer { tickets ->
362+ .observe(viewLifecycleOwner , Observer { tickets ->
366363 ticketsRecyclerAdapter.addAll(tickets)
367364 ticketsRecyclerAdapter.notifyDataSetChanged()
368365 if (! singleTicket)
@@ -377,21 +374,21 @@ class AttendeeFragment : Fragment() {
377374
378375 attendeeViewModel.totalQty
379376 .nonNull()
380- .observe(this , Observer {
377+ .observe(viewLifecycleOwner , Observer {
381378 rootView.qty.text = " — $it items"
382379 })
383380
384381 attendeeViewModel.countryVisibility
385382 .nonNull()
386- .observe(this , Observer {
383+ .observe(viewLifecycleOwner , Observer {
387384 if (singleTicket) {
388385 rootView.countryPickerContainer.visibility = if (it) View .VISIBLE else View .GONE
389386 }
390387 })
391388
392389 attendeeViewModel.paymentCompleted
393390 .nonNull()
394- .observe(this , Observer {
391+ .observe(viewLifecycleOwner , Observer {
395392 if (it)
396393 openOrderCompletedFragment()
397394 })
@@ -401,7 +398,7 @@ class AttendeeFragment : Fragment() {
401398
402399 attendeeViewModel.attendee
403400 .nonNull()
404- .observe(this , Observer { user ->
401+ .observe(viewLifecycleOwner , Observer { user ->
405402 helloUser.text = " Hello ${user.firstName.nullToEmpty()} "
406403 firstName.text = Editable .Factory .getInstance().newEditable(user.firstName.nullToEmpty())
407404 lastName.text = Editable .Factory .getInstance().newEditable(user.lastName.nullToEmpty())
@@ -422,7 +419,7 @@ class AttendeeFragment : Fragment() {
422419
423420 attendeeViewModel.forms
424421 .nonNull()
425- .observe(this , Observer {
422+ .observe(viewLifecycleOwner , Observer {
426423 if (singleTicket)
427424 fillInformationSection(it)
428425 attendeeRecyclerAdapter.setCustomForm(it)
@@ -443,43 +440,53 @@ class AttendeeFragment : Fragment() {
443440 " Please accept the terms and conditions!" , Snackbar .LENGTH_LONG ).show()
444441 return @setOnClickListener
445442 }
446- val attendees = ArrayList <Attendee >()
447- if (singleTicket) {
448- val pos = ticketIdAndQty?.map { it.second }?.indexOf(1 )
449- val ticket = pos?.let { it1 -> ticketIdAndQty?.get(it1)?.first?.toLong() } ? : - 1
450- val attendee = Attendee (id = attendeeViewModel.getId(),
451- firstname = firstName.text.toString(),
452- lastname = lastName.text.toString(),
453- city = getAttendeeField(" city" ),
454- address = getAttendeeField(" address" ),
455- state = getAttendeeField(" state" ),
456- email = email.text.toString(),
457- ticket = TicketId (ticket),
458- event = eventId)
459- attendees.add(attendee)
460- } else {
461- attendees.addAll(attendeeRecyclerAdapter.attendeeList)
443+
444+ val builder = AlertDialog .Builder (requireContext())
445+ builder.setTitle(R .string.confirmation_dialog)
446+
447+ builder.setPositiveButton(android.R .string.yes) { dialog, which ->
448+ val attendees = ArrayList <Attendee >()
449+ if (singleTicket) {
450+ val pos = ticketIdAndQty?.map { it.second }?.indexOf(1 )
451+ val ticket = pos?.let { it1 -> ticketIdAndQty?.get(it1)?.first?.toLong() } ? : - 1
452+ val attendee = Attendee (id = attendeeViewModel.getId(),
453+ firstname = firstName.text.toString(),
454+ lastname = lastName.text.toString(),
455+ city = getAttendeeField(" city" ),
456+ address = getAttendeeField(" address" ),
457+ state = getAttendeeField(" state" ),
458+ email = email.text.toString(),
459+ ticket = TicketId (ticket),
460+ event = eventId)
461+ attendees.add(attendee)
462+ } else {
463+ attendees.addAll(attendeeRecyclerAdapter.attendeeList)
464+ }
465+
466+ if (attendeeViewModel.areAttendeeEmailsValid(attendees)) {
467+ val country = rootView.countryPicker.selectedItem.toString()
468+ attendeeViewModel.createAttendees(attendees, country, paymentOptions[selectedPaymentOption])
469+
470+ attendeeViewModel.isAttendeeCreated.observe(viewLifecycleOwner, Observer { isAttendeeCreated ->
471+ if (isAttendeeCreated && selectedPaymentOption ==
472+ paymentOptions.indexOf(getString(R .string.stripe))) {
473+ sendToken()
474+ }
475+ })
476+ } else Snackbar .make(rootView.attendeeScrollView, " Invalid email address!" , Snackbar .LENGTH_LONG ).show()
462477 }
463478
464- if (attendeeViewModel.areAttendeeEmailsValid(attendees)) {
465- val country = rootView.countryPicker.selectedItem.toString()
466- attendeeViewModel.createAttendees(attendees, country, paymentOptions[selectedPaymentOption])
479+ builder.setNegativeButton(android.R .string.no) { dialog, which ->
480+ Snackbar .make(rootView, R .string.order_not_completed, Snackbar .LENGTH_SHORT ).show()
481+ }
482+ builder.show()
467483
468- attendeeViewModel.isAttendeeCreated.observe(this , Observer { isAttendeeCreated ->
469- if (isAttendeeCreated && selectedPaymentOption ==
470- paymentOptions.indexOf(getString(R .string.stripe))) {
471- sendToken()
472- }
484+ attendeeViewModel.ticketSoldOut
485+ .nonNull()
486+ .observe(this , Observer {
487+ showTicketSoldOutDialog(it)
473488 })
474- } else Snackbar .make(rootView.attendeeScrollView, " Invalid email address!" , Snackbar .LENGTH_LONG ).show()
475489 }
476-
477- attendeeViewModel.ticketSoldOut
478- .nonNull()
479- .observe(this , Observer {
480- showTicketSoldOutDialog(it)
481- })
482-
483490 return rootView
484491 }
485492
0 commit comments