mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 19:57:04 +05:30
common: integrate LinkMetadata
This commit is contained in:
parent
2ca150c666
commit
a3520c818b
6 changed files with 33 additions and 9 deletions
|
@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.Spacer
|
|||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
|
@ -31,9 +32,11 @@ import dev.msfjarvis.claw.common.posts.PostTitle
|
|||
import dev.msfjarvis.claw.common.posts.Submitter
|
||||
import dev.msfjarvis.claw.common.posts.TagRow
|
||||
import dev.msfjarvis.claw.common.res.ClawIcons
|
||||
import dev.msfjarvis.claw.common.ui.NetworkImage
|
||||
import dev.msfjarvis.claw.common.ui.ThemedRichText
|
||||
import dev.msfjarvis.claw.model.Comment
|
||||
import dev.msfjarvis.claw.model.ExtendedPostDetails
|
||||
import dev.msfjarvis.claw.model.LinkMetadata
|
||||
|
||||
@Composable
|
||||
fun CommentsHeader(
|
||||
|
@ -54,7 +57,7 @@ fun CommentsHeader(
|
|||
|
||||
if (postDetails.linkMetadata.url.isNotBlank()) {
|
||||
PostLink(
|
||||
link = postDetails.linkMetadata.url,
|
||||
linkMetadata = postDetails.linkMetadata,
|
||||
modifier =
|
||||
Modifier.clickable {
|
||||
postActions.viewPost(postDetails.linkMetadata.url, postDetails.commentsUrl)
|
||||
|
@ -82,7 +85,7 @@ fun CommentsHeader(
|
|||
|
||||
@Composable
|
||||
fun PostLink(
|
||||
link: String,
|
||||
linkMetadata: LinkMetadata,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Box(
|
||||
|
@ -92,13 +95,22 @@ fun PostLink(
|
|||
)
|
||||
) {
|
||||
Row(modifier = Modifier.padding(16.dp), horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
Icon(
|
||||
painter = ClawIcons.Web,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSecondary,
|
||||
)
|
||||
if (linkMetadata.faviconUrl != null) {
|
||||
NetworkImage(
|
||||
url = linkMetadata.faviconUrl!!,
|
||||
placeholder = ClawIcons.Web,
|
||||
contentDescription = "",
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
painter = ClawIcons.Web,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSecondary,
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = link,
|
||||
text = linkMetadata.url,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
color = MaterialTheme.colorScheme.onSecondary,
|
||||
|
|
|
@ -143,6 +143,7 @@ fun Submitter(
|
|||
) {
|
||||
NetworkImage(
|
||||
url = avatarUrl,
|
||||
placeholder = ClawIcons.Account,
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier.requiredSize(24.dp).clip(CircleShape),
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.msfjarvis.claw.common.res
|
||||
|
||||
import dev.msfjarvis.claw.common.res.clawicons.account_circle_black_24dp
|
||||
import dev.msfjarvis.claw.common.res.clawicons.arrow_back_black_24dp
|
||||
import dev.msfjarvis.claw.common.res.clawicons.comment_black_24dp
|
||||
import dev.msfjarvis.claw.common.res.clawicons.favorite_black_24dp
|
||||
|
@ -12,6 +13,8 @@ import dev.msfjarvis.claw.common.res.clawicons.whatshot_filled_black_24dp
|
|||
|
||||
object ClawIcons {
|
||||
|
||||
val Account = account_circle_black_24dp()
|
||||
|
||||
val ArrowBack = arrow_back_black_24dp()
|
||||
|
||||
val Comment = comment_black_24dp()
|
||||
|
|
|
@ -4,16 +4,21 @@ import androidx.compose.foundation.shape.CircleShape
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import coil.compose.AsyncImage
|
||||
|
||||
@Composable
|
||||
fun NetworkImage(
|
||||
url: String,
|
||||
placeholder: Painter,
|
||||
contentDescription: String,
|
||||
modifier: Modifier,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
AsyncImage(
|
||||
model = url,
|
||||
placeholder = placeholder,
|
||||
error = placeholder,
|
||||
fallback = placeholder,
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier.clip(CircleShape)
|
||||
)
|
||||
|
|
|
@ -19,6 +19,7 @@ import androidx.compose.ui.unit.dp
|
|||
import dev.msfjarvis.claw.common.NetworkState
|
||||
import dev.msfjarvis.claw.common.NetworkState.Loading
|
||||
import dev.msfjarvis.claw.common.NetworkState.Success
|
||||
import dev.msfjarvis.claw.common.res.ClawIcons
|
||||
import dev.msfjarvis.claw.common.ui.NetworkError
|
||||
import dev.msfjarvis.claw.common.ui.NetworkImage
|
||||
import dev.msfjarvis.claw.common.ui.ProgressBar
|
||||
|
@ -57,6 +58,7 @@ private fun UserProfileInternal(
|
|||
) {
|
||||
NetworkImage(
|
||||
url = "https://lobste.rs/${user.avatarUrl}",
|
||||
placeholder = ClawIcons.Account,
|
||||
contentDescription = "Avatar of ${user.username}",
|
||||
modifier = Modifier.requiredSize(120.dp).clip(CircleShape),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue