|
|
@ -25,7 +25,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity |
|
|
|
ImportBookAdapter.CallBack { |
|
|
|
ImportBookAdapter.CallBack { |
|
|
|
private val requestCodeSelectFolder = 342 |
|
|
|
private val requestCodeSelectFolder = 342 |
|
|
|
private var rootDoc: DocumentFile? = null |
|
|
|
private var rootDoc: DocumentFile? = null |
|
|
|
private val subDirs = arrayListOf<String>() |
|
|
|
private val subDocs = arrayListOf<DocumentFile>() |
|
|
|
private lateinit var importBookAdapter: ImportBookAdapter |
|
|
|
private lateinit var importBookAdapter: ImportBookAdapter |
|
|
|
private var localUriLiveData: LiveData<List<String>>? = null |
|
|
|
private var localUriLiveData: LiveData<List<String>>? = null |
|
|
|
|
|
|
|
|
|
|
@ -81,7 +81,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity |
|
|
|
AppConfig.importBookPath?.let { |
|
|
|
AppConfig.importBookPath?.let { |
|
|
|
val rootUri = Uri.parse(it) |
|
|
|
val rootUri = Uri.parse(it) |
|
|
|
rootDoc = DocumentFile.fromTreeUri(this, rootUri) |
|
|
|
rootDoc = DocumentFile.fromTreeUri(this, rootUri) |
|
|
|
subDirs.clear() |
|
|
|
subDocs.clear() |
|
|
|
upPath() |
|
|
|
upPath() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -91,15 +91,13 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity |
|
|
|
private fun upPath() { |
|
|
|
private fun upPath() { |
|
|
|
rootDoc?.let { rootDoc -> |
|
|
|
rootDoc?.let { rootDoc -> |
|
|
|
var path = rootDoc.name.toString() + File.separator |
|
|
|
var path = rootDoc.name.toString() + File.separator |
|
|
|
var doc: DocumentFile? = rootDoc |
|
|
|
var lastDoc = rootDoc |
|
|
|
for (dirName in subDirs) { |
|
|
|
for (doc in subDocs) { |
|
|
|
doc = doc?.findFile(dirName) |
|
|
|
lastDoc = doc |
|
|
|
doc?.let { |
|
|
|
path = path + doc.name + File.separator |
|
|
|
path = path + it.name + File.separator |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
val docList = arrayListOf<DocumentFile>() |
|
|
|
val docList = arrayListOf<DocumentFile>() |
|
|
|
doc?.listFiles()?.forEach { |
|
|
|
lastDoc.listFiles().forEach { |
|
|
|
if (it.isDirectory && it.name?.startsWith(".") == false) { |
|
|
|
if (it.isDirectory && it.name?.startsWith(".") == false) { |
|
|
|
docList.add(it) |
|
|
|
docList.add(it) |
|
|
|
} else if (it.name?.endsWith(".txt", true) == true) { |
|
|
|
} else if (it.name?.endsWith(".txt", true) == true) { |
|
|
@ -140,15 +138,15 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
@Synchronized |
|
|
|
override fun findFolder(dirName: String) { |
|
|
|
override fun nextDoc(doc: DocumentFile) { |
|
|
|
subDirs.add(dirName) |
|
|
|
subDocs.add(doc) |
|
|
|
upPath() |
|
|
|
upPath() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
@Synchronized |
|
|
|
private fun goBackDir(): Boolean { |
|
|
|
private fun goBackDir(): Boolean { |
|
|
|
return if (subDirs.isNotEmpty()) { |
|
|
|
return if (subDocs.isNotEmpty()) { |
|
|
|
subDirs.removeAt(subDirs.lastIndex) |
|
|
|
subDocs.removeAt(subDocs.lastIndex) |
|
|
|
upPath() |
|
|
|
upPath() |
|
|
|
true |
|
|
|
true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|