feat: 优化代码

pull/172/head
kunfei 5 years ago
parent 2ae8cea905
commit 01ce97581f
  1. 24
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  2. 18
      app/src/main/res/layout/activity_import_book.xml

@ -17,7 +17,8 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.help.AppConfig
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.filechooser.FileChooserDialog
import io.legado.app.ui.filechooser.FilePicker
import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_import_book.*
@ -31,6 +32,7 @@ import java.util.*
class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity_import_book),
FileChooserDialog.CallBack,
PopupMenu.OnMenuItemClickListener,
ImportBookAdapter.CallBack {
private val requestCodeSelectFolder = 342
@ -59,7 +61,6 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
recycler_view.layoutManager = LinearLayoutManager(this)
adapter = ImportBookAdapter(this, this)
recycler_view.adapter = adapter
rotate_loading.loadingColor = accentColor
select_action_bar.setMainActionText(R.string.add_to_shelf)
select_action_bar.inflateMenu(R.menu.import_book_sel)
select_action_bar.setOnMenuItemClickListener(this)
@ -88,7 +89,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_select_folder -> selectImportFolder()
R.id.menu_select_folder -> FilePicker.selectFolder(this, requestCodeSelectFolder)
}
return super.onCompatOptionsItemSelected(item)
}
@ -118,6 +119,8 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
rootDoc = DocumentFile.fromTreeUri(this, rootUri)
subDocs.clear()
} else {
rootDoc = null
subDocs.clear()
path = it
}
}
@ -137,7 +140,6 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
tv_path.text = path
adapter.selectedUris.clear()
adapter.clearItems()
rotate_loading.show()
launch(IO) {
val docList = DocumentUtils.listFiles(
this@ImportBookActivity,
@ -153,7 +155,6 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
}
docList.sortWith(compareBy({ !it.isDir }, { it.name }))
withContext(Main) {
rotate_loading.hide()
adapter.setData(docList)
}
}
@ -186,13 +187,12 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
}
}
private fun selectImportFolder() {
try {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
startActivityForResult(intent, requestCodeSelectFolder)
} catch (e: Exception) {
e.printStackTrace()
override fun onFilePicked(requestCode: Int, currentPath: String) {
when (requestCode) {
requestCodeSelectFolder -> {
AppConfig.importBookPath = currentPath
upRootDoc()
}
}
}

@ -50,23 +50,11 @@
tools:ignore="UnusedAttribute" />
</LinearLayout>
<FrameLayout
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<io.legado.app.ui.widget.anima.RotateLoading
android:id="@+id/rotate_loading"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center" />
</FrameLayout>
android:layout_weight="1" />
<io.legado.app.ui.widget.SelectActionBar
android:id="@+id/select_action_bar"

Loading…
Cancel
Save