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