pull/2385/head
kunfei 2 years ago
parent 88101335b2
commit 4cc2a73a58
  1. 14
      app/src/main/java/io/legado/app/help/book/BookExtensions.kt
  2. 11
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt

@ -1,9 +1,13 @@
package io.legado.app.help.book package io.legado.app.help.book
import android.net.Uri
import io.legado.app.constant.BookSourceType import io.legado.app.constant.BookSourceType
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.exception.NoStackTraceException
import io.legado.app.utils.isContentScheme
import java.io.File
val Book.isAudio: Boolean val Book.isAudio: Boolean
@ -44,6 +48,16 @@ val Book.isOnLineTxt: Boolean
return !isLocal && type and BookType.text > 0 return !isLocal && type and BookType.text > 0
} }
fun Book.getLocalUri(): Uri {
if (isLocal) {
if (bookUrl.isContentScheme()) {
return Uri.parse(bookUrl)
}
return Uri.fromFile(File(bookUrl))
}
throw NoStackTraceException("不是本地书籍")
}
fun Book.getRemoteUrl(): String? { fun Book.getRemoteUrl(): String? {
if (origin.startsWith(BookType.webDavTag)) { if (origin.startsWith(BookType.webDavTag)) {
return origin.substring(8) return origin.substring(8)

@ -15,10 +15,7 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.exception.TocEmptyException import io.legado.app.exception.TocEmptyException
import io.legado.app.help.AppWebDav import io.legado.app.help.AppWebDav
import io.legado.app.help.book.BookHelp import io.legado.app.help.book.*
import io.legado.app.help.book.getRemoteUrl
import io.legado.app.help.book.isEpub
import io.legado.app.help.book.isUmd
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.WebDav
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -44,11 +41,7 @@ object LocalBook {
@Throws(FileNotFoundException::class, SecurityException::class) @Throws(FileNotFoundException::class, SecurityException::class)
fun getBookInputStream(book: Book): InputStream { fun getBookInputStream(book: Book): InputStream {
val uri = if (book.bookUrl.isContentScheme()) { val uri = book.getLocalUri()
Uri.parse(book.bookUrl)
} else {
Uri.fromFile(File(book.bookUrl))
}
//文件不存在 尝试下载webDav文件 book.remoteUrl //文件不存在 尝试下载webDav文件 book.remoteUrl
val inputStream = uri.inputStream(appCtx) ?: downloadRemoteBook(book) val inputStream = uri.inputStream(appCtx) ?: downloadRemoteBook(book)
if (inputStream != null) return inputStream if (inputStream != null) return inputStream

Loading…
Cancel
Save