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