pull/1155/head
gedoor 3 years ago
parent d1cf6c459a
commit 82b5bd0685
  1. 42
      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.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = Theme.Transparent) { class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = Theme.Transparent) {
@ -16,18 +15,15 @@ class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = T
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
intent.data?.let { intent.data?.let {
when (it.path) { val url = it.getQueryParameter("src")
"bookSource" -> it.getQueryParameter("src")?.let { url -> if (url.isNullOrBlank()) {
importBookSource(url) finish()
} return
"rssSource" -> it.getQueryParameter("src")?.let { url ->
importRssSource(url)
}
"replaceRule" -> it.getQueryParameter("src")?.let { url ->
startActivity<ImportReplaceRuleActivity> {
putExtra("source", url)
}
} }
when (it.path) {
"bookSource" -> importBookSource(url)
"rssSource" -> importRssSource(url)
"replaceRule" -> importReplaceRule(url)
else -> { else -> {
} }
} }
@ -44,7 +40,7 @@ class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = T
viewModel.successLiveData.observe(this, { viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide() binding.rotateLoading.hide()
if (it > 0) { if (it > 0) {
ImportBookSourceDialog().show(supportFragmentManager, "SourceDialog") ImportBookSourceDialog().show(supportFragmentManager, "bookSource")
} else { } else {
errorDialog(getString(R.string.wrong_format)) errorDialog(getString(R.string.wrong_format))
} }
@ -62,7 +58,7 @@ class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = T
viewModel.successLiveData.observe(this, { viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide() binding.rotateLoading.hide()
if (it > 0) { if (it > 0) {
ImportRssSourceDialog().show(supportFragmentManager, "SourceDialog") ImportRssSourceDialog().show(supportFragmentManager, "rssSource")
} else { } else {
errorDialog(getString(R.string.wrong_format)) errorDialog(getString(R.string.wrong_format))
} }
@ -70,6 +66,24 @@ class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = T
viewModel.importSource(url) viewModel.importSource(url)
} }
private fun importReplaceRule(url: String) {
val viewModel by viewModels<ImportReplaceRuleViewModel>()
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) { private fun errorDialog(msg: String) {
alert(getString(R.string.error), msg) { alert(getString(R.string.error), msg) {
okButton { } okButton { }

Loading…
Cancel
Save