From bee2a59594e8abc2e68063e34e66ff88d79e995b Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 21:37:37 +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 | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 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 cbd7863eb..cf8843600 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 @@ -14,6 +14,10 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.help.AppConfig import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_import_book.* +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.jetbrains.anko.sdk27.listeners.onClick import java.io.File @@ -79,21 +83,27 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity @SuppressLint("SetTextI18n") private fun upPath() { rootDoc?.let { rootDoc -> - tv_path.text = rootDoc.name.toString() + File.separator - var doc: DocumentFile? = rootDoc - for (dirName in subDirs) { - doc = doc?.findFile(dirName) - doc?.let { - tv_path.text = tv_path.text.toString() + it.name + File.separator + launch(IO) { + 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 + } } - } - val docList = arrayListOf() - doc?.listFiles()?.forEach { - if (it.isDirectory || it.name?.endsWith(".txt", true) == true) { - docList.add(it) + val docList = arrayListOf() + doc?.listFiles()?.forEach { + if (it.isDirectory || it.name?.endsWith(".txt", true) == true) { + docList.add(it) + } + } + docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) + withContext(Main) { + tv_path.text = path + importBookAdapter.setItems(docList) } } - importBookAdapter.setItems(docList) } }