From f508f45e16f5637674346760d1d28400363e6a6a Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 14 Jun 2024 08:16:19 -0400 Subject: [PATCH] Fixes Url Preview Crop when the image is too small or to big for the preview card. --- .../amethyst/ui/components/UrlPreviewCard.kt | 12 +++--------- .../com/vitorpamplona/amethyst/ui/theme/Shape.kt | 2 ++ 2 files changed, 5 insertions(+), 9 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 d93bd2f25..781c12ac5 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 @@ -24,8 +24,6 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.heightIn import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.MaterialTheme @@ -34,7 +32,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalClipboardManager @@ -42,14 +39,13 @@ import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.dp import coil.compose.AsyncImage import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.service.previews.UrlInfoItem import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer import com.vitorpamplona.amethyst.ui.theme.MaxWidthWithHorzPadding -import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer import com.vitorpamplona.amethyst.ui.theme.innerPostModifier +import com.vitorpamplona.amethyst.ui.theme.previewCardImageModifier @Composable private fun CopyToClipboard( @@ -108,12 +104,10 @@ fun UrlPreviewCard( AsyncImage( model = previewInfo.imageUrlFullPath, contentDescription = stringResource(R.string.preview_card_image_for, previewInfo.url), - contentScale = ContentScale.Fit, - modifier = Modifier.fillMaxWidth().heightIn(max = 200.dp), + contentScale = ContentScale.Crop, + modifier = previewCardImageModifier, ) - Spacer(modifier = StdVertSpacer) - Text( text = previewInfo.verifiedUrl?.host ?: previewInfo.url, style = MaterialTheme.typography.bodySmall, diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt index 285af4743..4a5ddcc9f 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt @@ -265,3 +265,5 @@ val incognitoIconModifier = val hashVerifierMark = Modifier.width(40.dp).height(40.dp).padding(10.dp) val noteComposeRelayBox = Modifier.width(55.dp).heightIn(min = 17.dp).padding(start = 2.dp, end = 1.dp) + +val previewCardImageModifier = Modifier.fillMaxWidth().heightIn(max = 200.dp).padding(bottom = 5.dp)