Skip to content

Commit

Permalink
Merge pull request #101 from aholeye/main
Browse files Browse the repository at this point in the history
  • Loading branch information
mudkipme authored Aug 19, 2023
2 parents 8d51610 + d6dd4fb commit 2c17f4d
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions app/src/main/java/me/mudkip/moememos/ui/component/MemoContent.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
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
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(
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 2c17f4d

Please sign in to comment.