Skip to content

Instantly share code, notes, and snippets.

@PollyGlot
Created January 3, 2020 16:00
Show Gist options
  • Save PollyGlot/6234523c6c4f4ba529812a05a549967d to your computer and use it in GitHub Desktop.
Save PollyGlot/6234523c6c4f4ba529812a05a549967d to your computer and use it in GitHub Desktop.
A method to control navigation graphs in bottomNavigationBar
/**
* Called on first creation and when restoring state.
*/
private fun setupBottomNavigationBar(recreated: Boolean) {
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottomNavigation)
val navGraphIds = listOf(TABS.BROWSE.navId, TABS.SEARCH.navId, TABS.FEED.navId, TABS.PROFILE.navId, TABS.PLUS.navId)
// Setup the bottom navigation view with a list of navigation graphs
val controller = bottomNavigationView.setupWithNavController(
navGraphIds = navGraphIds,
fragmentManager = supportFragmentManager,
containerId = R.id.nav_host_container,
intent = intent,
navigationInterface = object : NavigationInterface {
override fun onTabSelected(selectedTab: TABS) {
changePlayButtonColor(selectedTab == TABS.FEED)
currentTab = selectedTab
}
}
)
// click on floating action button actually clicks on hidden bottom navigation button
navigationVideo.setOnClickListener {
bottomNavigationView.findViewById<View>(R.id.home).performClick()
}
// Whenever the selected controller changes, setup the action bar.
controller.observe(this, Observer { navController ->
setupActionBarWithNavController(navController)
})
currentNavController = controller
//set feed as default if first launched
if (!recreated) bottomNavigationView.selectedItemId = TABS.FEED.buttonId
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment