pull/83/head
kunfei 5 years ago
parent e460cf1718
commit 5ccf4b8e2c
  1. 24
      app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt
  2. 6
      app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt

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

@ -50,9 +50,8 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
tv_name.text = item.name
cb_select.isChecked = selectedUris.contains(item.uri.toString())
onClick {
item.name?.let { name ->
if (item.isDirectory) {
callBack.findFolder(name)
callBack.nextDoc(item)
} else {
cb_select.isChecked = !cb_select.isChecked
if (cb_select.isChecked) {
@ -64,10 +63,9 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
}
}
}
}
interface CallBack {
fun findFolder(dirName: String)
fun nextDoc(doc: DocumentFile)
fun upCountView()
}

Loading…
Cancel
Save