From e0a51033c12ff7a10e54eee85d5b88291fadfb4f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Dec 2021 23:32:04 +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 --- .../legado/app/model/localBook/LocalBook.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) 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 e930392c3..ec85423f8 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 @@ -59,23 +59,25 @@ object LocalBook { fun importFile(uri: Uri): Book { val path: String + val updateTime: Long //这个变量不要修改,否则会导致读取不到缓存 val fileName = (if (uri.isContentScheme()) { path = uri.toString() - val doc = DocumentFile.fromSingleUri(appCtx, uri) - doc?.let { - val bookFile = cacheFolder.getFile(it.name!!) - if (!bookFile.exists()) { - bookFile.createNewFile() - doc.readBytes(appCtx).let { bytes -> - bookFile.writeBytes(bytes) - } + val doc = DocumentFile.fromSingleUri(appCtx, uri)!! + updateTime = doc.lastModified() + val bookFile = cacheFolder.getFile(doc.name!!) + if (!bookFile.exists()) { + bookFile.createNewFile() + doc.readBytes(appCtx).let { bytes -> + bookFile.writeBytes(bytes) } } - doc?.name!! + doc.name!! } else { path = uri.path!! - File(path).name + val file = File(path) + updateTime = file.lastModified() + file.name }) var book = appDb.bookDao.getBook(path) if (book == null) { @@ -89,7 +91,8 @@ object LocalBook { appCtx.externalFiles, "covers", "${MD5Utils.md5Encode16(path)}.jpg" - ) + ), + latestChapterTime = updateTime ) if (book.isEpub()) EpubFile.upBookInfo(book) if (book.isUmd()) UmdFile.upBookInfo(book)