@@ -387,35 +387,40 @@ after opening the app.
387387 }
388388
389389 override fun onBackPressed () {
390- if (contributionsFragment != null && activeFragment == ActiveFragment .CONTRIBUTIONS ) {
390+ when (activeFragment) {
391+ ActiveFragment .CONTRIBUTIONS -> {
391392 // 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
393394 // the back press, let the activity do so
394395 super .onBackPressed()
396+ }
395397 }
396- } else if (nearbyParentFragment != null && activeFragment == ActiveFragment .NEARBY ) {
398+ ActiveFragment .NEARBY -> {
397399 // 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+ }
403404 setSelectedItemId(NavTab .CONTRIBUTIONS .code())
405+ }
404406 }
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 ) {
409411 super .onBackPressed()
410412 } else {
411413 setSelectedItemId(NavTab .CONTRIBUTIONS .code())
414+ }
412415 }
413416 }
414- } else if (bookmarkFragment != null && activeFragment == ActiveFragment .BOOKMARK ) {
417+ ActiveFragment .BOOKMARK -> {
415418 // Means that bookmark fragment is visible
416- bookmarkFragment!! .onBackPressed()
417- } else {
419+ bookmarkFragment?.onBackPressed()
420+ }
421+ else -> {
418422 super .onBackPressed()
423+ }
419424 }
420425 }
421426
0 commit comments