From 1f761a5713391ef4a997bdb2ba84933a0f49166f Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 21 Jul 2021 17:31:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=AF=BC=E5=85=A5url?= =?UTF-8?q?=E4=B8=BA=20legado://import/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 26 ++++++ .../app/receiver/SharedReceiverActivity.kt | 4 +- .../association/ImportBookSourceActivity.kt | 2 +- .../association/ImportReplaceRuleActivity.kt | 2 +- .../ui/association/ImportRssSourceActivity.kt | 2 +- .../ui/association/OnLineImportActivity.kt | 82 +++++++++++++++++++ 6 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4cae9d17d..fea75c6a4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -319,6 +319,32 @@ + + + + + + + + + + + + + + + + + + + { + intent.action == Intent.ACTION_SEND && intent.type == receivingType -> { intent.getStringExtra(Intent.EXTRA_TEXT)?.let { dispose(it) } } Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - && Intent.ACTION_PROCESS_TEXT == intent.action + && intent.action == Intent.ACTION_PROCESS_TEXT && intent.type == receivingType -> { intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let { dispose(it) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt index 9884a768d..18b385627 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt @@ -60,7 +60,7 @@ class ImportBookSourceActivity : finish() } } - } + } ?: finish() } private fun errorDialog(msg: String) { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt index d77256698..49439f76b 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt @@ -59,7 +59,7 @@ class ImportReplaceRuleActivity : finish() } } - } + } ?: finish() } private fun errorDialog(msg: String) { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt index 651aa82c2..0ee8a4126 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt @@ -59,7 +59,7 @@ class ImportRssSourceActivity : finish() } } - } + } ?: finish() } private fun errorDialog(msg: String) { 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 new file mode 100644 index 000000000..f0062270a --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt @@ -0,0 +1,82 @@ +package io.legado.app.ui.association + +import android.os.Bundle +import androidx.activity.viewModels +import io.legado.app.R +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) { + + override val binding by viewBinding(ActivityTranslucenceBinding::inflate) + + override fun onActivityCreated(savedInstanceState: Bundle?) { + intent.data?.let { + 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) + } + } + else -> { + } + } + } + } + + private fun importBookSource(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) { + ImportBookSourceDialog().show(supportFragmentManager, "SourceDialog") + } else { + errorDialog(getString(R.string.wrong_format)) + } + }) + viewModel.importSource(url) + } + + private fun importRssSource(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) { + ImportRssSourceDialog().show(supportFragmentManager, "SourceDialog") + } else { + errorDialog(getString(R.string.wrong_format)) + } + }) + viewModel.importSource(url) + } + + private fun errorDialog(msg: String) { + alert(getString(R.string.error), msg) { + okButton { } + onDismiss { + finish() + } + }.show() + } + +} \ No newline at end of file