|
|
@ -66,42 +66,65 @@ private val localUriCache by lazy { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun Book.getLocalUri(): Uri { |
|
|
|
fun Book.getLocalUri(): Uri { |
|
|
|
if (isLocal) { |
|
|
|
if (!isLocal) { |
|
|
|
var uri = localUriCache[bookUrl] |
|
|
|
throw NoStackTraceException("不是本地书籍") |
|
|
|
if (uri != null) { |
|
|
|
} |
|
|
|
return uri |
|
|
|
var uri = localUriCache[bookUrl] |
|
|
|
} |
|
|
|
if (uri != null) { |
|
|
|
uri = if (bookUrl.isUri()) { |
|
|
|
return uri |
|
|
|
Uri.parse(bookUrl) |
|
|
|
} |
|
|
|
|
|
|
|
uri = if (bookUrl.isUri()) { |
|
|
|
|
|
|
|
Uri.parse(bookUrl) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Uri.fromFile(File(bookUrl)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//先检测uri是否有效,这个比较快 |
|
|
|
|
|
|
|
uri.inputStream(appCtx).getOrNull()?.use { |
|
|
|
|
|
|
|
localUriCache[bookUrl] = uri |
|
|
|
|
|
|
|
}?.let { |
|
|
|
|
|
|
|
return uri |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//不同的设备书籍保存路径可能不一样, uri无效时尝试寻找当前保存路径下的文件 |
|
|
|
|
|
|
|
val defaultBookDir = AppConfig.defaultBookTreeUri |
|
|
|
|
|
|
|
val importBookDir = AppConfig.importBookPath |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查找书籍保存目录 |
|
|
|
|
|
|
|
if (!defaultBookDir.isNullOrBlank()) { |
|
|
|
|
|
|
|
val treeUri = Uri.parse(defaultBookDir) |
|
|
|
|
|
|
|
val treeFileDoc = FileDoc.fromUri(treeUri, true) |
|
|
|
|
|
|
|
if (!treeFileDoc.exists()) { |
|
|
|
|
|
|
|
appCtx.toastOnUi("书籍保存目录失效,请重新设置!") |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Uri.fromFile(File(bookUrl)) |
|
|
|
val fileDoc = treeFileDoc.find(originName, 5) |
|
|
|
} |
|
|
|
if (fileDoc != null) { |
|
|
|
//先检测uri是否有效,这个比较快 |
|
|
|
localUriCache[bookUrl] = fileDoc.uri |
|
|
|
uri.inputStream(appCtx).getOrNull()?.use { |
|
|
|
//更新bookUrl 重启不用再找一遍 |
|
|
|
localUriCache[bookUrl] = uri |
|
|
|
bookUrl = fileDoc.toString() |
|
|
|
}?.let { |
|
|
|
save() |
|
|
|
return uri |
|
|
|
return fileDoc.uri |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//不同的设备书籍保存路径可能不一样, uri无效时尝试寻找当前保存路径下的文件 |
|
|
|
} |
|
|
|
val defaultBookDir = AppConfig.defaultBookTreeUri |
|
|
|
|
|
|
|
if (defaultBookDir.isNullOrBlank()) { |
|
|
|
// 查找添加本地选择的目录 |
|
|
|
localUriCache[bookUrl] = uri |
|
|
|
if (!importBookDir.isNullOrBlank()) { |
|
|
|
return uri |
|
|
|
val treeUri = if (importBookDir.isUri()) { |
|
|
|
|
|
|
|
Uri.parse(importBookDir) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Uri.fromFile(File(importBookDir)) |
|
|
|
} |
|
|
|
} |
|
|
|
val treeUri = Uri.parse(defaultBookDir) |
|
|
|
|
|
|
|
val treeFileDoc = FileDoc.fromUri(treeUri, true) |
|
|
|
val treeFileDoc = FileDoc.fromUri(treeUri, true) |
|
|
|
val fileDoc = treeFileDoc.find(originName, 3) |
|
|
|
val fileDoc = treeFileDoc.find(originName, 5) |
|
|
|
if (fileDoc != null) { |
|
|
|
if (fileDoc != null) { |
|
|
|
localUriCache[bookUrl] = fileDoc.uri |
|
|
|
localUriCache[bookUrl] = fileDoc.uri |
|
|
|
//更新bookUrl 重启不用再找一遍 |
|
|
|
|
|
|
|
bookUrl = fileDoc.toString() |
|
|
|
bookUrl = fileDoc.toString() |
|
|
|
save() |
|
|
|
save() |
|
|
|
return fileDoc.uri |
|
|
|
return fileDoc.uri |
|
|
|
} |
|
|
|
} |
|
|
|
localUriCache[bookUrl] = uri |
|
|
|
|
|
|
|
return uri |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
throw NoStackTraceException("不是本地书籍") |
|
|
|
|
|
|
|
|
|
|
|
localUriCache[bookUrl] = uri |
|
|
|
|
|
|
|
return uri |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun Book.cacheLocalUri(uri: Uri) { |
|
|
|
fun Book.cacheLocalUri(uri: Uri) { |
|
|
|