@@ -387,35 +387,40 @@ after opening the app.
387
387
}
388
388
389
389
override fun onBackPressed () {
390
- if (contributionsFragment != null && activeFragment == ActiveFragment .CONTRIBUTIONS ) {
390
+ when (activeFragment) {
391
+ ActiveFragment .CONTRIBUTIONS -> {
391
392
// Means that contribution fragment is visible
392
- if (! contributionsFragment!! .backButtonClicked()) { // If this one does not wan't to handle
393
+ if (contributionsFragment? .backButtonClicked() != true ) { // If this one does not want to handle
393
394
// the back press, let the activity do so
394
395
super .onBackPressed()
396
+ }
395
397
}
396
- } else if (nearbyParentFragment != null && activeFragment == ActiveFragment .NEARBY ) {
398
+ ActiveFragment .NEARBY -> {
397
399
// Means that nearby fragment is visible
398
- /* If function nearbyParentFragment.backButtonClick() returns false, it means that the bottomsheet is
399
- not expanded. So if the back button is pressed, then go back to the Contributions tab */
400
- if (! nearbyParentFragment!! .backButtonClicked()) {
401
- supportFragmentManager.beginTransaction().remove(nearbyParentFragment!! )
402
- .commit()
400
+ if (nearbyParentFragment?.backButtonClicked() != true ) {
401
+ nearbyParentFragment?.let {
402
+ supportFragmentManager.beginTransaction().remove(it).commit()
403
+ }
403
404
setSelectedItemId(NavTab .CONTRIBUTIONS .code())
405
+ }
404
406
}
405
- } else if (exploreFragment != null && activeFragment == ActiveFragment .EXPLORE ) {
406
- // Means that explore fragment is visible
407
- if (! exploreFragment!! .onBackPressed()) {
408
- if (applicationKvStore!! .getBoolean(" login_skipped" )) {
407
+ ActiveFragment .EXPLORE -> {
408
+ // Explore Fragment is visible
409
+ if (exploreFragment? .onBackPressed() != true ) {
410
+ if (applicationKvStore? .getBoolean(" login_skipped" ) == true ) {
409
411
super .onBackPressed()
410
412
} else {
411
413
setSelectedItemId(NavTab .CONTRIBUTIONS .code())
414
+ }
412
415
}
413
416
}
414
- } else if (bookmarkFragment != null && activeFragment == ActiveFragment .BOOKMARK ) {
417
+ ActiveFragment .BOOKMARK -> {
415
418
// Means that bookmark fragment is visible
416
- bookmarkFragment!! .onBackPressed()
417
- } else {
419
+ bookmarkFragment?.onBackPressed()
420
+ }
421
+ else -> {
418
422
super .onBackPressed()
423
+ }
419
424
}
420
425
}
421
426
0 commit comments