MainActivity: Handle back action properly when on onboarding/splash fragment
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -98,6 +98,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
B = ActivityMainBinding.inflate(layoutInflater)
|
B = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(B.root)
|
setContentView(B.root)
|
||||||
|
|
||||||
|
val navHostFragment =
|
||||||
|
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
|
||||||
|
navController = navHostFragment.navController
|
||||||
|
|
||||||
this.lifecycleScope.launch {
|
this.lifecycleScope.launch {
|
||||||
NetworkProvider(this@MainActivity).networkStatus.collect {
|
NetworkProvider(this@MainActivity).networkStatus.collect {
|
||||||
when(it) {
|
when(it) {
|
||||||
@@ -173,6 +177,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
} else {
|
} else {
|
||||||
navController.navigate(defaultTab)
|
navController.navigate(defaultTab)
|
||||||
}
|
}
|
||||||
|
} else if (navHostFragment.childFragmentManager.backStackEntryCount == 0) {
|
||||||
|
// We are on either on onboarding or splash fragment
|
||||||
|
finish()
|
||||||
} else {
|
} else {
|
||||||
navController.navigateUp()
|
navController.navigateUp()
|
||||||
}
|
}
|
||||||
@@ -220,9 +227,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun attachNavigation() {
|
private fun attachNavigation() {
|
||||||
val bottomNavigationView: BottomNavigationView = B.navView
|
val bottomNavigationView: BottomNavigationView = B.navView
|
||||||
val navHostFragment =
|
|
||||||
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
|
|
||||||
navController = navHostFragment.navController
|
|
||||||
bottomNavigationView.setupWithNavController(navController)
|
bottomNavigationView.setupWithNavController(navController)
|
||||||
|
|
||||||
bottomNavigationView.apply {
|
bottomNavigationView.apply {
|
||||||
|
|||||||
Reference in New Issue
Block a user