From d4d108780353ab91f99ca164e19615170b11f69c Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 7 Jul 2022 16:36:39 +0200 Subject: [PATCH] improve backstack behavior --- .../github/libretube/activities/MainActivity.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 4341b30f3..18c41cbe5 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -136,6 +136,12 @@ class MainActivity : AppCompatActivity() { false } + /** + * don't remove this line + * this prevents reselected items at the bottomNav to be duplicated in the backstack + */ + binding.bottomNav.setOnItemReselectedListener {} + binding.toolbar.title = ThemeHelper.getStyledAppName(this) binding.toolbar.setNavigationOnClickListener { @@ -260,13 +266,15 @@ class MainActivity : AppCompatActivity() { } override fun onBackPressed() { - if ( - binding.mainMotionLayout.progress == 0F - ) { + if (binding.mainMotionLayout.progress == 1F) { try { minimizePlayer() } catch (e: Exception) { - super.onBackPressed() + if (navController.currentDestination?.id == startFragmentId) { + super.onBackPressed() + } else { + navController.popBackStack() + } } } else if (navController.currentDestination?.id == startFragmentId) { super.onBackPressed()