diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/Destinations.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/Destinations.kt index 1e0d07e5..16b99d3b 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/Destinations.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/Destinations.kt @@ -1,6 +1,11 @@ package dev.msfjarvis.claw.android.ui -object Destinations { - const val Hottest = "hottest" - const val Comments = "comments/%s" +sealed class Destinations(internal val route: String) { + object Hottest : Destinations("hottest") { + fun getRoute() = route + } + + object Comments : Destinations("comments/%s") { + fun getRoute(postId: String) = route.format(postId) + } } diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt index 9a21be8b..e7c0ccd5 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt @@ -51,7 +51,7 @@ fun LobstersApp( val scaffoldState = rememberScaffoldState() val listState = rememberLazyListState() val navController = rememberNavController() - var currentDestination by remember { mutableStateOf(Destinations.Hottest) } + var currentDestination by remember { mutableStateOf(Destinations.Hottest.getRoute()) } var isFabVisible by remember { mutableStateOf(false) } val nestedScrollConnection = remember { object : NestedScrollConnection { @@ -76,7 +76,7 @@ fun LobstersApp( } override fun viewComments(postId: String) { - navController.navigate(Destinations.Comments.format(postId)) + navController.navigate(Destinations.Comments.getRoute(postId)) } override fun viewCommentsPage(commentsUrl: String) { @@ -89,7 +89,7 @@ fun LobstersApp( } } navController.addOnDestinationChangedListener { _, destination, _ -> - currentDestination = destination.route ?: Destinations.Hottest + currentDestination = destination.route ?: Destinations.Hottest.getRoute() } LobstersTheme( providedValues = @@ -113,14 +113,14 @@ fun LobstersApp( topBar = { ClawAppBar(modifier = Modifier.statusBarsPadding()) }, floatingActionButton = { ClawFab( - isFabVisible = isFabVisible && currentDestination == Destinations.Hottest, + isFabVisible = isFabVisible && currentDestination == Destinations.Hottest.getRoute(), listState = listState, modifier = Modifier.navigationBarsPadding(), ) }, ) { - NavHost(navController, startDestination = Destinations.Hottest) { - composable(Destinations.Hottest) { + NavHost(navController, startDestination = Destinations.Hottest.getRoute()) { + composable(Destinations.Hottest.getRoute()) { setWebUri("https://lobste.rs/") HottestPosts( items, @@ -131,7 +131,7 @@ fun LobstersApp( Modifier.nestedScroll(nestedScrollConnection), ) } - composable(Destinations.Comments.format("{postId}")) { backStackEntry -> + composable(Destinations.Comments.getRoute("{postId}")) { backStackEntry -> val postId = requireNotNull(backStackEntry.arguments?.getString("postId")) setWebUri("https://lobste.rs/s/$postId") CommentsPage(