pull/306/head
gedoor 5 years ago
parent 32f552f2e6
commit 098d2723b6
  1. 3
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -162,7 +162,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
ImageProvider.getImage( ImageProvider.getImage(
ReadBook.book!!, ReadBook.book!!,
textPage.chapterIndex, textPage.chapterIndex,
textChar.charData textChar.charData,
true
)?.let { )?.let {
canvas.drawBitmap(it, null, rectF, null) canvas.drawBitmap(it, null, rectF, null)
} }

@ -31,7 +31,7 @@ object ImageProvider {
indexCache[src] = bitmap indexCache[src] = bitmap
} }
fun getImage(book: Book, chapterIndex: Int, src: String): Bitmap? { fun getImage(book: Book, chapterIndex: Int, src: String, onUi: Boolean = false): Bitmap? {
getCache(chapterIndex, src)?.let { getCache(chapterIndex, src)?.let {
return it return it
} }
@ -48,7 +48,7 @@ object ImageProvider {
out.flush() out.flush()
out.close() out.close()
} }
} else { } else if (!onUi) {
HttpHelper.getBytes(src, src)?.let { HttpHelper.getBytes(src, src)?.let {
FileUtils.createFileIfNotExist(vFile.absolutePath).writeBytes(it) FileUtils.createFileIfNotExist(vFile.absolutePath).writeBytes(it)
} }
@ -68,7 +68,7 @@ object ImageProvider {
} }
fun clearAllCache() { fun clearAllCache() {
cache.forEach {indexCache-> cache.forEach { indexCache ->
indexCache.value.forEach { indexCache.value.forEach {
it.value.recycle() it.value.recycle()
} }
@ -77,7 +77,7 @@ object ImageProvider {
} }
fun clearOut(chapterIndex: Int) { fun clearOut(chapterIndex: Int) {
cache.forEach {indexCache-> cache.forEach { indexCache ->
if (indexCache.key !in chapterIndex - 1..chapterIndex + 1) { if (indexCache.key !in chapterIndex - 1..chapterIndex + 1) {
indexCache.value.forEach { indexCache.value.forEach {
it.value.recycle() it.value.recycle()

Loading…
Cancel
Save