Fixing relative paths on OG:IMAGE tags to correctly see a preview card

pull/192/head
Vitor Pamplona 2023-03-04 10:49:36 -05:00
rodzic 9432135847
commit 58e0aa5f8f
2 zmienionych plików z 9 dodań i 2 usunięć

Wyświetl plik

@ -103,7 +103,7 @@ dependencies {
implementation 'androidx.security:security-crypto-ktx:1.1.0-alpha05'
// view videos
implementation 'com.google.android.exoplayer:exoplayer:2.18.3'
implementation 'com.google.android.exoplayer:exoplayer:2.18.4'
// Load images from the web.
implementation "io.coil-kt:coil-compose:2.2.2"

Wyświetl plik

@ -21,6 +21,7 @@ import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.baha.url.preview.UrlInfoItem
import com.vitorpamplona.amethyst.R
import java.net.URL
@Composable
fun UrlPreviewCard(
@ -36,8 +37,14 @@ fun UrlPreviewCard(
.border(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.12f), RoundedCornerShape(15.dp))
) {
Column {
// correctly treating relative images
val imageUrl = if (previewInfo.image.startsWith("/"))
URL(URL(previewInfo.url), previewInfo.image).toString()
else
previewInfo.image
AsyncImage(
model = previewInfo.image,
model = imageUrl,
contentDescription = stringResource(R.string.preview_card_image_for, url),
contentScale = ContentScale.FillWidth,
modifier = Modifier.fillMaxWidth()