mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 05:57:03 +05:30
refactor(android): simplify Destinations
This commit is contained in:
parent
52ac8346b3
commit
999f2dfb01
5 changed files with 26 additions and 22 deletions
|
@ -88,7 +88,7 @@ fun LobstersApp(
|
|||
listOf(
|
||||
NavigationItem(
|
||||
label = "Hottest",
|
||||
route = Destinations.Hottest.getRoute(),
|
||||
route = Destinations.Hottest.route,
|
||||
icon = ClawIcons.Flame,
|
||||
selectedIcon = ClawIcons.FlameFilled,
|
||||
) {
|
||||
|
@ -96,7 +96,7 @@ fun LobstersApp(
|
|||
},
|
||||
NavigationItem(
|
||||
label = "Newest",
|
||||
route = Destinations.Newest.getRoute(),
|
||||
route = Destinations.Newest.route,
|
||||
icon = ClawIcons.New,
|
||||
selectedIcon = ClawIcons.NewFilled,
|
||||
) {
|
||||
|
@ -104,7 +104,7 @@ fun LobstersApp(
|
|||
},
|
||||
NavigationItem(
|
||||
label = "Saved",
|
||||
route = Destinations.Saved.getRoute(),
|
||||
route = Destinations.Saved.route,
|
||||
icon = ClawIcons.HeartBorder,
|
||||
selectedIcon = ClawIcons.Heart,
|
||||
) {
|
||||
|
@ -158,12 +158,12 @@ fun LobstersApp(
|
|||
) { paddingValues ->
|
||||
MaterialMotionNavHost(
|
||||
navController = navController,
|
||||
startDestination = Destinations.startDestination.getRoute(),
|
||||
startDestination = Destinations.startDestination.route,
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
) {
|
||||
val uri = LobstersApi.BASE_URL
|
||||
composable(
|
||||
route = Destinations.Hottest.getRoute(),
|
||||
route = Destinations.Hottest.route,
|
||||
deepLinks =
|
||||
listOf(navDeepLink { uriPattern = uri }, navDeepLink { uriPattern = "$uri/" }),
|
||||
) {
|
||||
|
@ -177,7 +177,7 @@ fun LobstersApp(
|
|||
)
|
||||
}
|
||||
composable(
|
||||
route = Destinations.Newest.getRoute(),
|
||||
route = Destinations.Newest.route,
|
||||
) {
|
||||
setWebUri("https://lobste.rs/")
|
||||
NetworkPosts(
|
||||
|
@ -188,7 +188,7 @@ fun LobstersApp(
|
|||
postActions = postActions,
|
||||
)
|
||||
}
|
||||
composable(Destinations.Saved.getRoute()) {
|
||||
composable(Destinations.Saved.route) {
|
||||
setWebUri(null)
|
||||
DatabasePosts(
|
||||
items = savedPosts,
|
||||
|
@ -197,12 +197,12 @@ fun LobstersApp(
|
|||
)
|
||||
}
|
||||
composable(
|
||||
route = Destinations.Comments.getRoute("{postId}"),
|
||||
route = Destinations.Comments.route,
|
||||
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
|
||||
deepLinks =
|
||||
listOf(
|
||||
navDeepLink { uriPattern = "$uri/s/{postId}/.*" },
|
||||
navDeepLink { uriPattern = "$uri/s/{postId}" },
|
||||
navDeepLink { uriPattern = "$uri/s/${Destinations.Comments.placeholder}/.*" },
|
||||
navDeepLink { uriPattern = "$uri/s/${Destinations.Comments.placeholder}" },
|
||||
),
|
||||
) { backStackEntry ->
|
||||
val postId = requireNotNull(backStackEntry.arguments?.getString("postId"))
|
||||
|
@ -214,9 +214,10 @@ fun LobstersApp(
|
|||
)
|
||||
}
|
||||
composable(
|
||||
route = Destinations.User.getRoute("{username}"),
|
||||
route = Destinations.User.route,
|
||||
arguments = listOf(navArgument("username") { type = NavType.StringType }),
|
||||
deepLinks = listOf(navDeepLink { uriPattern = "$uri/u/{username}" }),
|
||||
deepLinks =
|
||||
listOf(navDeepLink { uriPattern = "$uri/u/${Destinations.User.placeholder}" }),
|
||||
) { backStackEntry ->
|
||||
val username = requireNotNull(backStackEntry.arguments?.getString("username"))
|
||||
UserProfile(
|
||||
|
|
|
@ -62,7 +62,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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,9 @@ fun rememberPostActions(
|
|||
}
|
||||
|
||||
override fun viewComments(postId: String) {
|
||||
navController.navigate(Destinations.Comments.getRoute(postId))
|
||||
navController.navigate(
|
||||
Destinations.Comments.route.replace(Destinations.Comments.placeholder, postId)
|
||||
)
|
||||
}
|
||||
|
||||
override fun viewCommentsPage(commentsUrl: String) {
|
||||
|
|
|
@ -1,24 +1,28 @@
|
|||
package dev.msfjarvis.claw.android.ui.navigation
|
||||
|
||||
sealed class Destinations {
|
||||
abstract val route: String
|
||||
|
||||
object Hottest : Destinations() {
|
||||
fun getRoute() = "hottest"
|
||||
override val route = "hottest"
|
||||
}
|
||||
|
||||
object Newest : Destinations() {
|
||||
fun getRoute() = "newest"
|
||||
override val route = "newest"
|
||||
}
|
||||
|
||||
object Saved : Destinations() {
|
||||
fun getRoute() = "saved"
|
||||
override val route = "saved"
|
||||
}
|
||||
|
||||
object Comments : Destinations() {
|
||||
fun getRoute(postId: String) = "comments/$postId"
|
||||
const val placeholder = "{postId}"
|
||||
override val route = "comments/$placeholder"
|
||||
}
|
||||
|
||||
object User : Destinations() {
|
||||
fun getRoute(username: String) = "user/$username"
|
||||
const val placeholder = "{username}"
|
||||
override val route = "user/$placeholder"
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -3,9 +3,6 @@
|
|||
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
||||
<CurrentIssues>
|
||||
<ID>ComposableParamOrder:LobstersApp.kt$LobstersApp</ID>
|
||||
<ID>FunctionOnlyReturningConstant:Destinations.kt$Destinations.Hottest$fun getRoute()</ID>
|
||||
<ID>FunctionOnlyReturningConstant:Destinations.kt$Destinations.Newest$fun getRoute()</ID>
|
||||
<ID>FunctionOnlyReturningConstant:Destinations.kt$Destinations.Saved$fun getRoute()</ID>
|
||||
<ID>LongMethod:LobstersApp.kt$@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class) @Composable fun LobstersApp( viewModel: ClawViewModel = viewModel(), urlLauncher: UrlLauncher, htmlConverter: HTMLConverter, setWebUri: (String?) -> Unit, )</ID>
|
||||
<ID>LongParameterList:NetworkPosts.kt$( items: LazyPagingItems<LobstersPost>, listState: LazyListState, isPostSaved: suspend (SavedPost) -> Boolean, reloadPosts: () -> Unit, postActions: PostActions, modifier: Modifier = Modifier, )</ID>
|
||||
<ID>MagicNumber:ClawApplication.kt$ClawApplication$0.25</ID>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue