This commit is contained in:
kunfei
2022-10-16 12:19:11 +08:00
parent 4a9ed64464
commit ae74dc93c6
2 changed files with 24 additions and 5 deletions

View File

@@ -62,7 +62,7 @@ fun Book.getLocalUri(): Uri {
defaultBookTreeUri ?: return originBookUri
val treeUri = Uri.parse(defaultBookTreeUri)
val treeFileDoc = FileDoc.fromUri(treeUri, true)
return treeFileDoc.find(originName)?.uri ?: originBookUri
return treeFileDoc.find(originName, 5)?.uri ?: originBookUri
}
throw NoStackTraceException("不是本地书籍")
}

View File

@@ -142,10 +142,29 @@ fun FileDoc.list(filter: FileDocFilter? = null): ArrayList<FileDoc>? {
return null
}
fun FileDoc.find(name: String): FileDoc? {
return list {
it.name == name
}?.firstOrNull()
/**
* 查找文档, 如果存在则返回文档,如果不存在返回空
* @param name 文件名
* @param depth 查找文件夹深度
*/
fun FileDoc.find(name: String, depth: Int = 0): FileDoc? {
val list = list()
list?.forEach {
if (it.name == name) {
return it
}
}
if (depth > 0) {
list?.forEach {
if (it.isDir) {
val fileDoc = it.find(name, depth - 1)
if (fileDoc != null) {
return fileDoc
}
}
}
}
return null
}
/**