UPD: Improve Performance by using coil to load image preview

This commit is contained in:
Fawkes100 2025-04-29 20:34:17 +02:00
parent e70d8989f1
commit 0a33c12cde
3 changed files with 8 additions and 8 deletions

View File

@ -61,6 +61,6 @@ dependencies {
implementation(libs.androidx.room.ktx) implementation(libs.androidx.room.ktx)
implementation(libs.lifecycle.livedata.ktx) implementation(libs.lifecycle.livedata.ktx)
implementation(libs.compose.runtime.livedata) implementation(libs.compose.runtime.livedata)
implementation(libs.coil.compose)
ksp(libs.androidx.room.compiler) ksp(libs.androidx.room.compiler)
} }

View File

@ -29,6 +29,7 @@ import come.stormborntales.notevault.data.model.NoteEntry
import come.stormborntales.notevault.ui.viewmodel.NoteViewModel import come.stormborntales.notevault.ui.viewmodel.NoteViewModel
import java.io.InputStream import java.io.InputStream
import androidx.core.net.toUri import androidx.core.net.toUri
import coil.compose.AsyncImage
fun loadImageBitmap(context: Context, uriString: String): ImageBitmap? { fun loadImageBitmap(context: Context, uriString: String): ImageBitmap? {
return try { return try {
@ -45,9 +46,7 @@ fun loadImageBitmap(context: Context, uriString: String): ImageBitmap? {
@Composable @Composable
fun NoteCard(note: NoteEntity) { fun NoteCard(note: NoteEntity) {
val context = LocalContext.current val context = LocalContext.current
val imageBitmap = remember(note.images) {
note.images.firstOrNull()?.let { loadImageBitmap(context, it) }
}
Card( Card(
modifier = Modifier modifier = Modifier
@ -58,15 +57,15 @@ fun NoteCard(note: NoteEntity) {
) { ) {
Row(modifier = Modifier.padding(16.dp)) { Row(modifier = Modifier.padding(16.dp)) {
// Linkes Vorschaubild // Linkes Vorschaubild
imageBitmap?.let {
Image( note.images.firstOrNull()?.let { uriString ->
bitmap = it, AsyncImage(
model = uriString,
contentDescription = "Vorschaubild", contentDescription = "Vorschaubild",
modifier = Modifier modifier = Modifier
.size(120.dp) .size(120.dp)
.clip(RoundedCornerShape(12.dp)) .clip(RoundedCornerShape(12.dp))
) )
Spacer(modifier = Modifier.width(16.dp))
} }
// Rechte Info-Spalte // Rechte Info-Spalte

View File

@ -15,6 +15,7 @@ ksp="2.1.21-RC-2.0.0"
compose = "1.6.0" # oder was immer deine aktuelle Compose-Version ist compose = "1.6.0" # oder was immer deine aktuelle Compose-Version ist
[libraries] [libraries]
coil-compose = { group = "io.coil-kt", name = "coil-compose", version = "2.5.0" } # oder aktueller
compose-runtime-livedata = { group = "androidx.compose.runtime", name = "runtime-livedata", version.ref = "compose" } compose-runtime-livedata = { group = "androidx.compose.runtime", name = "runtime-livedata", version.ref = "compose" }
lifecycle-livedata-ktx = "androidx.lifecycle:lifecycle-livedata-ktx:2.8.7" lifecycle-livedata-ktx = "androidx.lifecycle:lifecycle-livedata-ktx:2.8.7"
androidx-compose-bom-v20240100 = { module = "androidx.compose:compose-bom", version.ref = "composeBomVersion" } androidx-compose-bom-v20240100 = { module = "androidx.compose:compose-bom", version.ref = "composeBomVersion" }