|
|
@ -34,40 +34,36 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun scanDoc(documentFile: DocumentFile, find: (docItem: DocItem) -> Unit) { |
|
|
|
fun scanDoc(documentFile: DocumentFile, find: (docItem: DocItem) -> Unit) { |
|
|
|
execute { |
|
|
|
val docList = DocumentUtils.listFiles(context, documentFile.uri) |
|
|
|
val docList = DocumentUtils.listFiles(context, documentFile.uri) |
|
|
|
docList.forEach { docItem -> |
|
|
|
docList.forEach { docItem -> |
|
|
|
if (docItem.isDir) { |
|
|
|
if (docItem.isDir) { |
|
|
|
DocumentFile.fromSingleUri(context, docItem.uri)?.let { |
|
|
|
DocumentFile.fromSingleUri(context, docItem.uri)?.let { |
|
|
|
scanDoc(it, find) |
|
|
|
scanDoc(it, find) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (docItem.name.endsWith(".txt", true) |
|
|
|
|
|
|
|
|| docItem.name.endsWith(".epub", true) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
find(docItem) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if (docItem.name.endsWith(".txt", true) |
|
|
|
|
|
|
|
|| docItem.name.endsWith(".epub", true) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
find(docItem) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun scanFile(file: File, find: (docItem: DocItem) -> Unit) { |
|
|
|
fun scanFile(file: File, find: (docItem: DocItem) -> Unit) { |
|
|
|
execute { |
|
|
|
file.listFiles()?.forEach { |
|
|
|
file.listFiles()?.forEach { |
|
|
|
if (it.isDirectory) { |
|
|
|
if (it.isDirectory) { |
|
|
|
scanFile(it, find) |
|
|
|
scanFile(it, find) |
|
|
|
} else if (it.name.endsWith(".txt", true) |
|
|
|
} else if (it.name.endsWith(".txt", true) |
|
|
|
|| it.name.endsWith(".epub", true) |
|
|
|
|| it.name.endsWith(".epub", true) |
|
|
|
) { |
|
|
|
) { |
|
|
|
find( |
|
|
|
find( |
|
|
|
DocItem( |
|
|
|
DocItem( |
|
|
|
it.name, |
|
|
|
it.name, |
|
|
|
it.extension, |
|
|
|
it.extension, |
|
|
|
it.length(), |
|
|
|
it.length(), |
|
|
|
Date(it.lastModified()), |
|
|
|
Date(it.lastModified()), |
|
|
|
Uri.parse(it.absolutePath) |
|
|
|
Uri.parse(it.absolutePath) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|