Compare commits
2 Commits
9361c7ef47
...
3137a1bb42
Author | SHA1 | Date |
---|---|---|
Harsh Shandilya | 3137a1bb42 | |
Harsh Shandilya | 127a69249e |
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- Bring back dividers between posts (I regret my earlier choices)
|
||||
- Upgrade to Compose May releases
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ plugins {
|
|||
alias(libs.plugins.baselineprofile)
|
||||
alias(libs.plugins.licensee)
|
||||
alias(libs.plugins.tracelog)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
alias(libs.plugins.navigation.safeargs)
|
||||
}
|
||||
|
||||
android {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2022-2023 Harsh Shandilya.
|
||||
* Copyright © 2022-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -22,7 +22,9 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.navigation.NavController
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Destinations
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import dev.msfjarvis.claw.android.ui.matches
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Destination
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
const val AnimationDuration = 100
|
||||
|
@ -51,11 +53,13 @@ fun ClawNavigationBar(
|
|||
modifier = Modifier,
|
||||
) {
|
||||
NavigationBar(modifier = modifier) {
|
||||
val navBackStackEntry = navController.currentBackStackEntryAsState().value
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
items.forEach { navItem ->
|
||||
val isCurrentDestination = navController.currentDestination?.route == navItem.route
|
||||
val isSelected = currentDestination.matches(navItem.destination)
|
||||
NavigationBarItem(
|
||||
icon = {
|
||||
Crossfade(isCurrentDestination, label = "nav-label") {
|
||||
Crossfade(isSelected, label = "nav-label") {
|
||||
Icon(
|
||||
imageVector = if (it) navItem.selectedIcon else navItem.icon,
|
||||
contentDescription = navItem.label.replaceFirstChar(Char::uppercase),
|
||||
|
@ -63,16 +67,15 @@ fun ClawNavigationBar(
|
|||
}
|
||||
},
|
||||
label = { Text(text = navItem.label) },
|
||||
selected = isCurrentDestination,
|
||||
selected = isSelected,
|
||||
onClick = {
|
||||
if (isCurrentDestination) {
|
||||
if (isSelected) {
|
||||
navItem.listStateResetCallback()
|
||||
} else {
|
||||
navController.graph.startDestinationRoute?.let { startDestination ->
|
||||
navController.popBackStack(startDestination, false)
|
||||
}
|
||||
if (navItem.route != Destinations.startDestination.route) {
|
||||
navController.navigate(navItem.route)
|
||||
navController.navigate(navItem.destination) {
|
||||
popUpTo(navController.graph.startDestinationId) { saveState = true }
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -85,7 +88,7 @@ fun ClawNavigationBar(
|
|||
|
||||
class NavigationItem(
|
||||
val label: String,
|
||||
val route: String,
|
||||
val destination: Destination,
|
||||
val icon: ImageVector,
|
||||
val selectedIcon: ImageVector,
|
||||
val listStateResetCallback: () -> Unit,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2022-2023 Harsh Shandilya.
|
||||
* Copyright © 2022-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -22,7 +22,8 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.navigation.NavController
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Destinations
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import dev.msfjarvis.claw.android.ui.matches
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
@Composable
|
||||
|
@ -49,12 +50,14 @@ fun ClawNavigationRail(
|
|||
modifier = Modifier,
|
||||
) {
|
||||
NavigationRail(modifier = modifier) {
|
||||
val navBackStackEntry = navController.currentBackStackEntryAsState().value
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
Spacer(Modifier.weight(1f))
|
||||
items.forEach { navItem ->
|
||||
val isCurrentDestination = navController.currentDestination?.route == navItem.route
|
||||
val isSelected = currentDestination.matches(navItem.destination)
|
||||
NavigationRailItem(
|
||||
icon = {
|
||||
Crossfade(isCurrentDestination, label = "nav-label") {
|
||||
Crossfade(isSelected, label = "nav-label") {
|
||||
Icon(
|
||||
imageVector = if (it) navItem.selectedIcon else navItem.icon,
|
||||
contentDescription = navItem.label.replaceFirstChar(Char::uppercase),
|
||||
|
@ -62,16 +65,15 @@ fun ClawNavigationRail(
|
|||
}
|
||||
},
|
||||
label = { Text(text = navItem.label) },
|
||||
selected = isCurrentDestination,
|
||||
selected = isSelected,
|
||||
onClick = {
|
||||
if (isCurrentDestination) {
|
||||
if (isSelected) {
|
||||
navItem.listStateResetCallback()
|
||||
} else {
|
||||
navController.graph.startDestinationRoute?.let { startDestination ->
|
||||
navController.popBackStack(startDestination, false)
|
||||
}
|
||||
if (navItem.route != Destinations.startDestination.route) {
|
||||
navController.navigate(navItem.route)
|
||||
navController.navigate(navItem.destination) {
|
||||
popUpTo(navController.graph.startDestinationId) { saveState = true }
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -12,12 +12,17 @@ import androidx.activity.ComponentActivity
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.navigation.NavController
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Destinations
|
||||
import androidx.navigation.NavDestination
|
||||
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Comments
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Destination
|
||||
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
||||
import dev.msfjarvis.claw.common.posts.PostActions
|
||||
import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
|
||||
import dev.msfjarvis.claw.model.LinkMetadata
|
||||
import dev.msfjarvis.claw.model.UIPost
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
fun Context.getActivity(): ComponentActivity? {
|
||||
return when (this) {
|
||||
|
@ -42,10 +47,7 @@ fun rememberPostActions(
|
|||
|
||||
override fun viewComments(postId: String) {
|
||||
viewModel.markPostAsRead(postId)
|
||||
val currentRoute = navController.currentDestination?.route
|
||||
val newRoute =
|
||||
Destinations.Comments.route.replace(Destinations.Comments.PLACEHOLDER, postId)
|
||||
if (currentRoute != Destinations.Comments.route) navController.navigate(newRoute)
|
||||
navController.navigate(Comments(postId))
|
||||
}
|
||||
|
||||
override fun viewCommentsPage(post: UIPost) {
|
||||
|
@ -66,3 +68,21 @@ fun rememberPostActions(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk through the [NavDestination]'s [hierarchy] to see if it has any destination that matches the
|
||||
* route defined by [dest].
|
||||
*/
|
||||
fun NavDestination?.matches(dest: Destination): Boolean {
|
||||
return this?.hierarchy?.any { it.hasRoute(dest::class) } == true
|
||||
}
|
||||
|
||||
/** Check if this [NavDestination] [matches] any of the potential navigation [destinations]. */
|
||||
fun NavDestination?.any(destinations: ImmutableList<Destination>): Boolean {
|
||||
return destinations.any { this?.matches(it) == true }
|
||||
}
|
||||
|
||||
/** Check if this [NavDestination] [matches] none of the potential navigation [destinations]. */
|
||||
fun NavDestination?.none(destinations: ImmutableList<Destination>): Boolean {
|
||||
return destinations.none { this?.matches(it) == true }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright © 2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.android.ui.navigation
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
sealed interface Destination
|
||||
|
||||
@Serializable data object Hottest : Destination
|
||||
|
||||
@Serializable data object Newest : Destination
|
||||
|
||||
@Serializable data object Saved : Destination
|
||||
|
||||
@Serializable data class Comments(val postId: String) : Destination
|
||||
|
||||
@Serializable data class User(val username: String) : Destination
|
||||
|
||||
@Serializable data object Search : Destination
|
||||
|
||||
@Serializable data object Settings : Destination
|
||||
|
||||
@Serializable data object AboutLibraries : Destination
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2021-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.android.ui.navigation
|
||||
|
||||
sealed class Destinations {
|
||||
abstract val route: String
|
||||
|
||||
data object Hottest : Destinations() {
|
||||
override val route = "hottest"
|
||||
}
|
||||
|
||||
data object Newest : Destinations() {
|
||||
override val route = "newest"
|
||||
}
|
||||
|
||||
data object Saved : Destinations() {
|
||||
override val route = "saved"
|
||||
}
|
||||
|
||||
data object Comments : Destinations() {
|
||||
const val PLACEHOLDER = "{postId}"
|
||||
override val route = "comments/$PLACEHOLDER"
|
||||
}
|
||||
|
||||
data object User : Destinations() {
|
||||
const val PLACEHOLDER = "{username}"
|
||||
override val route = "user/$PLACEHOLDER"
|
||||
}
|
||||
|
||||
data object Search : Destinations() {
|
||||
override val route = "search"
|
||||
}
|
||||
|
||||
data object Settings : Destinations() {
|
||||
override val route = "settings"
|
||||
}
|
||||
|
||||
data object AboutLibraries : Destinations() {
|
||||
override val route = "about_libraries"
|
||||
}
|
||||
|
||||
companion object {
|
||||
val startDestination
|
||||
get() = Hottest
|
||||
}
|
||||
}
|
|
@ -52,26 +52,33 @@ import androidx.compose.ui.semantics.semantics
|
|||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import androidx.navigation.toRoute
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import com.deliveryhero.whetstone.compose.injectedViewModel
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
|
||||
import dev.msfjarvis.claw.android.MainActivity
|
||||
import dev.msfjarvis.claw.android.R
|
||||
import dev.msfjarvis.claw.android.SearchActivity
|
||||
import dev.msfjarvis.claw.android.ui.any
|
||||
import dev.msfjarvis.claw.android.ui.decorations.ClawNavigationBar
|
||||
import dev.msfjarvis.claw.android.ui.decorations.ClawNavigationRail
|
||||
import dev.msfjarvis.claw.android.ui.decorations.NavigationItem
|
||||
import dev.msfjarvis.claw.android.ui.getActivity
|
||||
import dev.msfjarvis.claw.android.ui.lists.DatabasePosts
|
||||
import dev.msfjarvis.claw.android.ui.lists.NetworkPosts
|
||||
import dev.msfjarvis.claw.android.ui.navigation.AboutLibraries
|
||||
import dev.msfjarvis.claw.android.ui.navigation.ClawNavigationType
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Destinations
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Comments
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Hottest
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Newest
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Saved
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Settings
|
||||
import dev.msfjarvis.claw.android.ui.navigation.User
|
||||
import dev.msfjarvis.claw.android.ui.none
|
||||
import dev.msfjarvis.claw.android.ui.rememberPostActions
|
||||
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
||||
import dev.msfjarvis.claw.common.comments.CommentsPage
|
||||
|
@ -81,6 +88,7 @@ import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
|
|||
import dev.msfjarvis.claw.common.user.UserProfile
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.persistentMapOf
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
|
@ -97,11 +105,11 @@ fun LobstersPostsScreen(
|
|||
val newestListState = rememberLazyListState()
|
||||
val savedListState = rememberLazyListState()
|
||||
val navController = rememberNavController()
|
||||
val navBackStackEntry = navController.currentBackStackEntryAsState().value
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val postActions = rememberPostActions(urlLauncher, navController, viewModel)
|
||||
val backStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = backStackEntry?.destination?.route
|
||||
val context = LocalContext.current
|
||||
|
||||
val hottestPosts = viewModel.hottestPosts.collectAsLazyPagingItems()
|
||||
|
@ -113,9 +121,7 @@ fun LobstersPostsScreen(
|
|||
val postIdOverride = context.getActivity()?.intent?.extras?.getString(MainActivity.NAVIGATION_KEY)
|
||||
LaunchedEffect(false) {
|
||||
if (postIdOverride != null) {
|
||||
navController.navigate(
|
||||
Destinations.Comments.route.replace(Destinations.Comments.PLACEHOLDER, postIdOverride)
|
||||
)
|
||||
navController.navigate(Comments(postIdOverride))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +129,7 @@ fun LobstersPostsScreen(
|
|||
persistentListOf(
|
||||
NavigationItem(
|
||||
label = "Hottest",
|
||||
route = Destinations.Hottest.route,
|
||||
destination = Hottest,
|
||||
icon = Icons.Outlined.Whatshot,
|
||||
selectedIcon = Icons.Filled.Whatshot,
|
||||
) {
|
||||
|
@ -133,7 +139,7 @@ fun LobstersPostsScreen(
|
|||
},
|
||||
NavigationItem(
|
||||
label = "Newest",
|
||||
route = Destinations.Newest.route,
|
||||
destination = Newest,
|
||||
icon = Icons.Outlined.NewReleases,
|
||||
selectedIcon = Icons.Filled.NewReleases,
|
||||
) {
|
||||
|
@ -143,7 +149,7 @@ fun LobstersPostsScreen(
|
|||
},
|
||||
NavigationItem(
|
||||
label = "Saved",
|
||||
route = Destinations.Saved.route,
|
||||
destination = Saved,
|
||||
icon = Icons.Outlined.FavoriteBorder,
|
||||
selectedIcon = Icons.Filled.Favorite,
|
||||
) {
|
||||
|
@ -152,14 +158,14 @@ fun LobstersPostsScreen(
|
|||
}
|
||||
},
|
||||
)
|
||||
val navDestinations = navItems.map(NavigationItem::destination).toPersistentList()
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
ClawAppBar(
|
||||
navigationIcon = {
|
||||
if (
|
||||
navController.previousBackStackEntry != null &&
|
||||
navItems.none { it.route == currentDestination }
|
||||
navController.previousBackStackEntry != null && currentDestination.none(navDestinations)
|
||||
) {
|
||||
IconButton(
|
||||
onClick = { if (!navController.popBackStack()) context.getActivity()?.finish() }
|
||||
|
@ -172,7 +178,7 @@ fun LobstersPostsScreen(
|
|||
}
|
||||
},
|
||||
title = {
|
||||
if (navItems.any { it.route == currentDestination }) {
|
||||
if (currentDestination.any(navDestinations)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.ic_launcher_foreground),
|
||||
|
@ -185,13 +191,13 @@ fun LobstersPostsScreen(
|
|||
}
|
||||
},
|
||||
actions = {
|
||||
if (navItems.any { it.route == currentDestination }) {
|
||||
if (currentDestination.any(navDestinations)) {
|
||||
IconButton(
|
||||
onClick = { context.startActivity(Intent(context, SearchActivity::class.java)) }
|
||||
) {
|
||||
Icon(imageVector = Icons.Filled.Search, contentDescription = "Search posts")
|
||||
}
|
||||
IconButton(onClick = { navController.navigate(Destinations.Settings.route) }) {
|
||||
IconButton(onClick = { navController.navigate(Settings) }) {
|
||||
Icon(imageVector = Icons.Filled.Tune, contentDescription = "Settings")
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +209,7 @@ fun LobstersPostsScreen(
|
|||
ClawNavigationBar(
|
||||
navController = navController,
|
||||
items = navItems,
|
||||
isVisible = navItems.any { it.route == currentDestination },
|
||||
isVisible = currentDestination.any(navDestinations),
|
||||
)
|
||||
}
|
||||
},
|
||||
|
@ -215,18 +221,18 @@ fun LobstersPostsScreen(
|
|||
ClawNavigationRail(
|
||||
navController = navController,
|
||||
items = navItems,
|
||||
isVisible = navItems.any { it.route == currentDestination },
|
||||
isVisible = currentDestination.any(navDestinations),
|
||||
)
|
||||
}
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = Destinations.startDestination.route,
|
||||
startDestination = Hottest,
|
||||
// Make animations 2x faster than default specs
|
||||
enterTransition = { fadeIn(animationSpec = tween(350)) },
|
||||
exitTransition = { fadeOut(animationSpec = tween(350)) },
|
||||
) {
|
||||
composable(route = Destinations.Hottest.route) {
|
||||
composable<Hottest> {
|
||||
setWebUri("https://lobste.rs/")
|
||||
NetworkPosts(
|
||||
lazyPagingItems = hottestPosts,
|
||||
|
@ -234,7 +240,7 @@ fun LobstersPostsScreen(
|
|||
postActions = postActions,
|
||||
)
|
||||
}
|
||||
composable(route = Destinations.Newest.route) {
|
||||
composable<Newest> {
|
||||
setWebUri("https://lobste.rs/")
|
||||
NetworkPosts(
|
||||
lazyPagingItems = newestPosts,
|
||||
|
@ -242,64 +248,42 @@ fun LobstersPostsScreen(
|
|||
postActions = postActions,
|
||||
)
|
||||
}
|
||||
composable(route = Destinations.Saved.route) {
|
||||
composable<Saved> {
|
||||
setWebUri(null)
|
||||
DatabasePosts(items = savedPosts, listState = savedListState, postActions = postActions)
|
||||
}
|
||||
composable(
|
||||
route = Destinations.Comments.route,
|
||||
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
|
||||
) { backStackEntry ->
|
||||
val postId =
|
||||
requireNotNull(backStackEntry.arguments?.getString("postId")) {
|
||||
"Navigating to ${Destinations.Comments.route} without necessary 'postId' argument"
|
||||
}
|
||||
setWebUri("https://lobste.rs/s/$postId")
|
||||
composable<Comments> { backStackEntry ->
|
||||
val postId = backStackEntry.toRoute<Comments>().postId
|
||||
setWebUri("https://lobste.rs/s/${postId}")
|
||||
CommentsPage(
|
||||
postId = postId,
|
||||
postActions = postActions,
|
||||
htmlConverter = htmlConverter,
|
||||
getSeenComments = viewModel::getSeenComments,
|
||||
markSeenComments = viewModel::markSeenComments,
|
||||
openUserProfile = {
|
||||
navController.navigate(
|
||||
Destinations.User.route.replace(Destinations.User.PLACEHOLDER, it)
|
||||
)
|
||||
},
|
||||
openUserProfile = { navController.navigate(User(it)) },
|
||||
)
|
||||
}
|
||||
composable(
|
||||
route = Destinations.User.route,
|
||||
arguments = listOf(navArgument("username") { type = NavType.StringType }),
|
||||
) { backStackEntry ->
|
||||
val username =
|
||||
requireNotNull(backStackEntry.arguments?.getString("username")) {
|
||||
"Navigating to ${Destinations.User.route} without necessary 'username' argument"
|
||||
}
|
||||
setWebUri("https://lobste.rs/u/$username")
|
||||
composable<User> { backStackEntry ->
|
||||
val username = backStackEntry.toRoute<User>().username
|
||||
setWebUri("https://lobste.rs/u/${username}")
|
||||
UserProfile(
|
||||
username = username,
|
||||
getProfile = viewModel::getUserProfile,
|
||||
openUserProfile = {
|
||||
navController.navigate(
|
||||
Destinations.User.route.replace(Destinations.User.PLACEHOLDER, it)
|
||||
)
|
||||
},
|
||||
openUserProfile = { navController.navigate(User(it)) },
|
||||
)
|
||||
}
|
||||
composable(route = Destinations.Settings.route) {
|
||||
composable<Settings> {
|
||||
SettingsScreen(
|
||||
context = context,
|
||||
openLibrariesScreen = { navController.navigate(Destinations.AboutLibraries.route) },
|
||||
openLibrariesScreen = { navController.navigate(AboutLibraries) },
|
||||
importPosts = viewModel::importPosts,
|
||||
exportPostsAsJson = viewModel::exportPostsAsJson,
|
||||
exportPostsAsHtml = viewModel::exportPostsAsHtml,
|
||||
snackbarHostState = snackbarHostState,
|
||||
)
|
||||
}
|
||||
composable(route = Destinations.AboutLibraries.route) {
|
||||
LibrariesContainer(modifier = Modifier.fillMaxSize())
|
||||
}
|
||||
composable<Settings> { LibrariesContainer(modifier = Modifier.fillMaxSize()) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,15 @@ import androidx.compose.foundation.lazy.rememberLazyListState
|
|||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import androidx.navigation.toRoute
|
||||
import com.deliveryhero.whetstone.compose.injectedViewModel
|
||||
import dev.msfjarvis.claw.android.ui.lists.SearchList
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Destinations
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Comments
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Search
|
||||
import dev.msfjarvis.claw.android.ui.navigation.User
|
||||
import dev.msfjarvis.claw.android.ui.rememberPostActions
|
||||
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
||||
import dev.msfjarvis.claw.common.comments.CommentsPage
|
||||
|
@ -40,10 +41,10 @@ fun SearchScreen(
|
|||
Scaffold(modifier = modifier) { paddingValues ->
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = Destinations.Search.route,
|
||||
startDestination = Search,
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
) {
|
||||
composable(route = Destinations.Search.route) {
|
||||
composable<Search> {
|
||||
setWebUri("https://lobste.rs/search")
|
||||
SearchList(
|
||||
items = viewModel.searchResults,
|
||||
|
@ -53,14 +54,8 @@ fun SearchScreen(
|
|||
setSearchQuery = { query -> viewModel.searchQuery = query },
|
||||
)
|
||||
}
|
||||
composable(
|
||||
route = Destinations.Comments.route,
|
||||
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
|
||||
) { backStackEntry ->
|
||||
val postId =
|
||||
requireNotNull(backStackEntry.arguments?.getString("postId")) {
|
||||
"Navigating to ${Destinations.Comments.route} without necessary 'postId' argument"
|
||||
}
|
||||
composable<Comments> { backStackEntry ->
|
||||
val postId = backStackEntry.toRoute<Comments>().postId
|
||||
setWebUri("https://lobste.rs/s/$postId")
|
||||
CommentsPage(
|
||||
postId = postId,
|
||||
|
@ -68,30 +63,16 @@ fun SearchScreen(
|
|||
htmlConverter = htmlConverter,
|
||||
getSeenComments = viewModel::getSeenComments,
|
||||
markSeenComments = viewModel::markSeenComments,
|
||||
openUserProfile = { username: String ->
|
||||
navController.navigate(
|
||||
Destinations.User.route.replace(Destinations.User.PLACEHOLDER, username)
|
||||
)
|
||||
},
|
||||
openUserProfile = { navController.navigate(User(it)) },
|
||||
)
|
||||
}
|
||||
composable(
|
||||
route = Destinations.User.route,
|
||||
arguments = listOf(navArgument("username") { type = NavType.StringType }),
|
||||
) { backStackEntry ->
|
||||
val username =
|
||||
requireNotNull(backStackEntry.arguments?.getString("username")) {
|
||||
"Navigating to ${Destinations.User.route} without necessary 'username' argument"
|
||||
}
|
||||
composable<User> { backStackEntry ->
|
||||
val username = backStackEntry.toRoute<User>().username
|
||||
setWebUri("https://lobste.rs/u/$username")
|
||||
UserProfile(
|
||||
username = username,
|
||||
getProfile = viewModel::getUserProfile,
|
||||
openUserProfile = {
|
||||
navController.navigate(
|
||||
Destinations.User.route.replace(Destinations.User.PLACEHOLDER, it)
|
||||
)
|
||||
},
|
||||
openUserProfile = { navController.navigate(User(it)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ konvert = "3.2.0"
|
|||
kotlin = "1.9.23"
|
||||
kotlinResult = "2.0.0"
|
||||
lifecycle = "2.8.0-rc01"
|
||||
navigation = "2.8.0-alpha08"
|
||||
retrofit = "2.11.0"
|
||||
richtext = "1.0.0-alpha01"
|
||||
sentry-sdk = "7.8.0"
|
||||
|
@ -47,7 +48,7 @@ androidx-lifecycle-common = { module = "androidx.lifecycle:lifecycle-common", ve
|
|||
androidx-lifecycle-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle" }
|
||||
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime", version.ref = "lifecycle" }
|
||||
androidx-lint = "androidx.lint:lint-gradle:1.0.0-alpha01"
|
||||
androidx-navigation-compose = "androidx.navigation:navigation-compose:2.8.0-alpha08"
|
||||
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigation" }
|
||||
androidx-paging-compose = "androidx.paging:paging-compose:3.3.0-rc01"
|
||||
androidx-profileinstaller = "androidx.profileinstaller:profileinstaller:1.4.0-alpha01"
|
||||
androidx-test-core = "androidx.test:core:1.6.0-alpha06"
|
||||
|
@ -122,6 +123,7 @@ kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", versi
|
|||
ksp = "com.google.devtools.ksp:1.9.23-1.0.20"
|
||||
licensee = "app.cash.licensee:1.11.0"
|
||||
modulegraphassert = "com.jraska.module.graph.assertion:2.5.0"
|
||||
navigation-safeargs = { id = "androidx.navigation.safeargs.kotlin", version.ref = "navigation" }
|
||||
poko = "dev.drewhamilton.poko:0.15.2"
|
||||
sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
|
||||
tracelog = "dev.msfjarvis.tracelog:0.1.3"
|
||||
|
|
|
@ -14,6 +14,7 @@ pluginManagement {
|
|||
includeGroup("androidx.baselineprofile")
|
||||
includeGroup("androidx.benchmark")
|
||||
includeGroup("androidx.databinding")
|
||||
includeGroupAndSubgroups("androidx.navigation")
|
||||
includeGroup("com.google.testing.platform")
|
||||
includeGroupAndSubgroups("com.android")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue