refactor(ImageProvider.kt):minify code

pull/1786/head
Xwite 3 years ago
parent 236aa2bf24
commit dd40083356
  1. 30
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -96,7 +96,7 @@ object ImageProvider {
book: Book, book: Book,
src: String, src: String,
width: Int, width: Int,
height: Int height: Int? = null
): Bitmap { ): Bitmap {
val cacheBitmap = bitmapLruCache.get(src) val cacheBitmap = bitmapLruCache.get(src)
if (cacheBitmap != null) return cacheBitmap if (cacheBitmap != null) return cacheBitmap
@ -118,32 +118,4 @@ object ImageProvider {
} }
} }
/**
*获取bitmap 使用LruCache缓存
*/
fun getImage(
book: Book,
src: String,
width: Int
): Bitmap {
val cacheBitmap = bitmapLruCache.get(src)
if (cacheBitmap != null) return cacheBitmap
val vFile = BookHelp.getImage(book, src)
@Suppress("BlockingMethodInNonBlockingContext")
return try {
val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width)
bitmapLruCache.put(src, bitmap)
bitmap
} catch (e: Exception) {
Coroutine.async {
putDebug("${vFile.absolutePath} 解码失败\n$e", e)
if (FileUtils.readText(vFile.absolutePath).isXml()) {
putDebug("${vFile.absolutePath}为xml,自动删除")
vFile.delete()
}
}
errorBitmap
}
}
} }

Loading…
Cancel
Save