-
- All Implemented Interfaces:
-
dev.teogor.ceres.core.logger.Logger
public class NavigationUI implements Logger
-
-
Field Summary
Fields Modifier and Type Field Description public final static NavigationUIINSTANCE
-
Method Summary
Modifier and Type Method Description final static BooleanonNavDestinationSelected(MenuItem item, NavController navController)Attempt to navigate to the NavDestination associated with the given MenuItem. final static BooleanonNavDestinationSelected(MenuItem item, NavController navController, Boolean saveState)Attempt to navigate to the NavDestination associated with the given MenuItem. final static BooleannavigateUp(NavController navController, Openable openableLayout)Handles the Up button by delegating its behavior to the given NavController. final static BooleannavigateUp(NavController navController, AppBarConfiguration configuration)Handles the Up button by delegating its behavior to the given NavController. final static UnitsetupWithNavController(NavigationView navigationView, NavController navController)Sets up a NavigationView for use with a NavController. final static UnitsetupWithNavController(NavigationView navigationView, NavController navController, Boolean saveState)Sets up a NavigationView for use with a NavController. final static UnitsetupWithNavController(NavigationBarView navigationBarView, NavController navController)Sets up a NavigationBarView for use with a NavController. final static UnitsetupWithNavController(NavigationBarView navigationBarView, NavController navController, Boolean saveState)Sets up a NavigationBarView for use with a NavController. -
-
Method Detail
-
onNavDestinationSelected
final static Boolean onNavDestinationSelected(MenuItem item, NavController navController)
Attempt to navigate to the NavDestination associated with the given MenuItem. This MenuItem should have been added via one of the helper methods in this class.
Importantly, it assumes the menu item id matches a valid action id or destination id to be navigated to.
By default, the back stack will be popped back to the navigation graph's start destination. Menu items that have
android:menuCategory="secondary"will not pop the back stack.- Parameters:
item- The selected MenuItem.navController- The NavController that hosts the destination.
-
onNavDestinationSelected
final static Boolean onNavDestinationSelected(MenuItem item, NavController navController, Boolean saveState)
Attempt to navigate to the NavDestination associated with the given MenuItem. This MenuItem should have been added via one of the helper methods in this class.
Importantly, it assumes the menu item id matches a valid action id or destination id to be navigated to.
By default, the back stack will be popped back to the navigation graph's start destination. Menu items that have
android:menuCategory="secondary"will not pop the back stack.- Parameters:
item- The selected MenuItem.navController- The NavController that hosts the destination.saveState- Whether the NavController should save the back stack state.
-
navigateUp
final static Boolean navigateUp(NavController navController, Openable openableLayout)
Handles the Up button by delegating its behavior to the given NavController. This should generally be called from AppCompatActivity.onSupportNavigateUp.
If you do not have a Openable layout, you should call NavController.navigateUp directly.
- Parameters:
navController- The NavController that hosts your content.openableLayout- The Openable layout that should be opened if you are on the topmost level of the app.
-
navigateUp
final static Boolean navigateUp(NavController navController, AppBarConfiguration configuration)
Handles the Up button by delegating its behavior to the given NavController. This is an alternative to using NavController.navigateUp directly when the given AppBarConfiguration needs to be considered when determining what should happen when the Up button is pressed.
In cases where no Up action is available, the AppBarConfiguration.fallbackOnNavigateUpListener will be called to provide additional control.
- Parameters:
navController- The NavController that hosts your content.configuration- Additional configuration options for determining what should happen when the Up button is pressed.
-
setupWithNavController
final static Unit setupWithNavController(NavigationView navigationView, NavController navController)
Sets up a NavigationView for use with a NavController. This will call onNavDestinationSelected when a menu item is selected. The selected item in the NavigationView will automatically be updated when the destination changes.
If the NavigationView is directly contained with an Openable layout, it will be closed when a menu item is selected.
Similarly, if the NavigationView has a BottomSheetBehavior associated with it (as is the case when using a com.google.android.material.bottomsheet.BottomSheetDialog), the bottom sheet will be hidden when a menu item is selected.
- Parameters:
navigationView- The NavigationView that should be kept in sync with changes to the NavController.navController- The NavController that supplies the primary and secondary menu.
-
setupWithNavController
final static Unit setupWithNavController(NavigationView navigationView, NavController navController, Boolean saveState)
Sets up a NavigationView for use with a NavController. This will call onNavDestinationSelected when a menu item is selected. The selected item in the NavigationView will automatically be updated when the destination changes.
If the NavigationView is directly contained with an Openable layout, it will be closed when a menu item is selected.
Similarly, if the NavigationView has a BottomSheetBehavior associated with it (as is the case when using a com.google.android.material.bottomsheet.BottomSheetDialog), the bottom sheet will be hidden when a menu item is selected.
- Parameters:
navigationView- The NavigationView that should be kept in sync with changes to the NavController.navController- The NavController that supplies the primary and secondary menu.saveState- Whether the NavController should save the back stack state.
-
setupWithNavController
final static Unit setupWithNavController(NavigationBarView navigationBarView, NavController navController)
Sets up a NavigationBarView for use with a NavController. This will call onNavDestinationSelected when a menu item is selected. The selected item in the NavigationBarView will automatically be updated when the destination changes.
- Parameters:
navigationBarView- The NavigationBarView (BottomNavigationView or NavigationRailView) that should be kept in sync with changes to the NavController.navController- The NavController that supplies the primary menu.
-
setupWithNavController
final static Unit setupWithNavController(NavigationBarView navigationBarView, NavController navController, Boolean saveState)
Sets up a NavigationBarView for use with a NavController. This will call onNavDestinationSelected when a menu item is selected. The selected item in the NavigationBarView will automatically be updated when the destination changes.
- Parameters:
navigationBarView- The NavigationBarView (BottomNavigationView or NavigationRailView) that should be kept in sync with changes to the NavController.navController- The NavController that supplies the primary menu.saveState- Whether the NavController should save the back stack state.
-
-
-
-