From 640aa297303a5dafc4643b5426a3ab3bf4dc75e4 Mon Sep 17 00:00:00 2001 From: hoodie13 <74173949+hoodie13@users.noreply.github.com> Date: Sat, 6 Mar 2021 20:51:48 +0800 Subject: [PATCH] =?UTF-8?q?epub=E4=B9=A6=E7=B1=8D=E5=A2=9E=E5=8A=A0cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 有些epub书籍一本书只使用了一个html,加载将近10S,做成与网文一样存到本地cache,加速2次加载时间 --- .../main/java/io/legado/app/help/BookHelp.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 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 803d11a9a..69ea5ff42 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -148,7 +148,7 @@ object BookHelp { fun getChapterFiles(book: Book): List { val fileNameList = arrayListOf() - if (book.isLocalBook()) { + if (book.isLocalTxt()) { return fileNameList } FileUtils.createFolderIfNotExist( @@ -162,7 +162,7 @@ object BookHelp { // 检测该章节是否下载 fun hasContent(book: Book, bookChapter: BookChapter): Boolean { - return if (book.isLocalBook()) { + return if (book.isLocalTxt()) { true } else { FileUtils.exists( @@ -175,8 +175,19 @@ object BookHelp { } fun getContent(book: Book, bookChapter: BookChapter): String? { - if (book.isLocalBook()) { + if (book.isLocalTxt()) { return LocalBook.getContext(book, bookChapter) + } else if (book.isEpub() && !hasContent(book, bookChapter)) { + val string = LocalBook.getContext(book, bookChapter) + string?.let { + FileUtils.createFileIfNotExist( + downloadDir, + cacheFolderName, + book.getFolderName(), + bookChapter.getFileName(), + ).writeText(it) + } + return string } else { val file = FileUtils.getFile( downloadDir, @@ -211,7 +222,7 @@ object BookHelp { } fun delContent(book: Book, bookChapter: BookChapter) { - if (book.isLocalBook()) { + if (book.isLocalTxt()) { return } else { FileUtils.createFileIfNotExist(