Skip to content

Commit 0010cf5

Browse files
author
Rohan Maity
authored
Merge branch 'development' into feature/autocomplete-place
2 parents 03e00d2 + 7c22ee0 commit 0010cf5

40 files changed

+400
-256
lines changed

app/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ repositories {
9090
dependencies {
9191
def lifecycle_version = "2.1.0-alpha03"
9292
def koin_version = "1.0.2"
93-
def roomVersion = "2.1.0-alpha04"
93+
def roomVersion = "2.1.0-alpha06"
9494
def ktx_version = "1.0.0"
9595
def ktx2_version = "2.0.0"
96+
def nav_version = "2.1.0-alpha01"
9697

9798
implementation fileTree(dir: 'libs', include: ['*.jar'])
9899
implementation 'androidx.multidex:multidex:2.0.1'
@@ -158,12 +159,12 @@ dependencies {
158159
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
159160

160161
//Navigation
161-
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0'
162-
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0'
162+
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" // For Kotlin use navigation-fragment-ktx
163+
implementation "androidx.navigation:navigation-ui-ktx:$nav_version" // For Kotlin use navigation-ui-ktx
163164

164165
// Stetho
165166
debugImplementation 'com.facebook.stetho:stetho:1.5.1'
166-
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
167+
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
167168
releaseImplementation 'com.github.iamareebjamal:stetho-noop:1.2.1'
168169
testImplementation 'com.github.iamareebjamal:stetho-noop:1.2.1'
169170

@@ -174,7 +175,7 @@ dependencies {
174175
testImplementation "io.mockk:mockk:1.9.2"
175176
testImplementation 'org.threeten:threetenbp:1.3.8'
176177
testImplementation "org.koin:koin-test:$koin_version"
177-
testImplementation 'androidx.arch.core:core-testing:2.0.0'
178+
testImplementation 'androidx.arch.core:core-testing:2.0.1'
178179
androidTestImplementation 'androidx.test:runner:1.1.1'
179180
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
180181
}

app/src/main/java/org/fossasia/openevent/general/MainActivity.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.google.android.material.snackbar.Snackbar
1010
import kotlinx.android.synthetic.main.activity_main.navigation
1111
import kotlinx.android.synthetic.main.activity_main.navigationAuth
1212
import kotlinx.android.synthetic.main.activity_main.mainFragmentCoordinatorLayout
13+
import org.fossasia.openevent.general.auth.EditProfileFragment
1314
import org.fossasia.openevent.general.search.RC_CREDENTIALS_READ
1415
import org.fossasia.openevent.general.search.RC_CREDENTIALS_SAVE
1516
import org.fossasia.openevent.general.search.SmartAuthViewModel
@@ -68,10 +69,23 @@ class MainActivity : AppCompatActivity() {
6869
}
6970
R.id.orderCompletedFragment -> navController.popBackStack(R.id.eventDetailsFragment, false)
7071
R.id.welcomeFragment -> finish()
72+
R.id.editProfileFragment -> {
73+
74+
// Calls the handleBackPress method in EditProfileFragment
75+
val hostFragment = supportFragmentManager.findFragmentById(R.id.frameContainer) as? NavHostFragment
76+
(hostFragment?.childFragmentManager?.fragments?.get(0) as? EditProfileFragment)?.handleBackPress()
77+
}
7178
else -> super.onBackPressed()
7279
}
7380
}
7481

82+
/**
83+
* Called by EditProfileFragment to go to previous fragment
84+
*/
85+
fun onSuperBackPressed() {
86+
super.onBackPressed()
87+
}
88+
7589
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
7690
if (requestCode == RC_CREDENTIALS_READ || requestCode == RC_CREDENTIALS_SAVE)
7791
SmartAuthViewModel().onActivityResult(requestCode, resultCode, data, this)

app/src/main/java/org/fossasia/openevent/general/about/AboutEventFragment.kt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ class AboutEventFragment : Fragment(), AppBarLayout.OnOffsetChangedListener {
3434
private var title: String = ""
3535
private val safeArgs: AboutEventFragmentArgs by navArgs()
3636

37-
override fun onCreate(savedInstanceState: Bundle?) {
38-
super.onCreate(savedInstanceState)
39-
40-
aboutEventViewModel.event
41-
.nonNull()
42-
.observe(this, Observer {
43-
loadEvent(it)
44-
})
45-
}
46-
4737
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
4838
rootView = layoutInflater.inflate(R.layout.fragment_about_event, container, false)
4939

@@ -54,17 +44,23 @@ class AboutEventFragment : Fragment(), AppBarLayout.OnOffsetChangedListener {
5444
}
5545
setHasOptionsMenu(true)
5646

47+
aboutEventViewModel.event
48+
.nonNull()
49+
.observe(viewLifecycleOwner, Observer {
50+
loadEvent(it)
51+
})
52+
5753
rootView.appBar.addOnOffsetChangedListener(this)
5854

5955
aboutEventViewModel.error
6056
.nonNull()
61-
.observe(this, Observer {
57+
.observe(viewLifecycleOwner, Observer {
6258
Snackbar.make(rootView, it, Snackbar.LENGTH_SHORT).show()
6359
})
6460

6561
aboutEventViewModel.progressAboutEvent
6662
.nonNull()
67-
.observe(this, Observer {
63+
.observe(viewLifecycleOwner, Observer {
6864
rootView.progressBarAbout.isVisible = it
6965
})
7066

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

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)