1
0
mirror of https://github.com/foobnix/LibreraReader.git synced 2025-10-06 00:02:43 +02:00

custom image loader

This commit is contained in:
Ivan Ivanenko
2025-07-28 18:12:00 +03:00
parent ba4d42daa6
commit 30ef7515a9
2 changed files with 15 additions and 23 deletions

View File

@@ -171,7 +171,7 @@ object AppImageLoader {
fun initialize(context: Context) {
if (!isInitialized) {
val memoryCache = MemoryCache(100)
val memoryCache = MemoryCache(64 * 1024 * 1024)
val diskCache = DiskCache(context.applicationContext)
imageLoader = ImageLoader(memoryCache, diskCache)
isInitialized = true

View File

@@ -19,37 +19,29 @@ fun MyAsyncImageView(
contentDescription: String? = null
) {
var loadedImage by remember { mutableStateOf<ImageBitmap?>(null) }
var isLoading by remember { mutableStateOf(true) }
LaunchedEffect(imageUrl) {
isLoading = true
try {
loadedImage = AppImageLoader.get().loadImage(imageUrl)
} catch (e: Exception) {
e.printStackTrace()
} finally {
isLoading = false
}
}
when {
isLoading -> {
Image(
bitmap = ImageBitmap(1, 1),
contentDescription = contentDescription,
modifier = modifier,
contentScale = contentScale
)
}
if (loadedImage == null) {
Image(
bitmap = ImageBitmap(1, 1),
contentDescription = contentDescription,
modifier = modifier,
contentScale = contentScale
)
} else {
Image(
bitmap = loadedImage!!,
contentDescription = contentDescription,
modifier = modifier,
contentScale = contentScale
)
loadedImage != null -> {
Image(
bitmap = loadedImage!!,
contentDescription = contentDescription,
modifier = modifier,
contentScale = contentScale
)
}
}
}