diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4960d2873..990621d22 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -340,11 +340,6 @@
android:name=".ui.association.ImportRssSourceActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"
android:theme="@style/AppTheme.Transparent" />
-
-
()
+ val importReplaceRuleLive = MutableLiveData()
val successLiveData = MutableLiveData()
val errorLiveData = MutableLiveData()
@@ -50,15 +51,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
return@execute
}
content.contains("pattern") -> {
- successLiveData.postValue(
- Intent(
- context,
- ImportReplaceRuleActivity::class.java
- ).apply {
- val dataKey = IntentDataHelp.putData(content)
- putExtra("dataKey", dataKey)
- }
- )
+ importReplaceRuleLive.postValue(IntentDataHelp.putData(content))
return@execute
}
}
diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
index 0db0970dc..695e20cc0 100644
--- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
+++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
@@ -101,14 +101,20 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
}
viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide()
- errorDialog(it)
+ binding.tvMsg.apply {
+ text = it
+ visible()
+ }
})
viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide()
if (it > 0) {
adapter.setItems(viewModel.allSources)
} else {
- errorDialog(getString(R.string.wrong_format))
+ binding.tvMsg.apply {
+ setText(R.string.wrong_format)
+ visible()
+ }
}
})
val source = arguments?.getString("source")
@@ -182,15 +188,6 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
return false
}
- private fun errorDialog(msg: String) {
- alert(getString(R.string.error), msg) {
- okButton { }
- onDismiss {
-
- }
- }.show()
- }
-
inner class SourcesAdapter(context: Context) :
RecyclerAdapter(context) {
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
deleted file mode 100644
index a202a03e9..000000000
--- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt
+++ /dev/null
@@ -1,60 +0,0 @@
-package io.legado.app.ui.association
-
-import android.os.Bundle
-import androidx.activity.viewModels
-import io.legado.app.base.VMBaseActivity
-import io.legado.app.constant.Theme
-import io.legado.app.databinding.ActivityTranslucenceBinding
-import io.legado.app.help.IntentDataHelp
-import io.legado.app.lib.dialogs.alert
-import io.legado.app.utils.viewbindingdelegate.viewBinding
-
-class ImportReplaceRuleActivity :
- VMBaseActivity(
- theme = Theme.Transparent
- ) {
-
- override val binding by viewBinding(ActivityTranslucenceBinding::inflate)
- override val viewModel by viewModels()
-
- override fun onActivityCreated(savedInstanceState: Bundle?) {
- 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, "importReplaceRule")
- } else {
- errorDialog("格式不对")
- }
- })
- initData()
- }
-
- private fun initData() {
- intent.getStringExtra("dataKey")?.let {
- IntentDataHelp.getData(it)?.let { source ->
- viewModel.import(source)
- return
- }
- }
- intent.getStringExtra("source")?.let {
- viewModel.import(it)
- return
- }
- finish()
- }
-
- private fun errorDialog(msg: String) {
- alert("导入出错", msg) {
- okButton { }
- onDismiss {
- finish()
- }
- }.show()
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt
index 3f6b14dbf..cd5ccf0d4 100644
--- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt
+++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt
@@ -6,7 +6,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
-import androidx.fragment.app.activityViewModels
+import androidx.fragment.app.FragmentManager
+import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
@@ -15,14 +16,26 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemSourceImportBinding
+import io.legado.app.help.IntentDataHelp
import io.legado.app.ui.widget.dialog.WaitDialog
+import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
class ImportReplaceRuleDialog : BaseDialogFragment() {
+ companion object {
+ fun start(fragmentManager: FragmentManager, source: String) {
+ ImportReplaceRuleDialog().apply {
+ arguments = Bundle().apply {
+ putString("source", source)
+ }
+ }.show(fragmentManager, "importReplaceRule")
+ }
+ }
+
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
- private val viewModel by activityViewModels()
+ private val viewModel by viewModels()
lateinit var adapter: SourcesAdapter
override fun onStart() {
@@ -43,6 +56,7 @@ class ImportReplaceRuleDialog : BaseDialogFragment() {
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setTitle(R.string.import_replace_rule)
+ binding.rotateLoading.show()
adapter = SourcesAdapter(requireContext())
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter
@@ -72,6 +86,37 @@ class ImportReplaceRuleDialog : BaseDialogFragment() {
adapter.notifyDataSetChanged()
upSelectText()
}
+ viewModel.errorLiveData.observe(this, {
+ binding.rotateLoading.hide()
+ binding.tvMsg.apply {
+ text = it
+ visible()
+ }
+ })
+ viewModel.successLiveData.observe(this, {
+ binding.rotateLoading.hide()
+ if (it > 0) {
+ adapter.setItems(viewModel.allRules)
+ } else {
+ binding.tvMsg.apply {
+ setText(R.string.wrong_format)
+ visible()
+ }
+ }
+ })
+ val source = arguments?.getString("source")
+ if (source.isNullOrEmpty()) {
+ dismiss()
+ return
+ }
+ if (source.isAbsUrl()) {
+ viewModel.import(source)
+ } else {
+ IntentDataHelp.getData(source)?.let {
+ viewModel.import(it)
+ return
+ }
+ }
}
private fun upSelectText() {
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 d24a1d635..03455a4ed 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
@@ -28,17 +28,17 @@ class OnLineImportActivity :
return
}
when (it.path) {
- "/bookSource" -> importBookSource(url)
+ "/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url)
"/rssSource" -> importRssSource(url)
- "/replaceRule" -> importReplaceRule(url)
+ "/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url)
"/textTocRule" -> viewModel.importTextTocRule(url, this::finallyDialog)
"/httpTTS" -> viewModel.importHttpTTS(url, this::finallyDialog)
"/theme" -> viewModel.importTheme(url, this::finallyDialog)
"/readConfig" -> viewModel.importReadConfig(url, this::finallyDialog)
"/importonline" -> when (it.host) {
- "booksource" -> importBookSource(url)
+ "booksource" -> ImportBookSourceDialog.start(supportFragmentManager, url)
"rsssource" -> importRssSource(url)
- "replace" -> importReplaceRule(url)
+ "replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url)
else -> {
toastOnUi("url error")
finish()
@@ -48,24 +48,6 @@ class OnLineImportActivity :
}
}
- private fun importBookSource(url: String) {
- val viewModel by viewModels()
- binding.rotateLoading.show()
- viewModel.errorLiveData.observe(this, {
- binding.rotateLoading.hide()
- finallyDialog(getString(R.string.error), it)
- })
- viewModel.successLiveData.observe(this, {
- binding.rotateLoading.hide()
- if (it > 0) {
- ImportBookSourceDialog().show(supportFragmentManager, "bookSource")
- } else {
- finallyDialog(getString(R.string.error), getString(R.string.wrong_format))
- }
- })
- viewModel.importSource(url)
- }
-
private fun importRssSource(url: String) {
val viewModel by viewModels()
binding.rotateLoading.show()
diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
index d21a0d147..f4936a354 100644
--- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
@@ -27,7 +27,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
-import io.legado.app.ui.association.ImportReplaceRuleActivity
+import io.legado.app.ui.association.ImportReplaceRuleDialog
import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.qrcode.QrCodeResult
@@ -63,9 +63,7 @@ class ReplaceRuleActivity : VMBaseActivity {
- putExtra("source", it)
- }
+ ImportReplaceRuleDialog.start(supportFragmentManager, it)
}
private val editActivity =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
@@ -76,10 +74,7 @@ class ReplaceRuleActivity : VMBaseActivity
kotlin.runCatching {
uri?.readText(this)?.let {
- val dataKey = IntentDataHelp.putData(it)
- startActivity {
- putExtra("dataKey", dataKey)
- }
+ ImportReplaceRuleDialog.start(supportFragmentManager, IntentDataHelp.putData(it))
}
}.onFailure {
toastOnUi("readTextError:${it.localizedMessage}")
@@ -276,9 +271,7 @@ class ReplaceRuleActivity : VMBaseActivity {
- putExtra("source", it)
- }
+ ImportReplaceRuleDialog.start(supportFragmentManager, it)
}
}
cancelButton()
diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
index f7c2ed3b3..8c1fcc0e3 100644
--- a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
@@ -14,7 +14,7 @@ import io.legado.app.databinding.ActivityRuleSubBinding
import io.legado.app.databinding.DialogRuleSubEditBinding
import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.association.ImportBookSourceDialog
-import io.legado.app.ui.association.ImportReplaceRuleActivity
+import io.legado.app.ui.association.ImportReplaceRuleDialog
import io.legado.app.ui.association.ImportRssSourceActivity
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.startActivity
@@ -82,9 +82,7 @@ class RuleSubActivity : BaseActivity(),
}
}
2 -> {
- startActivity {
- putExtra("source", ruleSub.url)
- }
+ ImportReplaceRuleDialog.start(supportFragmentManager, ruleSub.url)
}
}
}
diff --git a/app/src/main/res/layout/dialog_recycler_view.xml b/app/src/main/res/layout/dialog_recycler_view.xml
index 2afcbca96..7f577dde3 100644
--- a/app/src/main/res/layout/dialog_recycler_view.xml
+++ b/app/src/main/res/layout/dialog_recycler_view.xml
@@ -34,6 +34,15 @@
android:layout_gravity="center"
app:loading_width="2dp" />
+
+