pull/457/head
gedoor 4 years ago
parent 61689338fe
commit b623b4d3b6
  1. 6
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt

@ -235,12 +235,15 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
* 扫描当前文件夹
*/
private fun scanFolder() {
launch(IO) {
rootDoc?.let { doc ->
adapter.clearItems()
val lastDoc = subDocs.lastOrNull() ?: doc
viewModel.scanDoc(lastDoc) {
launch {
adapter.addItem(it)
}
}
} ?: let {
val lastPath = AppConfig.importBookPath
if (lastPath.isNullOrEmpty()) {
@ -249,11 +252,14 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
adapter.clearItems()
val file = File(path)
viewModel.scanFile(file) {
launch {
adapter.addItem(it)
}
}
}
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

@ -34,7 +34,6 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
}
fun scanDoc(documentFile: DocumentFile, find: (docItem: DocItem) -> Unit) {
execute {
val docList = DocumentUtils.listFiles(context, documentFile.uri)
docList.forEach { docItem ->
if (docItem.isDir) {
@ -48,10 +47,8 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
}
}
}
}
fun scanFile(file: File, find: (docItem: DocItem) -> Unit) {
execute {
file.listFiles()?.forEach {
if (it.isDirectory) {
scanFile(it, find)
@ -70,6 +67,5 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
}
}
}
}
}
Loading…
Cancel
Save