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:
@@ -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
|
||||
|
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user