From 82b5bd06853962079f14159582a1d53ca67a045f Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 22 Jul 2021 18:17:03 +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 --- .../ui/association/OnLineImportActivity.kt | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt b/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt index f0062270a..45cc57de7 100644 --- a/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt @@ -7,7 +7,6 @@ import io.legado.app.base.BaseActivity import io.legado.app.constant.Theme import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.lib.dialogs.alert -import io.legado.app.utils.startActivity import io.legado.app.utils.viewbindingdelegate.viewBinding class OnLineImportActivity : BaseActivity(theme = Theme.Transparent) { @@ -16,18 +15,15 @@ class OnLineImportActivity : BaseActivity(theme = T override fun onActivityCreated(savedInstanceState: Bundle?) { intent.data?.let { + val url = it.getQueryParameter("src") + if (url.isNullOrBlank()) { + finish() + return + } when (it.path) { - "bookSource" -> it.getQueryParameter("src")?.let { url -> - importBookSource(url) - } - "rssSource" -> it.getQueryParameter("src")?.let { url -> - importRssSource(url) - } - "replaceRule" -> it.getQueryParameter("src")?.let { url -> - startActivity { - putExtra("source", url) - } - } + "bookSource" -> importBookSource(url) + "rssSource" -> importRssSource(url) + "replaceRule" -> importReplaceRule(url) else -> { } } @@ -44,7 +40,7 @@ class OnLineImportActivity : BaseActivity(theme = T viewModel.successLiveData.observe(this, { binding.rotateLoading.hide() if (it > 0) { - ImportBookSourceDialog().show(supportFragmentManager, "SourceDialog") + ImportBookSourceDialog().show(supportFragmentManager, "bookSource") } else { errorDialog(getString(R.string.wrong_format)) } @@ -62,7 +58,7 @@ class OnLineImportActivity : BaseActivity(theme = T viewModel.successLiveData.observe(this, { binding.rotateLoading.hide() if (it > 0) { - ImportRssSourceDialog().show(supportFragmentManager, "SourceDialog") + ImportRssSourceDialog().show(supportFragmentManager, "rssSource") } else { errorDialog(getString(R.string.wrong_format)) } @@ -70,6 +66,24 @@ class OnLineImportActivity : BaseActivity(theme = T viewModel.importSource(url) } + private fun importReplaceRule(url: String) { + val viewModel by viewModels() + binding.rotateLoading.show() + viewModel.errorLiveData.observe(this, { + binding.rotateLoading.hide() + errorDialog(it) + }) + viewModel.successLiveData.observe(this, { + binding.rotateLoading.hide() + if (it > 0) { + ImportReplaceRuleDialog().show(supportFragmentManager, "replaceRule") + } else { + errorDialog(getString(R.string.wrong_format)) + } + }) + viewModel.import(url) + } + private fun errorDialog(msg: String) { alert(getString(R.string.error), msg) { okButton { }