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 970b65670..66c694ea3 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 @@ -5,6 +5,7 @@ import androidx.activity.viewModels import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.ui.book.read.ReadBookActivity +import io.legado.app.utils.showDialog import io.legado.app.utils.startActivity import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -26,7 +27,7 @@ class FileAssociationActivity : } viewModel.importBookSourceLive.observe(this) { binding.rotateLoading.hide() - ImportBookSourceDialog.start(supportFragmentManager, it, true) + supportFragmentManager.showDialog(ImportBookSourceDialog(it, true)) } viewModel.importRssSourceLive.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 1b919e439..234e0157d 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 @@ -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 @@ -27,28 +26,23 @@ import io.legado.app.help.AppConfig 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 ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { +class ImportBookSourceDialog() : 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 2aec56703..8d8f7b7e3 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 @@ -6,6 +6,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.lib.dialogs.alert +import io.legado.app.utils.showDialog import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -22,8 +23,9 @@ class OnLineImportActivity : override fun onActivityCreated(savedInstanceState: Bundle?) { viewModel.successLive.observe(this) { when (it.first) { - "bookSource" -> ImportBookSourceDialog - .start(supportFragmentManager, it.second, true) + "bookSource" -> supportFragmentManager.showDialog( + ImportBookSourceDialog(it.second, true) + ) "rssSource" -> ImportRssSourceDialog .start(supportFragmentManager, it.second, true) "replaceRule" -> ImportReplaceRuleDialog @@ -40,7 +42,9 @@ class OnLineImportActivity : return } when (it.path) { - "/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url, true) + "/bookSource" -> supportFragmentManager.showDialog( + ImportBookSourceDialog(url, true) + ) "/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) "/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) "/textTocRule" -> viewModel.getText(url) { json -> @@ -56,7 +60,9 @@ class OnLineImportActivity : viewModel.importReadConfig(bytes, this::finallyDialog) } "/importonline" -> when (it.host) { - "booksource" -> ImportBookSourceDialog.start(supportFragmentManager, url, true) + "booksource" -> supportFragmentManager.showDialog( + ImportBookSourceDialog(url, true) + ) "rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) "replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) else -> { diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt index a5c779bf9..1bb2661f2 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt @@ -95,7 +95,7 @@ class AudioPlayActivity : override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_change_source -> AudioPlay.book?.let { - ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) + supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) } R.id.menu_login -> AudioPlay.bookSource?.let { startActivity { diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index ee19680da..44426a0ac 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -5,7 +5,6 @@ import android.view.* import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.Toolbar import androidx.core.os.bundleOf -import androidx.fragment.app.FragmentManager import androidx.fragment.app.viewModels import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -29,18 +28,14 @@ import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch -class ChangeSourceDialog : BaseDialogFragment(), +class ChangeSourceDialog() : BaseDialogFragment(), Toolbar.OnMenuItemClickListener, ChangeSourceAdapter.CallBack { - companion object { - const val tag = "changeSourceDialog" - - fun show(manager: FragmentManager, name: String, author: String) { - manager.showDialog { - putString("name", name) - putString("author", author) - } + constructor(name: String, author: String) : this() { + arguments = Bundle().apply { + putString("name", name) + putString("author", author) } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 4ee294511..6173da0d8 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -288,7 +288,7 @@ class BookInfoActivity : } tvChangeSource.setOnClickListener { viewModel.bookData.value?.let { - ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) + supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) } } tvTocView.setOnClickListener { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 06b29f925..9ec383eeb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -226,7 +226,7 @@ class ReadBookActivity : ReadBookBaseActivity(), R.id.menu_change_source -> { binding.readMenu.runMenuOut() ReadBook.book?.let { - ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) + supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) } } R.id.menu_refresh -> { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 8234880ae..2340552d0 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -62,13 +62,13 @@ class BookSourceActivity : VMBaseActivity uri ?: return@registerForActivityResult try { uri.readText(this)?.let { - ImportBookSourceDialog.start(supportFragmentManager, it) + supportFragmentManager.showDialog(ImportBookSourceDialog(it)) } } catch (e: Exception) { toastOnUi("readTextError:${e.localizedMessage}") @@ -440,7 +440,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.frag BaseRssArticlesAdapter.CallBack { constructor(sortName: String, sortUrl: String) : this() { - val bundle = Bundle() - bundle.putString("sortName", sortName) - bundle.putString("sortUrl", sortUrl) - arguments = bundle + arguments = Bundle().apply { + putString("sortName", sortName) + putString("sortUrl", sortUrl) + } } private val binding by viewBinding(FragmentRssArticlesBinding::bind) 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 d842eb724..9303dbe33 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 @@ -16,6 +16,7 @@ import io.legado.app.ui.association.ImportBookSourceDialog import io.legado.app.ui.association.ImportReplaceRuleDialog import io.legado.app.ui.association.ImportRssSourceDialog import io.legado.app.ui.widget.recycler.ItemTouchCallback +import io.legado.app.utils.showDialog import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO @@ -70,9 +71,7 @@ class RuleSubActivity : BaseActivity(), override fun openSubscription(ruleSub: RuleSub) { when (ruleSub.type) { - 0 -> { - ImportBookSourceDialog.start(supportFragmentManager, ruleSub.url) - } + 0 -> supportFragmentManager.showDialog(ImportBookSourceDialog(ruleSub.url)) 1 -> { ImportRssSourceDialog.start(supportFragmentManager, ruleSub.url) } diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index 5d6265a50..195903cf9 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -24,6 +24,10 @@ inline fun FragmentManager.showDialog( dialog.show(this, T::class.simpleName) } +fun FragmentManager.showDialog(dialogFragment: DialogFragment) { + dialogFragment.show(this, dialogFragment::class.simpleName) +} + fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = requireContext().defaultSharedPreferences.getBoolean(key, defValue)