diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index 66c694ea3..4f2c6e4ca 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -35,7 +35,7 @@ class FileAssociationActivity : } viewModel.importReplaceRuleLive.observe(this) { binding.rotateLoading.hide() - ImportReplaceRuleDialog.start(supportFragmentManager, it, true) + supportFragmentManager.showDialog(ImportReplaceRuleDialog(it, true)) } viewModel.errorLiveData.observe(this, { binding.rotateLoading.hide() 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 d684c9d9c..1c491f651 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 @@ -9,7 +9,6 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar -import androidx.fragment.app.FragmentManager import androidx.fragment.app.viewModels import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R @@ -26,24 +25,19 @@ import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.dialog.WaitDialog -import io.legado.app.utils.* +import io.legado.app.utils.dp +import io.legado.app.utils.putPrefBoolean +import io.legado.app.utils.splitNotBlank import io.legado.app.utils.viewbindingdelegate.viewBinding +import io.legado.app.utils.visible -class ImportReplaceRuleDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { +class ImportReplaceRuleDialog() : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { - companion object { - - fun start( - fragmentManager: FragmentManager, - source: String, - finishOnDismiss: Boolean = false - ) { - fragmentManager.showDialog { - putString("source", source) - putBoolean("finishOnDismiss", finishOnDismiss) - } + constructor(source: String, finishOnDismiss: Boolean = false) : this() { + arguments = Bundle().apply { + putString("source", source) + putBoolean("finishOnDismiss", finishOnDismiss) } - } private val binding by viewBinding(DialogRecyclerViewBinding::bind) 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 8d8f7b7e3..3ddfbd65a 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,8 +28,9 @@ class OnLineImportActivity : ) "rssSource" -> ImportRssSourceDialog .start(supportFragmentManager, it.second, true) - "replaceRule" -> ImportReplaceRuleDialog - .start(supportFragmentManager, it.second, true) + "replaceRule" -> supportFragmentManager.showDialog( + ImportReplaceRuleDialog(it.second, true) + ) } } viewModel.errorLive.observe(this) { @@ -46,7 +47,9 @@ class OnLineImportActivity : ImportBookSourceDialog(url, true) ) "/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) - "/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) + "/replaceRule" -> supportFragmentManager.showDialog( + ImportReplaceRuleDialog(url, true) + ) "/textTocRule" -> viewModel.getText(url) { json -> viewModel.importTextTocRule(json, this::finallyDialog) } @@ -64,7 +67,9 @@ class OnLineImportActivity : ImportBookSourceDialog(url, true) ) "rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) - "replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) + "replace" -> supportFragmentManager.showDialog( + ImportReplaceRuleDialog(url, true) + ) else -> { toastOnUi("url error") finish() 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 44bd93807..f1661993e 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 @@ -61,7 +61,9 @@ class ReplaceRuleActivity : VMBaseActivity kotlin.runCatching { uri?.readText(this)?.let { - ImportReplaceRuleDialog.start(supportFragmentManager, it) + supportFragmentManager.showDialog( + ImportReplaceRuleDialog(it) + ) } }.onFailure { toastOnUi("readTextError:${it.localizedMessage}") @@ -279,7 +283,9 @@ class ReplaceRuleActivity : VMBaseActivity(), 1 -> { ImportRssSourceDialog.start(supportFragmentManager, ruleSub.url) } - 2 -> { - ImportReplaceRuleDialog.start(supportFragmentManager, ruleSub.url) - } + 2 -> supportFragmentManager.showDialog( + ImportReplaceRuleDialog(ruleSub.url) + ) } }