From 5ccf4b8e2cd853e0b33bbda82cbcee4d80332071 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 12:15:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/importbook/ImportBookActivity.kt | 24 +++++++++---------- .../app/ui/importbook/ImportBookAdapter.kt | 18 +++++++------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 5d3fb2810..ad6b67419 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -25,7 +25,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity ImportBookAdapter.CallBack { private val requestCodeSelectFolder = 342 private var rootDoc: DocumentFile? = null - private val subDirs = arrayListOf() + private val subDocs = arrayListOf() private lateinit var importBookAdapter: ImportBookAdapter private var localUriLiveData: LiveData>? = null @@ -81,7 +81,7 @@ class ImportBookActivity : VMBaseActivity(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(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() - 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(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 { diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index 02645acc3..34ebd4e36 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -50,16 +50,14 @@ 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) + if (item.isDirectory) { + callBack.nextDoc(item) + } else { + cb_select.isChecked = !cb_select.isChecked + if (cb_select.isChecked) { + selectedUris.add(item.uri.toString()) } else { - cb_select.isChecked = !cb_select.isChecked - if (cb_select.isChecked) { - selectedUris.add(item.uri.toString()) - } else { - selectedUris.remove(item.uri.toString()) - } + selectedUris.remove(item.uri.toString()) } } } @@ -67,7 +65,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : } interface CallBack { - fun findFolder(dirName: String) + fun nextDoc(doc: DocumentFile) fun upCountView() }