From 3311b6ac39a9002426fa7e719223e924e80f1cc7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 17 Oct 2022 09:21:29 +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 --- .../main/java/io/legado/app/help/book/BookExtensions.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/book/BookExtensions.kt b/app/src/main/java/io/legado/app/help/book/BookExtensions.kt index b349fe697..5134c0186 100644 --- a/app/src/main/java/io/legado/app/help/book/BookExtensions.kt +++ b/app/src/main/java/io/legado/app/help/book/BookExtensions.kt @@ -10,6 +10,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException import io.legado.app.help.config.AppConfig import io.legado.app.utils.* +import splitties.init.appCtx import java.io.File import java.util.concurrent.ConcurrentHashMap @@ -67,6 +68,12 @@ fun Book.getLocalUri(): Uri { } else { Uri.fromFile(File(bookUrl)) } + //先检测uri是否有效,这个比较快 + uri.inputStream(appCtx)?.use { + localUriCache[bookUrl] = uri + }?.let { + return uri + } //不同的设备书籍保存路径可能不一样 优先尝试寻找当前保存路径下的文件 val defaultBookDir = AppConfig.defaultBookTreeUri if (defaultBookDir.isNullOrBlank()) {