pull/2437/head
kunfei 2 years ago
parent 4a9ed64464
commit ae74dc93c6
  1. 2
      app/src/main/java/io/legado/app/help/book/BookExtensions.kt
  2. 27
      app/src/main/java/io/legado/app/utils/FileDocExtensions.kt

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

@ -142,10 +142,29 @@ fun FileDoc.list(filter: FileDocFilter? = null): ArrayList<FileDoc>? {
return null return null
} }
fun FileDoc.find(name: String): FileDoc? { /**
return list { * 查找文档, 如果存在则返回文档,如果不存在返回空
it.name == name * @param name 文件名
}?.firstOrNull() * @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
} }
/** /**

Loading…
Cancel
Save