From 20fa2bfc19974c695606e015048da4c005025809 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 24 Jul 2021 16:23:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/association/FileAssociationActivity.kt | 6 +++--- .../app/ui/association/ImportBookSourceDialog.kt | 15 ++++++++++++++- .../app/ui/association/ImportReplaceRuleDialog.kt | 15 ++++++++++++++- .../app/ui/association/ImportRssSourceDialog.kt | 15 ++++++++++++++- .../app/ui/association/OnLineImportActivity.kt | 12 ++++++------ 5 files changed, 51 insertions(+), 12 deletions(-) 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 55259b746..b8b6c7f90 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 @@ -21,15 +21,15 @@ class FileAssociationActivity : binding.rotateLoading.show() viewModel.importBookSourceLive.observe(this) { binding.rotateLoading.hide() - ImportBookSourceDialog.start(supportFragmentManager, it) + ImportBookSourceDialog.start(supportFragmentManager, it, true) } viewModel.importRssSourceLive.observe(this) { binding.rotateLoading.hide() - ImportRssSourceDialog.start(supportFragmentManager, it) + ImportRssSourceDialog.start(supportFragmentManager, it, true) } viewModel.importReplaceRuleLive.observe(this) { binding.rotateLoading.hide() - ImportReplaceRuleDialog.start(supportFragmentManager, it) + ImportReplaceRuleDialog.start(supportFragmentManager, it, true) } viewModel.errorLiveData.observe(this, { binding.rotateLoading.hide() 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 695e20cc0..38cb9dc56 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 @@ -2,6 +2,7 @@ package io.legado.app.ui.association import android.annotation.SuppressLint import android.content.Context +import android.content.DialogInterface import android.os.Bundle import android.view.LayoutInflater import android.view.MenuItem @@ -37,10 +38,15 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList companion object { - fun start(fragmentManager: FragmentManager, source: String) { + fun start( + fragmentManager: FragmentManager, + source: String, + finishOnDismiss: Boolean = false + ) { ImportBookSourceDialog().apply { arguments = Bundle().apply { putString("source", source) + putBoolean("finishOnDismiss", finishOnDismiss) } }.show(fragmentManager, "importBookSource") } @@ -67,6 +73,13 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList return inflater.inflate(R.layout.dialog_recycler_view, container) } + override fun onDismiss(dialog: DialogInterface) { + super.onDismiss(dialog) + if (arguments?.getBoolean("finishOnDismiss") == true) { + activity?.finish() + } + } + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { binding.toolBar.setTitle(R.string.import_book_source) binding.rotateLoading.show() 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 dce88a04c..a542d39ff 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 @@ -1,6 +1,7 @@ package io.legado.app.ui.association import android.content.Context +import android.content.DialogInterface import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -24,10 +25,15 @@ import io.legado.app.utils.visible class ImportReplaceRuleDialog : BaseDialogFragment() { companion object { - fun start(fragmentManager: FragmentManager, source: String) { + fun start( + fragmentManager: FragmentManager, + source: String, + finishOnDismiss: Boolean = false + ) { ImportReplaceRuleDialog().apply { arguments = Bundle().apply { putString("source", source) + putBoolean("finishOnDismiss", finishOnDismiss) } }.show(fragmentManager, "importReplaceRule") } @@ -45,6 +51,13 @@ class ImportReplaceRuleDialog : BaseDialogFragment() { ) } + override fun onDismiss(dialog: DialogInterface) { + super.onDismiss(dialog) + if (arguments?.getBoolean("finishOnDismiss") == true) { + activity?.finish() + } + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index f5fea4d57..db723253e 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.association import android.annotation.SuppressLint import android.content.Context +import android.content.DialogInterface import android.os.Bundle import android.view.LayoutInflater import android.view.MenuItem @@ -35,10 +36,15 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { companion object { - fun start(fragmentManager: FragmentManager, source: String) { + fun start( + fragmentManager: FragmentManager, + source: String, + finishOnDismiss: Boolean = false + ) { ImportRssSourceDialog().apply { arguments = Bundle().apply { putString("source", source) + putBoolean("finishOnDismiss", finishOnDismiss) } }.show(fragmentManager, "importRssSource") } @@ -56,6 +62,13 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe ) } + override fun onDismiss(dialog: DialogInterface) { + super.onDismiss(dialog) + if (arguments?.getBoolean("finishOnDismiss") == true) { + activity?.finish() + } + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, 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 234b2915a..c56b48ec2 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 @@ -27,17 +27,17 @@ class OnLineImportActivity : return } when (it.path) { - "/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url) - "/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url) - "/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url) + "/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url, true) + "/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) + "/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) "/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" -> ImportBookSourceDialog.start(supportFragmentManager, url) - "rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url) - "replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url) + "booksource" -> ImportBookSourceDialog.start(supportFragmentManager, url, true) + "rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) + "replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) else -> { toastOnUi("url error") finish()