parent
52b771a8b5
commit
febbd26261
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.navigation
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.view.View
|
||||||
|
import androidx.compose.material3.windowsizeclass.WindowSizeClass
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalView
|
||||||
|
import androidx.core.view.doOnPreDraw
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
|
import androidx.navigation.compose.NavHost
|
||||||
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.author.navigation.AuthorDestination
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.author.navigation.authorGraph
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouDestination
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouGraph
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.interests.navigation.interestsGraph
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.topic.navigation.TopicDestination
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicGraph
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Top-level navigation graph. Navigation is organized as explained at
|
||||||
|
* https://d.android.com/jetpack/compose/nav-adaptive
|
||||||
|
*
|
||||||
|
* The navigation graph defined in this file defines the different top level routes. Navigation
|
||||||
|
* within each route is handled using state and Back Handlers.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun NiaNavHost(
|
||||||
|
windowSizeClass: WindowSizeClass,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
navController: NavHostController = rememberNavController(),
|
||||||
|
startDestination: String = ForYouDestination.route
|
||||||
|
) {
|
||||||
|
NavHost(
|
||||||
|
navController = navController,
|
||||||
|
startDestination = startDestination,
|
||||||
|
modifier = modifier,
|
||||||
|
) {
|
||||||
|
forYouGraph(
|
||||||
|
windowSizeClass = windowSizeClass
|
||||||
|
)
|
||||||
|
interestsGraph(
|
||||||
|
navigateToTopic = { navController.navigate("${TopicDestination.route}/$it") },
|
||||||
|
navigateToAuthor = { navController.navigate("${AuthorDestination.route}/$it") }
|
||||||
|
)
|
||||||
|
topicGraph(
|
||||||
|
onBackClick = { navController.popBackStack() }
|
||||||
|
)
|
||||||
|
authorGraph(
|
||||||
|
onBackClick = { navController.popBackStack() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// Reporting the app fully drawn to get accurate TTFD readings for the baseline profile.
|
||||||
|
// https://developer.android.com/topic/performance/vitals/launch-time#retrieve-TTFD
|
||||||
|
ReportFullyDrawn(ForYouDestination.route)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calling [Activity#reportFullyDrawn] in compose UI.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun ReportFullyDrawn(destination: String) {
|
||||||
|
// Holding on to the local view and calling `reportFullyDrawn` in an `onPreDraw` listener.
|
||||||
|
// Compose currently doesn't offer a way to otherwise report fully drawn,
|
||||||
|
// so this is a viable approach.
|
||||||
|
val localView: View = LocalView.current
|
||||||
|
(localView.context as? Activity)?.run {
|
||||||
|
localView.doOnPreDraw {
|
||||||
|
reportFullyDrawn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.navigation
|
||||||
|
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Grid3x3
|
||||||
|
import androidx.compose.material.icons.filled.Upcoming
|
||||||
|
import androidx.compose.material.icons.outlined.Grid3x3
|
||||||
|
import androidx.compose.material.icons.outlined.Upcoming
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.foryou.R.string.for_you
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouDestination
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.interests.R.string.interests
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.interests.navigation.InterestsDestination
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Routes for the different top level destinations in the application. Each of these destinations
|
||||||
|
* can contain one or more screens (based on the window size). Navigation from one screen to the
|
||||||
|
* next within a single destination will be handled directly in composables.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Models the navigation top level actions in the app.
|
||||||
|
*/
|
||||||
|
class NiaTopLevelNavigation(private val navController: NavHostController) {
|
||||||
|
|
||||||
|
fun navigateTo(destination: TopLevelDestination) {
|
||||||
|
navController.navigate(destination.route) {
|
||||||
|
// Pop up to the start destination of the graph to
|
||||||
|
// avoid building up a large stack of destinations
|
||||||
|
// on the back stack as users select items
|
||||||
|
popUpTo(navController.graph.findStartDestination().id) {
|
||||||
|
saveState = true
|
||||||
|
}
|
||||||
|
// Avoid multiple copies of the same destination when
|
||||||
|
// reselecting the same item
|
||||||
|
launchSingleTop = true
|
||||||
|
// Restore state when reselecting a previously selected item
|
||||||
|
restoreState = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class TopLevelDestination(
|
||||||
|
val route: String,
|
||||||
|
val selectedIcon: ImageVector,
|
||||||
|
val unselectedIcon: ImageVector,
|
||||||
|
val iconTextId: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
val TOP_LEVEL_DESTINATIONS = listOf(
|
||||||
|
TopLevelDestination(
|
||||||
|
route = ForYouDestination.route,
|
||||||
|
selectedIcon = Icons.Filled.Upcoming,
|
||||||
|
unselectedIcon = Icons.Outlined.Upcoming,
|
||||||
|
iconTextId = for_you
|
||||||
|
),
|
||||||
|
TopLevelDestination(
|
||||||
|
route = InterestsDestination.route,
|
||||||
|
selectedIcon = Icons.Filled.Grid3x3,
|
||||||
|
unselectedIcon = Icons.Outlined.Grid3x3,
|
||||||
|
iconTextId = interests
|
||||||
|
)
|
||||||
|
)
|
@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2022 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* https://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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.samples.apps.nowinandroid.ui
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.view.View
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.windowsizeclass.WindowSizeClass
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.platform.LocalView
|
|
||||||
import androidx.core.view.doOnPreDraw
|
|
||||||
import androidx.navigation.NavHostController
|
|
||||||
import androidx.navigation.NavType
|
|
||||||
import androidx.navigation.compose.NavHost
|
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
import androidx.navigation.compose.navigation
|
|
||||||
import androidx.navigation.compose.rememberNavController
|
|
||||||
import androidx.navigation.navArgument
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.author.AuthorDestinations
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.author.AuthorDestinationsArgs
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.author.AuthorRoute
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.author.InterestsScreens.AUTHOR_SCREEN
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.foryou.ForYouRoute
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.interests.InterestsRoute
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.InterestsDestinations
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.InterestsScreens.TOPIC_SCREEN
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.TopicDestinationsArgs
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.TopicRoute
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Top-level navigation graph. Navigation is organized as explained at
|
|
||||||
* https://d.android.com/jetpack/compose/nav-adaptive
|
|
||||||
*
|
|
||||||
* The navigation graph defined in this file defines the different top level routes. Navigation
|
|
||||||
* within each route is handled using state and Back Handlers.
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun NiaNavGraph(
|
|
||||||
windowSizeClass: WindowSizeClass,
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
navController: NavHostController = rememberNavController(),
|
|
||||||
startDestination: String = NiaDestinations.FOR_YOU_ROUTE
|
|
||||||
) {
|
|
||||||
NavHost(
|
|
||||||
navController = navController,
|
|
||||||
startDestination = startDestination,
|
|
||||||
modifier = modifier,
|
|
||||||
) {
|
|
||||||
composable(NiaDestinations.FOR_YOU_ROUTE) {
|
|
||||||
ForYouRoute(windowSizeClass)
|
|
||||||
}
|
|
||||||
composable(NiaDestinations.EPISODES_ROUTE) {
|
|
||||||
Text("EPISODES")
|
|
||||||
}
|
|
||||||
composable(NiaDestinations.SAVED_ROUTE) {
|
|
||||||
Text("SAVED")
|
|
||||||
}
|
|
||||||
navigation(
|
|
||||||
startDestination = InterestsDestinations.INTERESTS_DESTINATION,
|
|
||||||
route = NiaDestinations.INTERESTS_ROUTE
|
|
||||||
) {
|
|
||||||
composable(InterestsDestinations.INTERESTS_DESTINATION) {
|
|
||||||
InterestsRoute(
|
|
||||||
navigateToTopic = { navController.navigate("$TOPIC_SCREEN/$it") },
|
|
||||||
navigateToAuthor = { navController.navigate("$AUTHOR_SCREEN/$it") },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
composable(
|
|
||||||
InterestsDestinations.TOPIC_ROUTE,
|
|
||||||
arguments = listOf(
|
|
||||||
navArgument(TopicDestinationsArgs.TOPIC_ID_ARG) {
|
|
||||||
type = NavType.StringType
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
TopicRoute(onBackClick = { navController.popBackStack() })
|
|
||||||
}
|
|
||||||
composable(
|
|
||||||
AuthorDestinations.AUTHOR_ROUTE,
|
|
||||||
arguments = listOf(
|
|
||||||
navArgument(AuthorDestinationsArgs.AUTHOR_ID_ARG) {
|
|
||||||
type = NavType.StringType
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
AuthorRoute(onBackClick = { navController.popBackStack() })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Reporting the app fully drawn to get accurate TTFD readings for the baseline profile.
|
|
||||||
// https://developer.android.com/topic/performance/vitals/launch-time#retrieve-TTFD
|
|
||||||
ReportFullyDrawn(NiaDestinations.FOR_YOU_ROUTE)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calling [Activity#reportFullyDrawn] in compose UI.
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
private fun ReportFullyDrawn(destination: String) {
|
|
||||||
// Holding on to the local view and calling `reportFullyDrawn` in an `onPreDraw` listener.
|
|
||||||
// Compose currently doesn't offer a way to otherwise report fully drawn,
|
|
||||||
// so this is a viable approach.
|
|
||||||
val localView: View = LocalView.current
|
|
||||||
(localView.context as? Activity)?.run {
|
|
||||||
localView.doOnPreDraw {
|
|
||||||
reportFullyDrawn()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2022 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* https://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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.samples.apps.nowinandroid.ui
|
|
||||||
|
|
||||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
|
||||||
import androidx.navigation.NavHostController
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Routes for the different destinations in the application. Each of these destinations can contain
|
|
||||||
* one or more screens (based on the window size). Navigation from one screen to the next within a
|
|
||||||
* single destination will be handled directly in Compose, not using the Navigation component.
|
|
||||||
*/
|
|
||||||
object NiaDestinations {
|
|
||||||
const val FOR_YOU_ROUTE = "for_you"
|
|
||||||
const val EPISODES_ROUTE = "episodes"
|
|
||||||
const val SAVED_ROUTE = "saved"
|
|
||||||
const val INTERESTS_ROUTE = "interests"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Models the navigation actions in the app.
|
|
||||||
*/
|
|
||||||
class NiaNavigationActions(private val navController: NavHostController) {
|
|
||||||
fun navigateToTopLevelDestination(route: String) {
|
|
||||||
navController.navigate(route) {
|
|
||||||
// Pop up to the start destination of the graph to
|
|
||||||
// avoid building up a large stack of destinations
|
|
||||||
// on the back stack as users select items
|
|
||||||
popUpTo(navController.graph.findStartDestination().id) {
|
|
||||||
saveState = true
|
|
||||||
}
|
|
||||||
// Avoid multiple copies of the same destination when
|
|
||||||
// reselecting the same item
|
|
||||||
launchSingleTop = true
|
|
||||||
// Restore state when reselecting a previously selected item
|
|
||||||
restoreState = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1 @@
|
|||||||
|
/build
|
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2022 The Android Open Source Project
|
||||||
|
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.google.samples.apps.nowinandroid.core.navigation">
|
||||||
|
|
||||||
|
</manifest>
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.core.navigation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for describing the Now in Android navigation destinations
|
||||||
|
*/
|
||||||
|
|
||||||
|
interface NiaNavigationDestination {
|
||||||
|
/**
|
||||||
|
* Defines a specific route this destination belongs to.
|
||||||
|
* Route is a String that defines the path to your composable.
|
||||||
|
* You can think of it as an implicit deep link that leads to a specific destination.
|
||||||
|
* Each destination should have a unique route.
|
||||||
|
*/
|
||||||
|
val route: String
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a specific destination ID.
|
||||||
|
* This is needed when using nested graphs via the navigation DLS, to differentiate a specific
|
||||||
|
* destination's route from the route of the entire nested graph it belongs to.
|
||||||
|
*/
|
||||||
|
val destination: String
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.feature.author.navigation
|
||||||
|
|
||||||
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.NavType
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
|
import androidx.navigation.navArgument
|
||||||
|
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationDestination
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.author.AuthorRoute
|
||||||
|
|
||||||
|
object AuthorDestination : NiaNavigationDestination {
|
||||||
|
override val route = "author_route"
|
||||||
|
override val destination = "author_destination"
|
||||||
|
const val authorIdArg = "authorId"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun NavGraphBuilder.authorGraph(
|
||||||
|
onBackClick: () -> Unit
|
||||||
|
) {
|
||||||
|
composable(
|
||||||
|
route = "${AuthorDestination.route}/{${AuthorDestination.authorIdArg}}",
|
||||||
|
arguments = listOf(
|
||||||
|
navArgument(AuthorDestination.authorIdArg) {
|
||||||
|
type = NavType.StringType
|
||||||
|
}
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
AuthorRoute(onBackClick = onBackClick)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.feature.foryou.navigation
|
||||||
|
|
||||||
|
import androidx.compose.material3.windowsizeclass.WindowSizeClass
|
||||||
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
|
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationDestination
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.foryou.ForYouRoute
|
||||||
|
|
||||||
|
object ForYouDestination : NiaNavigationDestination {
|
||||||
|
override val route = "for_you_route"
|
||||||
|
override val destination = "for_you_destination"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun NavGraphBuilder.forYouGraph(
|
||||||
|
windowSizeClass: WindowSizeClass
|
||||||
|
) {
|
||||||
|
composable(route = ForYouDestination.route) {
|
||||||
|
ForYouRoute(windowSizeClass)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.feature.interests.navigation
|
||||||
|
|
||||||
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
|
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationDestination
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.interests.InterestsRoute
|
||||||
|
|
||||||
|
object InterestsDestination : NiaNavigationDestination {
|
||||||
|
override val route = "interests_route"
|
||||||
|
override val destination = "interests_destination"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun NavGraphBuilder.interestsGraph(
|
||||||
|
navigateToTopic: (String) -> Unit,
|
||||||
|
navigateToAuthor: (String) -> Unit
|
||||||
|
) {
|
||||||
|
composable(route = InterestsDestination.route) {
|
||||||
|
InterestsRoute(
|
||||||
|
navigateToTopic = navigateToTopic,
|
||||||
|
navigateToAuthor = navigateToAuthor,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2022 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* https://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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.samples.apps.nowinandroid.feature.topic
|
|
||||||
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.InterestsScreens.TOPIC_SCREEN
|
|
||||||
import com.google.samples.apps.nowinandroid.feature.topic.TopicDestinationsArgs.TOPIC_ID_ARG
|
|
||||||
|
|
||||||
object InterestsDestinations {
|
|
||||||
const val INTERESTS_DESTINATION = "interests_destination"
|
|
||||||
const val TOPIC_ROUTE = "$TOPIC_SCREEN/{$TOPIC_ID_ARG}"
|
|
||||||
}
|
|
||||||
|
|
||||||
object TopicDestinationsArgs {
|
|
||||||
const val TOPIC_ID_ARG = "topicId"
|
|
||||||
}
|
|
||||||
|
|
||||||
object InterestsScreens {
|
|
||||||
const val TOPIC_SCREEN = "topic"
|
|
||||||
}
|
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* https://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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.feature.topic.navigation
|
||||||
|
|
||||||
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.NavType
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
|
import androidx.navigation.navArgument
|
||||||
|
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationDestination
|
||||||
|
import com.google.samples.apps.nowinandroid.feature.topic.TopicRoute
|
||||||
|
|
||||||
|
object TopicDestination : NiaNavigationDestination {
|
||||||
|
override val route = "topic_route"
|
||||||
|
override val destination = "topic_destination"
|
||||||
|
const val topicIdArg = "topicId"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun NavGraphBuilder.topicGraph(
|
||||||
|
onBackClick: () -> Unit
|
||||||
|
) {
|
||||||
|
composable(
|
||||||
|
route = "${TopicDestination.route}/{${TopicDestination.topicIdArg}}",
|
||||||
|
arguments = listOf(
|
||||||
|
navArgument(TopicDestination.topicIdArg) {
|
||||||
|
type = NavType.StringType
|
||||||
|
}
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
TopicRoute(onBackClick = onBackClick)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue