|
@@ -3,16 +3,13 @@
|
|
|
package io.legado.app.help.book
|
|
package io.legado.app.help.book
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
import android.net.Uri
|
|
|
-import androidx.documentfile.provider.DocumentFile
|
|
|
|
|
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.exception.NoStackTraceException
|
|
|
import io.legado.app.help.config.AppConfig.defaultBookTreeUri
|
|
import io.legado.app.help.config.AppConfig.defaultBookTreeUri
|
|
|
-import io.legado.app.utils.getFile
|
|
|
|
|
-import io.legado.app.utils.isContentScheme
|
|
|
|
|
-import splitties.init.appCtx
|
|
|
|
|
|
|
+import io.legado.app.utils.*
|
|
|
import java.io.File
|
|
import java.io.File
|
|
|
|
|
|
|
|
|
|
|
|
@@ -64,17 +61,8 @@ fun Book.getLocalUri(): Uri {
|
|
|
//不同的设备书籍保存路径可能不一样 优先尝试寻找当前保存路径下的文件
|
|
//不同的设备书籍保存路径可能不一样 优先尝试寻找当前保存路径下的文件
|
|
|
defaultBookTreeUri ?: return originBookUri
|
|
defaultBookTreeUri ?: return originBookUri
|
|
|
val treeUri = Uri.parse(defaultBookTreeUri)
|
|
val treeUri = Uri.parse(defaultBookTreeUri)
|
|
|
- return if (treeUri.isContentScheme()) {
|
|
|
|
|
- DocumentFile.fromTreeUri(appCtx, treeUri)?.run {
|
|
|
|
|
- findFile(originName)?.let {
|
|
|
|
|
- if (it.exists()) it.uri else originBookUri
|
|
|
|
|
- } ?: originBookUri
|
|
|
|
|
- } ?: originBookUri
|
|
|
|
|
- } else {
|
|
|
|
|
- val treeFile = File(treeUri.path!!)
|
|
|
|
|
- val file = treeFile.getFile(originName)
|
|
|
|
|
- if (file.exists()) Uri.fromFile(file) else originBookUri
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ val treeFileDoc = FileDoc.fromUri(treeUri, true)
|
|
|
|
|
+ return treeFileDoc.find(originName)?.uri ?: originBookUri
|
|
|
}
|
|
}
|
|
|
throw NoStackTraceException("不是本地书籍")
|
|
throw NoStackTraceException("不是本地书籍")
|
|
|
}
|
|
}
|