|
|
@ -3,15 +3,17 @@ package io.legado.app.ui.association |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import androidx.activity.viewModels |
|
|
|
import androidx.activity.viewModels |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.BaseActivity |
|
|
|
import io.legado.app.base.VMBaseActivity |
|
|
|
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.viewbindingdelegate.viewBinding |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
|
|
|
|
|
|
|
class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = Theme.Transparent) { |
|
|
|
class OnLineImportActivity : |
|
|
|
|
|
|
|
VMBaseActivity<ActivityTranslucenceBinding, OnLineImportViewModel>(theme = Theme.Transparent) { |
|
|
|
|
|
|
|
|
|
|
|
override val binding by viewBinding(ActivityTranslucenceBinding::inflate) |
|
|
|
override val binding by viewBinding(ActivityTranslucenceBinding::inflate) |
|
|
|
|
|
|
|
override val viewModel by viewModels<OnLineImportViewModel>() |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
intent.data?.let { |
|
|
|
intent.data?.let { |
|
|
@ -24,6 +26,7 @@ class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = T |
|
|
|
"bookSource" -> importBookSource(url) |
|
|
|
"bookSource" -> importBookSource(url) |
|
|
|
"rssSource" -> importRssSource(url) |
|
|
|
"rssSource" -> importRssSource(url) |
|
|
|
"replaceRule" -> importReplaceRule(url) |
|
|
|
"replaceRule" -> importReplaceRule(url) |
|
|
|
|
|
|
|
"textTocRule" -> viewModel.importTextTocRule(url, this::finallyDialog) |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -35,14 +38,14 @@ class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = T |
|
|
|
binding.rotateLoading.show() |
|
|
|
binding.rotateLoading.show() |
|
|
|
viewModel.errorLiveData.observe(this, { |
|
|
|
viewModel.errorLiveData.observe(this, { |
|
|
|
binding.rotateLoading.hide() |
|
|
|
binding.rotateLoading.hide() |
|
|
|
errorDialog(it) |
|
|
|
finallyDialog(getString(R.string.error), it) |
|
|
|
}) |
|
|
|
}) |
|
|
|
viewModel.successLiveData.observe(this, { |
|
|
|
viewModel.successLiveData.observe(this, { |
|
|
|
binding.rotateLoading.hide() |
|
|
|
binding.rotateLoading.hide() |
|
|
|
if (it > 0) { |
|
|
|
if (it > 0) { |
|
|
|
ImportBookSourceDialog().show(supportFragmentManager, "bookSource") |
|
|
|
ImportBookSourceDialog().show(supportFragmentManager, "bookSource") |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
errorDialog(getString(R.string.wrong_format)) |
|
|
|
finallyDialog(getString(R.string.error), getString(R.string.wrong_format)) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
viewModel.importSource(url) |
|
|
|
viewModel.importSource(url) |
|
|
@ -53,14 +56,14 @@ class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = T |
|
|
|
binding.rotateLoading.show() |
|
|
|
binding.rotateLoading.show() |
|
|
|
viewModel.errorLiveData.observe(this, { |
|
|
|
viewModel.errorLiveData.observe(this, { |
|
|
|
binding.rotateLoading.hide() |
|
|
|
binding.rotateLoading.hide() |
|
|
|
errorDialog(it) |
|
|
|
finallyDialog(getString(R.string.error), it) |
|
|
|
}) |
|
|
|
}) |
|
|
|
viewModel.successLiveData.observe(this, { |
|
|
|
viewModel.successLiveData.observe(this, { |
|
|
|
binding.rotateLoading.hide() |
|
|
|
binding.rotateLoading.hide() |
|
|
|
if (it > 0) { |
|
|
|
if (it > 0) { |
|
|
|
ImportRssSourceDialog().show(supportFragmentManager, "rssSource") |
|
|
|
ImportRssSourceDialog().show(supportFragmentManager, "rssSource") |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
errorDialog(getString(R.string.wrong_format)) |
|
|
|
finallyDialog(getString(R.string.error), getString(R.string.wrong_format)) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
viewModel.importSource(url) |
|
|
|
viewModel.importSource(url) |
|
|
@ -71,22 +74,22 @@ class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = T |
|
|
|
binding.rotateLoading.show() |
|
|
|
binding.rotateLoading.show() |
|
|
|
viewModel.errorLiveData.observe(this, { |
|
|
|
viewModel.errorLiveData.observe(this, { |
|
|
|
binding.rotateLoading.hide() |
|
|
|
binding.rotateLoading.hide() |
|
|
|
errorDialog(it) |
|
|
|
finallyDialog(getString(R.string.error), it) |
|
|
|
}) |
|
|
|
}) |
|
|
|
viewModel.successLiveData.observe(this, { |
|
|
|
viewModel.successLiveData.observe(this, { |
|
|
|
binding.rotateLoading.hide() |
|
|
|
binding.rotateLoading.hide() |
|
|
|
if (it > 0) { |
|
|
|
if (it > 0) { |
|
|
|
ImportReplaceRuleDialog().show(supportFragmentManager, "replaceRule") |
|
|
|
ImportReplaceRuleDialog().show(supportFragmentManager, "replaceRule") |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
errorDialog(getString(R.string.wrong_format)) |
|
|
|
finallyDialog(getString(R.string.error), getString(R.string.wrong_format)) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
viewModel.import(url) |
|
|
|
viewModel.import(url) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun errorDialog(msg: String) { |
|
|
|
private fun finallyDialog(title: String, msg: String) { |
|
|
|
alert(getString(R.string.error), msg) { |
|
|
|
alert(title, msg) { |
|
|
|
okButton { } |
|
|
|
okButton() |
|
|
|
onDismiss { |
|
|
|
onDismiss { |
|
|
|
finish() |
|
|
|
finish() |
|
|
|
} |
|
|
|
} |
|
|
|