mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
feat:使用glide解码正文图片
This commit is contained in:
@@ -55,7 +55,6 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
callBack?.upMenuView()
|
||||
callBack?.upPageAnim()
|
||||
upWebBook(book)
|
||||
ImageProvider.clearAllCache()
|
||||
synchronized(this) {
|
||||
loadingChapters.clear()
|
||||
}
|
||||
@@ -207,7 +206,6 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
}
|
||||
upReadTime()
|
||||
preDownload()
|
||||
ImageProvider.clearOut(durChapterIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,32 +4,17 @@ import android.graphics.Bitmap
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.help.BookHelp
|
||||
import io.legado.app.help.glide.ImageLoader
|
||||
import io.legado.app.model.localBook.EpubFile
|
||||
import io.legado.app.utils.BitmapUtils
|
||||
import io.legado.app.utils.FileUtils
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import splitties.init.appCtx
|
||||
import java.io.FileOutputStream
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
object ImageProvider {
|
||||
|
||||
private val cache = ConcurrentHashMap<Int, ConcurrentHashMap<String, Bitmap>>()
|
||||
|
||||
@Synchronized
|
||||
fun getCache(chapterIndex: Int, src: String): Bitmap? {
|
||||
return cache[chapterIndex]?.get(src)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun setCache(chapterIndex: Int, src: String, bitmap: Bitmap) {
|
||||
var indexCache = cache[chapterIndex]
|
||||
if (indexCache == null) {
|
||||
indexCache = ConcurrentHashMap()
|
||||
cache[chapterIndex] = indexCache
|
||||
}
|
||||
indexCache[src] = bitmap
|
||||
}
|
||||
|
||||
fun getImage(
|
||||
book: Book,
|
||||
chapterIndex: Int,
|
||||
@@ -37,9 +22,6 @@ object ImageProvider {
|
||||
bookSource: BookSource?,
|
||||
onUi: Boolean = false,
|
||||
): Bitmap? {
|
||||
getCache(chapterIndex, src)?.let {
|
||||
return it
|
||||
}
|
||||
val vFile = BookHelp.getImage(book, src)
|
||||
if (!vFile.exists()) {
|
||||
if (book.isEpub()) {
|
||||
@@ -56,38 +38,10 @@ object ImageProvider {
|
||||
}
|
||||
}
|
||||
return try {
|
||||
val bitmap = BitmapUtils.decodeBitmap(
|
||||
vFile.absolutePath,
|
||||
ChapterProvider.visibleWidth,
|
||||
ChapterProvider.visibleHeight
|
||||
)
|
||||
setCache(chapterIndex, src, bitmap)
|
||||
bitmap
|
||||
ImageLoader.loadBitmap(appCtx, vFile.absolutePath).submit().get()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun clearAllCache() {
|
||||
cache.forEach { indexCache ->
|
||||
indexCache.value.forEach {
|
||||
it.value.recycle()
|
||||
}
|
||||
}
|
||||
cache.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun clearOut(chapterIndex: Int) {
|
||||
cache.forEach { indexCache ->
|
||||
if (indexCache.key !in chapterIndex - 1..chapterIndex + 1) {
|
||||
indexCache.value.forEach {
|
||||
it.value.recycle()
|
||||
}
|
||||
cache.remove(indexCache.key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user