fix: images always being full-width

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2023-11-01 17:59:32 +01:00
parent 88faa795ba
commit 89cc41b414
1 changed files with 45 additions and 37 deletions

View File

@ -4,6 +4,7 @@ import android.text.format.Formatter
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@ -75,26 +76,32 @@ fun FileAttachment(attachment: AutumnResource) {
fun ImageAttachment(attachment: AutumnResource) {
val url = "$REVOLT_FILES/attachments/${attachment.id}/${attachment.filename}"
BoxWithConstraints {
RemoteImage(
url = url,
contentScale = ContentScale.Fit,
modifier = Modifier
.fillMaxWidth()
.width(attachment.metadata?.width?.toInt()?.dp ?: maxWidth)
.aspectRatio(
attachment.metadata!!.width!!.toFloat() / attachment.metadata.height!!.toFloat()
),
description = attachment.filename ?: "Image"
)
}
}
@Composable
fun VideoAttachment(attachment: AutumnResource) {
val url = "$REVOLT_FILES/attachments/${attachment.id}/${attachment.filename}"
BoxWithConstraints {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.width(attachment.metadata?.width?.toInt()?.dp ?: maxWidth)
.aspectRatio(
attachment.metadata!!.width!!.toFloat() / attachment.metadata.height!!.toFloat()
)
) {
// Turns out that when you give Glide a video URL, you get a perfectly cromulent thumbnail.
RemoteImage(
@ -103,7 +110,7 @@ fun VideoAttachment(attachment: AutumnResource) {
modifier = Modifier
.fillMaxWidth()
.aspectRatio(
attachment.metadata!!.width!!.toFloat() / attachment.metadata.height!!.toFloat()
attachment.metadata.width!!.toFloat() / attachment.metadata.height.toFloat()
),
description = attachment.filename ?: "Video"
)
@ -124,6 +131,7 @@ fun VideoAttachment(attachment: AutumnResource) {
.aspectRatio(1f)
)
}
}
}
@Composable