mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 15:47: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(
|
listOf(
|
||||||
NavigationItem(
|
NavigationItem(
|
||||||
label = "Hottest",
|
label = "Hottest",
|
||||||
route = Destinations.Hottest.getRoute(),
|
route = Destinations.Hottest.route,
|
||||||
icon = ClawIcons.Flame,
|
icon = ClawIcons.Flame,
|
||||||
selectedIcon = ClawIcons.FlameFilled,
|
selectedIcon = ClawIcons.FlameFilled,
|
||||||
) {
|
) {
|
||||||
|
@ -96,7 +96,7 @@ fun LobstersApp(
|
||||||
},
|
},
|
||||||
NavigationItem(
|
NavigationItem(
|
||||||
label = "Newest",
|
label = "Newest",
|
||||||
route = Destinations.Newest.getRoute(),
|
route = Destinations.Newest.route,
|
||||||
icon = ClawIcons.New,
|
icon = ClawIcons.New,
|
||||||
selectedIcon = ClawIcons.NewFilled,
|
selectedIcon = ClawIcons.NewFilled,
|
||||||
) {
|
) {
|
||||||
|
@ -104,7 +104,7 @@ fun LobstersApp(
|
||||||
},
|
},
|
||||||
NavigationItem(
|
NavigationItem(
|
||||||
label = "Saved",
|
label = "Saved",
|
||||||
route = Destinations.Saved.getRoute(),
|
route = Destinations.Saved.route,
|
||||||
icon = ClawIcons.HeartBorder,
|
icon = ClawIcons.HeartBorder,
|
||||||
selectedIcon = ClawIcons.Heart,
|
selectedIcon = ClawIcons.Heart,
|
||||||
) {
|
) {
|
||||||
|
@ -158,12 +158,12 @@ fun LobstersApp(
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
MaterialMotionNavHost(
|
MaterialMotionNavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = Destinations.startDestination.getRoute(),
|
startDestination = Destinations.startDestination.route,
|
||||||
modifier = Modifier.padding(paddingValues),
|
modifier = Modifier.padding(paddingValues),
|
||||||
) {
|
) {
|
||||||
val uri = LobstersApi.BASE_URL
|
val uri = LobstersApi.BASE_URL
|
||||||
composable(
|
composable(
|
||||||
route = Destinations.Hottest.getRoute(),
|
route = Destinations.Hottest.route,
|
||||||
deepLinks =
|
deepLinks =
|
||||||
listOf(navDeepLink { uriPattern = uri }, navDeepLink { uriPattern = "$uri/" }),
|
listOf(navDeepLink { uriPattern = uri }, navDeepLink { uriPattern = "$uri/" }),
|
||||||
) {
|
) {
|
||||||
|
@ -177,7 +177,7 @@ fun LobstersApp(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(
|
composable(
|
||||||
route = Destinations.Newest.getRoute(),
|
route = Destinations.Newest.route,
|
||||||
) {
|
) {
|
||||||
setWebUri("https://lobste.rs/")
|
setWebUri("https://lobste.rs/")
|
||||||
NetworkPosts(
|
NetworkPosts(
|
||||||
|
@ -188,7 +188,7 @@ fun LobstersApp(
|
||||||
postActions = postActions,
|
postActions = postActions,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(Destinations.Saved.getRoute()) {
|
composable(Destinations.Saved.route) {
|
||||||
setWebUri(null)
|
setWebUri(null)
|
||||||
DatabasePosts(
|
DatabasePosts(
|
||||||
items = savedPosts,
|
items = savedPosts,
|
||||||
|
@ -197,12 +197,12 @@ fun LobstersApp(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(
|
composable(
|
||||||
route = Destinations.Comments.getRoute("{postId}"),
|
route = Destinations.Comments.route,
|
||||||
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
|
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
|
||||||
deepLinks =
|
deepLinks =
|
||||||
listOf(
|
listOf(
|
||||||
navDeepLink { uriPattern = "$uri/s/{postId}/.*" },
|
navDeepLink { uriPattern = "$uri/s/${Destinations.Comments.placeholder}/.*" },
|
||||||
navDeepLink { uriPattern = "$uri/s/{postId}" },
|
navDeepLink { uriPattern = "$uri/s/${Destinations.Comments.placeholder}" },
|
||||||
),
|
),
|
||||||
) { backStackEntry ->
|
) { backStackEntry ->
|
||||||
val postId = requireNotNull(backStackEntry.arguments?.getString("postId"))
|
val postId = requireNotNull(backStackEntry.arguments?.getString("postId"))
|
||||||
|
@ -214,9 +214,10 @@ fun LobstersApp(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(
|
composable(
|
||||||
route = Destinations.User.getRoute("{username}"),
|
route = Destinations.User.route,
|
||||||
arguments = listOf(navArgument("username") { type = NavType.StringType }),
|
arguments = listOf(navArgument("username") { type = NavType.StringType }),
|
||||||
deepLinks = listOf(navDeepLink { uriPattern = "$uri/u/{username}" }),
|
deepLinks =
|
||||||
|
listOf(navDeepLink { uriPattern = "$uri/u/${Destinations.User.placeholder}" }),
|
||||||
) { backStackEntry ->
|
) { backStackEntry ->
|
||||||
val username = requireNotNull(backStackEntry.arguments?.getString("username"))
|
val username = requireNotNull(backStackEntry.arguments?.getString("username"))
|
||||||
UserProfile(
|
UserProfile(
|
||||||
|
|
|
@ -62,7 +62,7 @@ fun ClawNavigationBar(
|
||||||
return@NavigationBarItem
|
return@NavigationBarItem
|
||||||
}
|
}
|
||||||
navController.popBackStack(navController.graph.startDestinationRoute!!, false)
|
navController.popBackStack(navController.graph.startDestinationRoute!!, false)
|
||||||
if (navItem.route != Destinations.startDestination.getRoute()) {
|
if (navItem.route != Destinations.startDestination.route) {
|
||||||
navController.navigate(navItem.route)
|
navController.navigate(navItem.route)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,9 @@ fun rememberPostActions(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun viewComments(postId: String) {
|
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) {
|
override fun viewCommentsPage(commentsUrl: String) {
|
||||||
|
|
|
@ -1,24 +1,28 @@
|
||||||
package dev.msfjarvis.claw.android.ui.navigation
|
package dev.msfjarvis.claw.android.ui.navigation
|
||||||
|
|
||||||
sealed class Destinations {
|
sealed class Destinations {
|
||||||
|
abstract val route: String
|
||||||
|
|
||||||
object Hottest : Destinations() {
|
object Hottest : Destinations() {
|
||||||
fun getRoute() = "hottest"
|
override val route = "hottest"
|
||||||
}
|
}
|
||||||
|
|
||||||
object Newest : Destinations() {
|
object Newest : Destinations() {
|
||||||
fun getRoute() = "newest"
|
override val route = "newest"
|
||||||
}
|
}
|
||||||
|
|
||||||
object Saved : Destinations() {
|
object Saved : Destinations() {
|
||||||
fun getRoute() = "saved"
|
override val route = "saved"
|
||||||
}
|
}
|
||||||
|
|
||||||
object Comments : Destinations() {
|
object Comments : Destinations() {
|
||||||
fun getRoute(postId: String) = "comments/$postId"
|
const val placeholder = "{postId}"
|
||||||
|
override val route = "comments/$placeholder"
|
||||||
}
|
}
|
||||||
|
|
||||||
object User : Destinations() {
|
object User : Destinations() {
|
||||||
fun getRoute(username: String) = "user/$username"
|
const val placeholder = "{username}"
|
||||||
|
override val route = "user/$placeholder"
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -3,9 +3,6 @@
|
||||||
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
||||||
<CurrentIssues>
|
<CurrentIssues>
|
||||||
<ID>ComposableParamOrder:LobstersApp.kt$LobstersApp</ID>
|
<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>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>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>
|
<ID>MagicNumber:ClawApplication.kt$ClawApplication$0.25</ID>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue