From cb4cd4fd1ed4a96e37bde811ce761a1ce97d1412 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Mon, 11 Apr 2022 20:04:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=E7=BC=93=E5=AD=98=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=90=8E=E7=BC=80=E9=94=99=E8=AF=AF=E6=8B=BC=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/BookHelp.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index e3728eeab..ea636cb83 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -122,7 +122,7 @@ object BookHelp { cacheFolderName, book.getFolderName(), cacheImageFolderName, - "${MD5Utils.md5Encode16(src)}${getImageSuffix(src)}" + "${MD5Utils.md5Encode16(src)}.${getImageSuffix(src)}" ).writeBytes(it) } } catch (e: Exception) { @@ -137,14 +137,14 @@ object BookHelp { cacheFolderName, book.getFolderName(), cacheImageFolderName, - "${MD5Utils.md5Encode16(src)}${getImageSuffix(src)}" + "${MD5Utils.md5Encode16(src)}.${getImageSuffix(src)}" ) } fun getImageSuffix(src: String): String { var suffix = src.substringAfterLast(".").substringBefore(",") if (suffix.length > 5) { - suffix = ".jpg" + suffix = "jpg" } return suffix } From 9c5fdfe46c7c73c90f75630263d1abe2eeda1b26 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Mon, 11 Apr 2022 20:04:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat=EF=BC=9A=E4=BD=BF=E7=94=A8glide?= =?UTF-8?q?=E8=A7=A3=E7=A0=81=E6=AD=A3=E6=96=87=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/ReadBook.kt | 2 - .../book/read/page/provider/ImageProvider.kt | 52 ++----------------- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 6be083ce9..e8b50dffa 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -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) } /** 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 386a37dbb..f5d8d9173 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 @@ -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>() - - @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) - } - } - } - } From 64a73554c52eb86945c0462a6c25f8ce9c49382b Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Mon, 11 Apr 2022 21:42:31 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix(web=E7=AB=AF)::glide=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E6=AD=A3=E6=96=87=E5=9B=BE=E7=89=87=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=86=85=E5=AD=98=E4=B8=80=E7=9B=B4=E4=B8=8D?= =?UTF-8?q?=E9=87=8A=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/api/controller/BookController.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index ab55f75ba..e68c48f2e 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -79,7 +79,6 @@ object BookController { ?: return returnData.setErrorMsg("bookUrl为空") val src = parameters["path"]?.firstOrNull() ?: return returnData.setErrorMsg("图片链接为空") - val width = parameters["width"]?.firstOrNull()?.toInt() ?: 640 if (this.bookUrl != bookUrl) { this.book = appDb.bookDao.getBook(bookUrl) ?: return returnData.setErrorMsg("bookUrl不对") @@ -95,7 +94,7 @@ object BookController { } this.bookUrl = bookUrl return returnData.setData( - BitmapUtils.decodeBitmap(vFile.absolutePath, width, width) + ImageLoader.loadBitmap(appCtx, vFile.absolutePath).submit().get() ) }