Skip to content
Permalink
Browse files

Add multiple-back stacks to Bottom Navigation

  • Loading branch information...
chrisbanes committed Oct 6, 2019
1 parent b7497a0 commit d8ce79cd53309d795e18c7a22789c6b2cdcfdbf5
@@ -20,13 +20,12 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import androidx.lifecycle.observe
import app.tivi.R
import app.tivi.TiviActivityMvRxView
import app.tivi.databinding.ActivityHomeBinding
import app.tivi.extensions.hideSoftInput
import app.tivi.extensions.setupWithNavController
import app.tivi.trakt.TraktConstants
import app.tivi.util.AppCoroutineDispatchers
import com.airbnb.mvrx.viewModel
@@ -48,12 +47,6 @@ class HomeActivity : TiviActivityMvRxView() {

private lateinit var binding: ActivityHomeBinding

private val navHostFragment: NavHostFragment
get() = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment

private val navController: NavController
get() = navHostFragment.navController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

@@ -63,11 +56,17 @@ class HomeActivity : TiviActivityMvRxView() {
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

binding.homeBottomNavigation.setupWithNavController(navController)

navController.addOnDestinationChangedListener { _, destination, _ ->
if (destination.id != R.id.navigation_search) {
hideSoftInput()
binding.homeBottomNavigation.setupWithNavController(
listOf(R.navigation.discover_nav_graph, R.navigation.watched_nav_graph,
R.navigation.following_nav_graph, R.navigation.search_nav_graph),
supportFragmentManager,
R.id.home_nav_container,
intent
).observe(this) {
it.addOnDestinationChangedListener { _, destination, _ ->
if (destination.id != R.id.navigation_search) {
hideSoftInput()
}
}
}
}
@@ -28,14 +28,11 @@
app:paddingRightSystemWindowInsets="@{true}"
tools:context=".home.HomeActivity">

<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
<FrameLayout
android:id="@+id/home_nav_container"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
android:layout_weight="1" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/home_bottom_navigation"
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2019 Google, Inc.
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
@@ -17,18 +18,13 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
android:id="@id/navigation_discover"
app:startDestination="@id/navigation_discover">

<activity
android:id="@id/activity_show_details"
android:name="app.tivi.showdetails.ShowDetailsActivity"
android:label="activity_show_details"
tools:layout="@layout/activity_show_details">
<argument
android:name="show_id"
app:argType="long" />
</activity>
<fragment
android:id="@id/navigation_discover"
android:name="app.tivi.home.discover.DiscoverFragment"
android:label="@string/discover_title" />

<fragment
android:id="@id/navigation_trending"
@@ -46,26 +42,18 @@
android:label="@string/discover_recommended_title" />

<fragment
android:id="@id/navigation_watched"
android:name="app.tivi.home.watched.WatchedFragment"
android:label="@string/watched_shows_title" />

<fragment
android:id="@id/navigation_discover"
android:name="app.tivi.home.discover.DiscoverFragment"
android:label="@string/discover_title" />

<fragment
android:id="@id/navigation_followed"
android:name="app.tivi.home.followed.FollowedFragment"
android:label="@string/following_shows_title" />

<fragment android:id="@id/navigation_search"
android:name="app.tivi.home.search.SearchFragment"
android:label="@string/search_menu_title" />

<fragment android:id="@id/navigation_settings"
android:id="@id/navigation_settings"
android:name="app.tivi.settings.SettingsFragment"
android:label="@string/settings_title" />

<activity
android:id="@id/activity_show_details"
android:name="app.tivi.showdetails.ShowDetailsActivity"
android:label="activity_show_details"
tools:layout="@layout/activity_show_details">
<argument
android:name="show_id"
app:argType="long" />
</activity>

</navigation>
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@id/navigation_followed"
app:startDestination="@id/navigation_followed">

<fragment
android:id="@id/navigation_followed"
android:name="app.tivi.home.followed.FollowedFragment"
android:label="@string/following_shows_title" />

<fragment
android:id="@id/navigation_settings"
android:name="app.tivi.settings.SettingsFragment"
android:label="@string/settings_title" />

<activity
android:id="@id/activity_show_details"
android:name="app.tivi.showdetails.ShowDetailsActivity"
android:label="activity_show_details"
tools:layout="@layout/activity_show_details">
<argument
android:name="show_id"
app:argType="long" />
</activity>

</navigation>
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@id/navigation_search"
app:startDestination="@id/navigation_search">

<fragment android:id="@id/navigation_search"
android:name="app.tivi.home.search.SearchFragment"
android:label="@string/search_menu_title" />

<activity
android:id="@id/activity_show_details"
android:name="app.tivi.showdetails.ShowDetailsActivity"
android:label="activity_show_details"
tools:layout="@layout/activity_show_details">
<argument
android:name="show_id"
app:argType="long" />
</activity>

</navigation>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@id/navigation_watched"
app:startDestination="@id/navigation_watched">

<fragment
android:id="@id/navigation_watched"
android:name="app.tivi.home.watched.WatchedFragment"
android:label="@string/watched_shows_title" />

<fragment
android:id="@id/navigation_settings"
android:name="app.tivi.settings.SettingsFragment"
android:label="@string/settings_title" />

<activity
android:id="@id/activity_show_details"
android:name="app.tivi.showdetails.ShowDetailsActivity"
android:label="activity_show_details"
tools:layout="@layout/activity_show_details">
<argument
android:name="show_id"
app:argType="long" />
</activity>


</navigation>

0 comments on commit d8ce79c

Please sign in to comment.
You can’t perform that action at this time.