diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index a75134288..c8232669d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -80,7 +80,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(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_qr -> startActivityForResult(qrRequestCode) R.id.menu_group_manage -> GroupManageDialog() @@ -203,10 +203,14 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } private fun selectFileSys() { - val intent = Intent(Intent.ACTION_GET_CONTENT) - intent.addCategory(Intent.CATEGORY_OPENABLE) - intent.type = "text/*"//设置类型 - startActivityForResult(intent, importSource) + try { + val intent = Intent(Intent.ACTION_GET_CONTENT) + intent.addCategory(Intent.CATEGORY_OPENABLE) + intent.type = "text/*"//设置类型 + startActivityForResult(intent, importSource) + } catch (e: Exception) { + selectFile() + } } override fun onMenuClick(menu: String) { @@ -229,11 +233,11 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r super.onActivityResult(requestCode, resultCode, data) when (requestCode) { importSource -> if (resultCode == Activity.RESULT_OK) { - data?.data?.let { - FileUtils.getPath(this, it)?.let { path -> + data?.data?.let { uri -> + uri.readText(this)?.let { Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) .show() - viewModel.importSourceFromFilePath(path) { msg -> + viewModel.importSource(it) { msg -> title_bar.snackbar(msg) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 6ee254029..c47bb8c9d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -115,7 +115,6 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) } } - fun importSourceFromFilePath(path: String, finally: (msg: String) -> Unit) { execute { val file = File(path)