pull/83/head
kunfei 5 years ago
parent bee2a59594
commit ee66194c15
  1. 27
      app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt

@ -14,10 +14,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_import_book.* 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 org.jetbrains.anko.sdk27.listeners.onClick
import java.io.File import java.io.File
@ -58,10 +54,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
private fun initEvent() { private fun initEvent() {
tv_go_back.onClick { tv_go_back.onClick {
if (subDirs.isNotEmpty()) { goBackDir()
subDirs.removeAt(subDirs.lastIndex)
upPath()
}
} }
btn_add_book.onClick { btn_add_book.onClick {
@ -81,9 +74,9 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@Synchronized
private fun upPath() { private fun upPath() {
rootDoc?.let { rootDoc -> rootDoc?.let { rootDoc ->
launch(IO) {
var path = rootDoc.name.toString() + File.separator var path = rootDoc.name.toString() + File.separator
var doc: DocumentFile? = rootDoc var doc: DocumentFile? = rootDoc
for (dirName in subDirs) { for (dirName in subDirs) {
@ -99,13 +92,10 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
} }
} }
docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) docList.sortWith(compareBy({ !it.isDirectory }, { it.name }))
withContext(Main) {
tv_path.text = path tv_path.text = path
importBookAdapter.setItems(docList) importBookAdapter.setItems(docList)
} }
} }
}
}
private fun selectImportFolder() { private fun selectImportFolder() {
try { try {
@ -133,16 +123,25 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
} }
} }
@Synchronized
override fun findFolder(dirName: String) { override fun findFolder(dirName: String) {
subDirs.add(dirName) subDirs.add(dirName)
upPath() upPath()
} }
override fun onBackPressed() { @Synchronized
if (subDirs.isNotEmpty()) { private fun goBackDir(): Boolean {
return if (subDirs.isNotEmpty()) {
subDirs.removeAt(subDirs.lastIndex) subDirs.removeAt(subDirs.lastIndex)
upPath() upPath()
true
} else { } else {
false
}
}
override fun onBackPressed() {
if (!goBackDir()) {
super.onBackPressed() super.onBackPressed()
} }
} }

Loading…
Cancel
Save