app: add comment open action

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-09-27 14:14:12 +05:30
parent ac336efa33
commit c21a2bf13a
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 13 additions and 7 deletions

View file

@ -56,9 +56,11 @@ fun LobstersApp(
if (lastIndex == index) {
viewModel.getMorePosts()
}
LobstersItem(item) { post ->
urlLauncher.launch(post.url)
}
LobstersItem(
item,
linkOpenAction = { post -> urlLauncher.launch(post.url) },
commentOpenAction = { post -> urlLauncher.launch(post.commentsUrl) },
)
}
}
)

View file

@ -25,12 +25,16 @@ import dev.msfjarvis.lobsters.model.Submitter
fun LazyItemScope.LobstersItem(
post: LobstersPost,
modifier: Modifier = Modifier,
onClick: (LobstersPost) -> Unit,
linkOpenAction: (LobstersPost) -> Unit,
commentOpenAction: (LobstersPost) -> Unit,
) {
ListItem(
modifier = modifier.padding(horizontal = 8.dp)
.fillParentMaxWidth()
.clickable(onClick = { onClick.invoke(post) }),
.clickable(
onClick = { linkOpenAction.invoke(post) },
onLongClick = { commentOpenAction.invoke(post) }
),
text = {
Text(
text = post.title,
@ -92,7 +96,7 @@ fun PreviewLobstersItem() {
)
LobstersTheme {
LazyColumnFor(items = listOf(post)) { item ->
LobstersItem(post = item, onClick = {})
LobstersItem(post = item, linkOpenAction = {}, commentOpenAction = {})
}
}
}
}