From b7c4ec8358c54642ddf968413571505228b2845b Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 15 Mar 2023 14:06:26 -0400 Subject: [PATCH] Shows url host in the link preview --- .../amethyst/ui/components/UrlPreviewCard.kt | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/UrlPreviewCard.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/UrlPreviewCard.kt index 8b4802ad6..e8453aff5 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/UrlPreviewCard.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/UrlPreviewCard.kt @@ -34,12 +34,18 @@ fun UrlPreviewCard( modifier = Modifier .clickable { runCatching { uri.openUri(url) } } .clip(shape = RoundedCornerShape(15.dp)) - .border(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.12f), RoundedCornerShape(15.dp)) + .border( + 1.dp, + MaterialTheme.colors.onSurface.copy(alpha = 0.12f), + RoundedCornerShape(15.dp) + ) ) { Column { + val url = URL(previewInfo.url) + // correctly treating relative images val imageUrl = if (previewInfo.image.startsWith("/")) { - URL(URL(previewInfo.url), previewInfo.image).toString() + URL(url, previewInfo.image).toString() } else { previewInfo.image } @@ -51,12 +57,23 @@ fun UrlPreviewCard( modifier = Modifier.fillMaxWidth() ) + Text( + text = url.host, + style = MaterialTheme.typography.caption, + modifier = Modifier + .fillMaxWidth() + .padding(start = 10.dp, end = 10.dp, top = 10.dp), + color = Color.Gray, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + Text( text = previewInfo.title, style = MaterialTheme.typography.body2, modifier = Modifier .fillMaxWidth() - .padding(start = 10.dp, end = 10.dp, top = 10.dp), + .padding(start = 10.dp, end = 10.dp), maxLines = 1, overflow = TextOverflow.Ellipsis )