From 0331e3e7823a83b1e263e70053c20d1e6225631e Mon Sep 17 00:00:00 2001 From: "Thomas W." Date: Wed, 15 Jan 2025 15:24:41 +0100 Subject: [PATCH 1/3] Preserve platform navigation implementation --- .../github/libretube/ui/activities/MainActivity.kt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index 58423c0e9e..a8f62e8e80 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -163,7 +163,6 @@ class MainActivity : BaseActivity() { binding.bottomNav.setOnItemSelectedListener { navigateToBottomSelectedItem(it) - false } if (binding.bottomNav.menu.children.none { it.itemId == startFragmentId }) deselectBottomBarItems() @@ -551,21 +550,17 @@ class MainActivity : BaseActivity() { } } - private fun navigateToBottomSelectedItem(item: MenuItem) { + private fun navigateToBottomSelectedItem(item: MenuItem): Boolean { if (item.itemId == R.id.subscriptionsFragment) { binding.bottomNav.removeBadge(R.id.subscriptionsFragment) } - // navigate to the selected fragment, if the fragment already - // exists in backstack then pop up to that entry - if (!navController.popBackStack(item.itemId, false)) { - navController.navigate(item.itemId) - } - // Remove focus from search view when navigating to bottom view. // Call only after navigate to destination, so it can be used in // onMenuItemActionCollapse for backstack management removeSearchFocus() + + return item.onNavDestinationSelected(navController) } override fun onUserLeaveHint() { From f7ddb51442a451c3e6621f760d36148386659976 Mon Sep 17 00:00:00 2001 From: "Thomas W." Date: Wed, 15 Jan 2025 15:31:26 +0100 Subject: [PATCH 2/3] Add missing import --- .../main/java/com/github/libretube/ui/activities/MainActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index a8f62e8e80..3ac4154395 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -26,6 +26,7 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.NavController import androidx.navigation.findNavController import androidx.navigation.fragment.NavHostFragment +import androidx.navigation.ui.onNavDestinationSelected import androidx.navigation.ui.setupWithNavController import androidx.recyclerview.widget.RecyclerView import com.github.libretube.BuildConfig From 632e62cbdf52103f68df7dfa6d3528e0dae6733f Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 15 Jan 2025 22:41:02 +0100 Subject: [PATCH 3/3] Set defaultNavHost --- app/src/main/res/layout/activity_main.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index deed46b5b5..bedad7c450 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -41,6 +41,7 @@ android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="0dp" android:layout_height="0dp" + app:defaultNavHost="true" app:layout_constraintBottom_toTopOf="@+id/bottomNav" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"