Fixed back button action

This commit is contained in:
Prathamesh More 2021-11-17 21:18:52 +05:30
parent 9fa4d0bcc6
commit 8099eb0012
8 changed files with 30 additions and 18 deletions

View file

@ -102,11 +102,11 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
}
}
}
// This is more like a work-around as for start destination of navGraph
// enterTransition won't work as expected
navGraph.setStartDestination(R.id.libraryFragment)
navController.addOnDestinationChangedListener { _, destination, _ ->
// This is more like a work-around as for start destination of navGraph
// enterTransition won't work as expected
navGraph.setStartDestination(R.id.libraryFragment)
when (destination.id) {
when (destination.id) {
R.id.action_home, R.id.action_song, R.id.action_album, R.id.action_artist, R.id.action_folder, R.id.action_playlist, R.id.action_genre -> {
// Save the last tab
if (PreferenceUtil.rememberLastTab) {
@ -131,16 +131,6 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
override fun onSupportNavigateUp(): Boolean =
findNavController(R.id.fragment_container).navigateUp()
override fun onBackPressed() {
val bottomTabs = listOf(R.id.action_home, R.id.action_song, R.id.action_album, R.id.action_artist, R.id.action_folder, R.id.action_playlist, R.id.action_genre)
val currentDestinationId = findNavController(R.id.fragment_container).currentDestination?.id
if (bottomTabs.contains(currentDestinationId)) {
finish()
} else {
findNavController(R.id.fragment_container).navigateUp()
}
}
override fun onResume() {
super.onResume()
PreferenceUtil.registerOnSharedPreferenceChangedListener(this)