android: inline routes

This commit is contained in:
Harsh Shandilya 2022-03-02 13:39:31 +05:30
parent 9fa8775d4c
commit de28ae2d95
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
4 changed files with 12 additions and 18 deletions

View file

@ -84,12 +84,12 @@ fun LobstersApp(
listOf(
NavigationItem(
label = "Hottest",
route = Destinations.Hottest.getRoute(),
route = Destinations.Hottest.route,
icon = painterResource(R.drawable.ic_whatshot_24dp),
) { coroutineScope.launch { networkListState.animateScrollToItem(index = 0) } },
NavigationItem(
label = "Saved",
route = Destinations.Saved.getRoute(),
route = Destinations.Saved.route,
icon = painterResource(commonR.drawable.ic_favorite_24dp),
) { coroutineScope.launch { savedListState.animateScrollToItem(index = 0) } },
)
@ -139,11 +139,11 @@ fun LobstersApp(
) { paddingValues ->
NavHost(
navController,
startDestination = Destinations.startDestination.getRoute(),
startDestination = Destinations.startDestination.route,
) {
val uri = LobstersApi.BASE_URL
composable(
route = Destinations.Hottest.getRoute(),
route = Destinations.Hottest.route,
deepLinks =
listOf(navDeepLink { uriPattern = uri }, navDeepLink { uriPattern = "$uri/" }),
) {
@ -157,7 +157,7 @@ fun LobstersApp(
modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()),
)
}
composable(Destinations.Saved.getRoute()) {
composable(Destinations.Saved.route) {
setWebUri(null)
DatabasePosts(
items = savedPosts,
@ -168,7 +168,7 @@ fun LobstersApp(
)
}
composable(
route = Destinations.Comments.getRoute("{postId}"),
route = Destinations.Comments.route,
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
deepLinks =
listOf(

View file

@ -38,7 +38,7 @@ fun ClawNavigationBar(
return@NavigationBarItem
}
navController.popBackStack(navController.graph.startDestinationRoute!!, false)
if (navItem.route != Destinations.startDestination.getRoute()) {
if (navItem.route != Destinations.startDestination.route) {
navController.navigate(navItem.route)
}
}

View file

@ -91,7 +91,7 @@ fun rememberPostActions(
}
override fun viewComments(postId: String) {
navController.navigate(Destinations.Comments.getRoute(postId))
navController.navigate(Destinations.Comments.route)
}
override fun viewCommentsPage(commentsUrl: String) {

View file

@ -1,17 +1,11 @@
package dev.msfjarvis.claw.android.ui.navigation
sealed class Destinations(internal val route: String) {
object Hottest : Destinations("hottest") {
fun getRoute() = route
}
sealed class Destinations(val route: String) {
object Hottest : Destinations("hottest")
object Saved : Destinations("saved") {
fun getRoute() = route
}
object Saved : Destinations("saved")
object Comments : Destinations("comments/%s") {
fun getRoute(postId: String) = route.format(postId)
}
object Comments : Destinations("comments/{postId}")
companion object {
val startDestination