pull/69/head
kunfei 5 years ago
parent 454e5395ee
commit 2d74a38d08
  1. 20
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  2. 1
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt

@ -80,7 +80,7 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds())
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds())
R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds())
R.id.menu_import_source_local -> selectFile() R.id.menu_import_source_local -> selectFileSys()
R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_onLine -> showImportDialog()
R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode) R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode)
R.id.menu_group_manage -> GroupManageDialog() R.id.menu_group_manage -> GroupManageDialog()
@ -203,10 +203,14 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
} }
private fun selectFileSys() { private fun selectFileSys() {
val intent = Intent(Intent.ACTION_GET_CONTENT) try {
intent.addCategory(Intent.CATEGORY_OPENABLE) val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "text/*"//设置类型 intent.addCategory(Intent.CATEGORY_OPENABLE)
startActivityForResult(intent, importSource) intent.type = "text/*"//设置类型
startActivityForResult(intent, importSource)
} catch (e: Exception) {
selectFile()
}
} }
override fun onMenuClick(menu: String) { override fun onMenuClick(menu: String) {
@ -229,11 +233,11 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
when (requestCode) { when (requestCode) {
importSource -> if (resultCode == Activity.RESULT_OK) { importSource -> if (resultCode == Activity.RESULT_OK) {
data?.data?.let { data?.data?.let { uri ->
FileUtils.getPath(this, it)?.let { path -> uri.readText(this)?.let {
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE)
.show() .show()
viewModel.importSourceFromFilePath(path) { msg -> viewModel.importSource(it) { msg ->
title_bar.snackbar(msg) title_bar.snackbar(msg)
} }
} }

@ -115,7 +115,6 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun importSourceFromFilePath(path: String, finally: (msg: String) -> Unit) { fun importSourceFromFilePath(path: String, finally: (msg: String) -> Unit) {
execute { execute {
val file = File(path) val file = File(path)

Loading…
Cancel
Save