Revert "android: inline routes"

This makes the handling in `PostActions#viewComments` slightly weird and isn't
worth it until that abstraction is removed.

This reverts commit de28ae2d95.
This commit is contained in:
Harsh Shandilya 2022-03-02 23:50:14 +05:30
parent c556f26d77
commit 5b0d953210
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
4 changed files with 18 additions and 12 deletions

View file

@ -84,12 +84,12 @@ fun LobstersApp(
listOf(
NavigationItem(
label = "Hottest",
route = Destinations.Hottest.route,
route = Destinations.Hottest.getRoute(),
icon = painterResource(R.drawable.ic_whatshot_24dp),
) { coroutineScope.launch { networkListState.animateScrollToItem(index = 0) } },
NavigationItem(
label = "Saved",
route = Destinations.Saved.route,
route = Destinations.Saved.getRoute(),
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.route,
startDestination = Destinations.startDestination.getRoute(),
) {
val uri = LobstersApi.BASE_URL
composable(
route = Destinations.Hottest.route,
route = Destinations.Hottest.getRoute(),
deepLinks =
listOf(navDeepLink { uriPattern = uri }, navDeepLink { uriPattern = "$uri/" }),
) {
@ -157,7 +157,7 @@ fun LobstersApp(
modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()),
)
}
composable(Destinations.Saved.route) {
composable(Destinations.Saved.getRoute()) {
setWebUri(null)
DatabasePosts(
items = savedPosts,
@ -168,7 +168,7 @@ fun LobstersApp(
)
}
composable(
route = Destinations.Comments.route,
route = Destinations.Comments.getRoute("{postId}"),
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.route) {
if (navItem.route != Destinations.startDestination.getRoute()) {
navController.navigate(navItem.route)
}
}

View file

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

View file

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