UPD: Improve Performance by using coil to load image preview
This commit is contained in:
parent
e70d8989f1
commit
0a33c12cde
@ -61,6 +61,6 @@ dependencies {
|
||||
implementation(libs.androidx.room.ktx)
|
||||
implementation(libs.lifecycle.livedata.ktx)
|
||||
implementation(libs.compose.runtime.livedata)
|
||||
|
||||
implementation(libs.coil.compose)
|
||||
ksp(libs.androidx.room.compiler)
|
||||
}
|
@ -29,6 +29,7 @@ import come.stormborntales.notevault.data.model.NoteEntry
|
||||
import come.stormborntales.notevault.ui.viewmodel.NoteViewModel
|
||||
import java.io.InputStream
|
||||
import androidx.core.net.toUri
|
||||
import coil.compose.AsyncImage
|
||||
|
||||
fun loadImageBitmap(context: Context, uriString: String): ImageBitmap? {
|
||||
return try {
|
||||
@ -45,9 +46,7 @@ fun loadImageBitmap(context: Context, uriString: String): ImageBitmap? {
|
||||
@Composable
|
||||
fun NoteCard(note: NoteEntity) {
|
||||
val context = LocalContext.current
|
||||
val imageBitmap = remember(note.images) {
|
||||
note.images.firstOrNull()?.let { loadImageBitmap(context, it) }
|
||||
}
|
||||
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
@ -58,15 +57,15 @@ fun NoteCard(note: NoteEntity) {
|
||||
) {
|
||||
Row(modifier = Modifier.padding(16.dp)) {
|
||||
// Linkes Vorschaubild
|
||||
imageBitmap?.let {
|
||||
Image(
|
||||
bitmap = it,
|
||||
|
||||
note.images.firstOrNull()?.let { uriString ->
|
||||
AsyncImage(
|
||||
model = uriString,
|
||||
contentDescription = "Vorschaubild",
|
||||
modifier = Modifier
|
||||
.size(120.dp)
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
)
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
}
|
||||
|
||||
// Rechte Info-Spalte
|
||||
|
@ -15,6 +15,7 @@ ksp="2.1.21-RC-2.0.0"
|
||||
compose = "1.6.0" # oder was immer deine aktuelle Compose-Version ist
|
||||
|
||||
[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" }
|
||||
lifecycle-livedata-ktx = "androidx.lifecycle:lifecycle-livedata-ktx:2.8.7"
|
||||
androidx-compose-bom-v20240100 = { module = "androidx.compose:compose-bom", version.ref = "composeBomVersion" }
|
||||
|
Loading…
Reference in New Issue
Block a user