diff --git a/app/src/main/java/me/mudkip/moememos/ui/component/MemoContent.kt b/app/src/main/java/me/mudkip/moememos/ui/component/MemoContent.kt index c773a0c..712f56b 100644 --- a/app/src/main/java/me/mudkip/moememos/ui/component/MemoContent.kt +++ b/app/src/main/java/me/mudkip/moememos/ui/component/MemoContent.kt @@ -1,12 +1,8 @@ package me.mudkip.moememos.ui.component import android.net.Uri -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.heightIn -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.widthIn +import androidx.compose.foundation.layout.* + import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @@ -14,6 +10,7 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.unit.dp import me.mudkip.moememos.data.model.Memo import me.mudkip.moememos.viewmodel.LocalUserState +import kotlin.math.ceil @Composable fun MemoContent( @@ -41,17 +38,33 @@ fun MemoContent( checkboxChange = checkboxChange ) - memo.resourceList?.forEach { resource -> - if (resource.type.startsWith("image/")) { - MemoImage( - url = resource.uri(LocalUserState.current.host).toString(), - modifier = Modifier - .heightIn(max = 400.dp) - .widthIn(min = 100.dp) - .padding(bottom = 10.dp) - .clip(RoundedCornerShape(8.dp)) - ) - } else { + val cols = 3 + memo.resourceList?.let { resourceList -> + val imageList = resourceList.filter { it.type.startsWith("image/") } + if (imageList.isNotEmpty()) { + val rows = ceil(imageList.size.toFloat() / cols).toInt() + for (rowIndex in 0 until rows) { + Row { + for (colIndex in 0 until cols) { + val index = rowIndex * cols + colIndex + if (index < imageList.size) { + Box(modifier = Modifier.fillMaxWidth(1f / (cols - colIndex))) { + MemoImage( + url = imageList[index].uri(LocalUserState.current.host).toString(), + modifier = Modifier + .aspectRatio(1f) + .padding(2.dp) + .clip(RoundedCornerShape(4.dp)) + ) + } + } else { + Spacer(modifier = Modifier.fillMaxWidth(1f / cols)) + } + } + } + } + } + resourceList.filterNot { it.type.startsWith("image/") }.forEach { resource -> Attachment(resource) } }