优化
This commit is contained in:
@@ -133,26 +133,21 @@ object ImageProvider {
|
|||||||
if (cacheBitmap != null) return cacheBitmap
|
if (cacheBitmap != null) return cacheBitmap
|
||||||
if (height != null && AppConfig.asyncLoadImage && ReadBook.pageAnim() == PageAnim.scrollPageAnim) {
|
if (height != null && AppConfig.asyncLoadImage && ReadBook.pageAnim() == PageAnim.scrollPageAnim) {
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
kotlin.runCatching {
|
|
||||||
val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width, height)
|
val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width, height)
|
||||||
?: throw NoStackTraceException(appCtx.getString(R.string.error_decode_bitmap))
|
?: throw NoStackTraceException(appCtx.getString(R.string.error_decode_bitmap))
|
||||||
withContext(Main) {
|
withContext(Main) {
|
||||||
bitmapLruCache.put(vFile.absolutePath, bitmap)
|
bitmapLruCache.put(vFile.absolutePath, bitmap)
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onError {
|
||||||
//错误图片占位,防止重复获取
|
//错误图片占位,防止重复获取
|
||||||
withContext(Main) {
|
|
||||||
bitmapLruCache.put(vFile.absolutePath, errorBitmap)
|
bitmapLruCache.put(vFile.absolutePath, errorBitmap)
|
||||||
}
|
|
||||||
putDebug(
|
putDebug(
|
||||||
"ImageProvider: decode bitmap failed. path: ${vFile.absolutePath}\n$it",
|
"ImageProvider: decode bitmap failed. path: ${vFile.absolutePath}\n$it",
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}.onFinally {
|
||||||
withContext(Main) {
|
|
||||||
block?.invoke()
|
block?.invoke()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
|
|||||||
Reference in New Issue
Block a user