From 27a749ddfd6133e3421556d07fd147042c7209dd Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Mon, 2 Jan 2023 12:47:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/storage/Restore.kt | 6 ++++++ .../io/legado/app/model/localBook/EpubFile.kt | 6 +----- .../io/legado/app/model/localBook/LocalBook.kt | 18 +++++++++++++----- .../io/legado/app/model/localBook/PdfFile.kt | 6 +----- .../io/legado/app/model/localBook/UmdFile.kt | 6 +----- .../app/ui/book/info/BookInfoViewModel.kt | 2 +- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 5226b9740..d524e8fb1 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -13,10 +13,12 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.* import io.legado.app.help.DirectLinkUpload import io.legado.app.help.LauncherIconHelp +import io.legado.app.help.book.isLocal import io.legado.app.help.book.upType import io.legado.app.help.config.LocalConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ThemeConfig +import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -69,6 +71,10 @@ object Restore { it.forEach { book -> book.upType() } + it.filter { book -> book.isLocal } + .forEach { book -> + book.coverUrl = LocalBook.getCoverPath(book) + } appDb.bookDao.insert(*it.toTypedArray()) } fileToListT(path, "bookmark.json")?.let { diff --git a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt index b2d9061c7..3b233a22a 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt @@ -85,11 +85,7 @@ class EpubFile(var book: Book) { try { epubBook?.let { if (book.coverUrl.isNullOrEmpty()) { - book.coverUrl = FileUtils.getPath( - appCtx.externalFiles, - "covers", - "${MD5Utils.md5Encode16(book.bookUrl)}.jpg" - ) + book.coverUrl = LocalBook.getCoverPath(book) } if (!File(book.coverUrl!!).exists()) { /*部分书籍DRM处理后,封面获取异常,待优化*/ diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index ea7bad72e..877f6ae05 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -123,6 +123,18 @@ object LocalBook { }.getOrElse { content } } + fun getCoverPath(book: Book): String { + return getCoverPath(book.bookUrl) + } + + private fun getCoverPath(bookUrl: String): String { + return FileUtils.getPath( + appCtx.externalFiles, + "covers", + "${MD5Utils.md5Encode16(bookUrl)}.jpg" + ) + } + /** * 下载在线的文件并自动导入到阅读(txt umd epub) * 压缩文件请先提示用户解压 @@ -162,11 +174,7 @@ object LocalBook { name = nameAuthor.first, author = nameAuthor.second, originName = fileName, - coverUrl = FileUtils.getPath( - appCtx.externalFiles, - "covers", - "${MD5Utils.md5Encode16(bookUrl)}.jpg" - ), + coverUrl = getCoverPath(bookUrl), latestChapterTime = updateTime, order = appDb.bookDao.minOrder - 1 ) diff --git a/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt b/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt index 40ccca227..029e977b0 100644 --- a/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt @@ -75,11 +75,7 @@ class PdfFile(var book: Book) { try { pdfRenderer?.let { renderer -> if (book.coverUrl.isNullOrEmpty()) { - book.coverUrl = FileUtils.getPath( - appCtx.externalFiles, - "covers", - "${MD5Utils.md5Encode16(book.bookUrl)}.jpg" - ) + book.coverUrl = LocalBook.getCoverPath(book) } if (!File(book.coverUrl!!).exists()) { diff --git a/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt b/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt index 963d2eb69..6e5ddf9ed 100644 --- a/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt @@ -64,11 +64,7 @@ class UmdFile(var book: Book) { try { umdBook?.let { if (book.coverUrl.isNullOrEmpty()) { - book.coverUrl = FileUtils.getPath( - appCtx.externalFiles, - "covers", - "${MD5Utils.md5Encode16(book.bookUrl)}.jpg" - ) + book.coverUrl = LocalBook.getCoverPath(book) } if (!File(book.coverUrl!!).exists()) { FileUtils.writeBytes(book.coverUrl!!, it.cover.coverData) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 70277a37b..f394f30a2 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -80,7 +80,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { upCoverByRule(book) bookSource = if (book.isLocal) null else appDb.bookSourceDao.getBookSource(book.origin) - if (book.tocUrl.isEmpty()) { + if (book.tocUrl.isEmpty() && !book.isLocal) { loadBookInfo(book) } else if (isImportBookOnLine) { chapterListData.postValue(emptyList())