From 7db9412fb60889dc35d04ef32380e2c7557c3d2a Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sun, 8 May 2022 17:39:21 +0800 Subject: [PATCH] feat:remove unnecessary code --- .../book/read/page/provider/ImageProvider.kt | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index ef9d9dc6d..70656df18 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -93,8 +93,10 @@ object ImageProvider { op.inJustDecodeBounds = true BitmapFactory.decodeFile(file.absolutePath, op) if (op.outWidth < 1 && op.outHeight < 1) { - putDebug("ImageProvider: delete file due to image size ${op.outHeight}*${op.outWidth}. path: ${file.absolutePath}") - file.delete() + Coroutine.async { + putDebug("ImageProvider: delete file due to image size ${op.outHeight}*${op.outWidth}. path: ${file.absolutePath}") + file.delete() + } return Size(errorBitmap.width, errorBitmap.height) } return Size(op.outWidth, op.outHeight) @@ -112,6 +114,7 @@ object ImageProvider { val cacheBitmap = bitmapLruCache.get(src) if (cacheBitmap != null) return cacheBitmap val vFile = BookHelp.getImage(book, src) + if (!vFile.exists()) return errorBitmap @Suppress("BlockingMethodInNonBlockingContext") return kotlin.runCatching { val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width, height) @@ -119,16 +122,10 @@ object ImageProvider { bitmapLruCache.put(src, bitmap) bitmap }.onFailure { - Coroutine.async { - putDebug( - "ImageProvider: decode bitmap failed. path: ${vFile.absolutePath}\n$it", - it - ) - if (FileUtils.readText(vFile.absolutePath).isXml()) { - putDebug("ImageProvider: delete xml file. path: ${vFile.absolutePath}") - vFile.delete() - } - } + putDebug( + "ImageProvider: decode bitmap failed. path: ${vFile.absolutePath}\n$it", + it + ) }.getOrDefault(errorBitmap) }