diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt index f878c003b..f21d09f77 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt @@ -20,10 +20,12 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.navigation.compose.NavHost import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.bookmarksScreen -import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouRoute -import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouScreen +import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouBaseRoute +import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouSection import com.google.samples.apps.nowinandroid.feature.interests.navigation.navigateToInterests import com.google.samples.apps.nowinandroid.feature.search.navigation.searchScreen +import com.google.samples.apps.nowinandroid.feature.topic.navigation.navigateToTopic +import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicScreen import com.google.samples.apps.nowinandroid.navigation.TopLevelDestination.INTERESTS import com.google.samples.apps.nowinandroid.ui.NiaAppState import com.google.samples.apps.nowinandroid.ui.interests2pane.interestsListDetailScreen @@ -44,10 +46,18 @@ fun NiaNavHost( val navController = appState.navController NavHost( navController = navController, - startDestination = ForYouRoute, + startDestination = ForYouBaseRoute, modifier = modifier, ) { - forYouScreen(onTopicClick = navController::navigateToInterests) + forYouSection( + onTopicClick = navController::navigateToTopic + ) { + topicScreen( + showBackButton = true, + onBackClick = navController::popBackStack, + onTopicClick = navController::navigateToTopic + ) + } bookmarksScreen( onTopicClick = navController::navigateToInterests, onShowSnackbar = onShowSnackbar, diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/TopLevelDestination.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/TopLevelDestination.kt index 815061273..5b286e111 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/TopLevelDestination.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/TopLevelDestination.kt @@ -21,7 +21,7 @@ import androidx.compose.ui.graphics.vector.ImageVector import com.google.samples.apps.nowinandroid.R import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.BookmarksRoute -import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouRoute +import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouBaseRoute import com.google.samples.apps.nowinandroid.feature.interests.navigation.InterestsRoute import kotlin.reflect.KClass import com.google.samples.apps.nowinandroid.feature.bookmarks.R as bookmarksR @@ -45,7 +45,7 @@ enum class TopLevelDestination( unselectedIcon = NiaIcons.UpcomingBorder, iconTextId = forYouR.string.feature_foryou_title, titleTextId = R.string.app_name, - route = ForYouRoute::class, + route = ForYouBaseRoute::class, ), BOOKMARKS( selectedIcon = NiaIcons.Bookmarks, diff --git a/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt b/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt index 9d98f1618..8348aac9f 100644 --- a/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt +++ b/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt @@ -20,30 +20,45 @@ import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions import androidx.navigation.compose.composable +import androidx.navigation.compose.navigation import androidx.navigation.navDeepLink import com.google.samples.apps.nowinandroid.core.notifications.DEEP_LINK_URI_PATTERN import com.google.samples.apps.nowinandroid.feature.foryou.ForYouScreen import kotlinx.serialization.Serializable -@Serializable data object ForYouRoute +@Serializable data object ForYouRoute // route to ForYou screen +@Serializable data object ForYouBaseRoute // route to base navigation graph fun NavController.navigateToForYou(navOptions: NavOptions) = navigate(route = ForYouRoute, navOptions) -fun NavGraphBuilder.forYouScreen(onTopicClick: (String) -> Unit) { - composable( - deepLinks = listOf( - navDeepLink { - /** - * This destination has a deep link that enables a specific news resource to be - * opened from a notification (@see SystemTrayNotifier for more). The news resource - * ID is sent in the URI rather than being modelled in the route type because it's - * transient data (stored in SavedStateHandle) that is cleared after the user has - * opened the news resource. - */ - uriPattern = DEEP_LINK_URI_PATTERN - }, - ), - ) { - ForYouScreen(onTopicClick) +/** + * The ForYou section of the app. It can also display information about topics. + * This should be supplied from a separate module. + * + * @param onTopicClick - Called when a topic is clicked, contains the ID of the topic + * @param topicDestination - Destination for topic content + */ +fun NavGraphBuilder.forYouSection( + onTopicClick: (String) -> Unit, + topicDestination: NavGraphBuilder.() -> Unit +) { + navigation(startDestination = ForYouRoute) { + composable( + deepLinks = listOf( + navDeepLink { + /** + * This destination has a deep link that enables a specific news resource to be + * opened from a notification (@see SystemTrayNotifier for more). The news resource + * ID is sent in the URI rather than being modelled in the route type because it's + * transient data (stored in SavedStateHandle) that is cleared after the user has + * opened the news resource. + */ + uriPattern = DEEP_LINK_URI_PATTERN + }, + ), + ) { + ForYouScreen(onTopicClick) + } + topicDestination() } } diff --git a/feature/topic/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt b/feature/topic/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt index a18d9988a..8ef0d786d 100644 --- a/feature/topic/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt +++ b/feature/topic/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt @@ -71,7 +71,7 @@ import com.google.samples.apps.nowinandroid.core.ui.userNewsResourceCardItems import com.google.samples.apps.nowinandroid.feature.topic.R.string @Composable -internal fun TopicScreen( +fun TopicScreen( showBackButton: Boolean, onBackClick: () -> Unit, onTopicClick: (String) -> Unit,