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 4f29e1c3b..63ca1839e 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 @@ -66,12 +66,12 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList adapter.setItems(viewModel.allSources) binding.tvCancel.visible() binding.tvCancel.setOnClickListener { - dismiss() + dismissAllowingStateLoss() } binding.tvOk.visible() binding.tvOk.setOnClickListener { viewModel.importSelect { - dismiss() + dismissAllowingStateLoss() } } upSelectText() 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 23fd39b39..19e86125d 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 @@ -64,12 +64,12 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe adapter.setItems(viewModel.allSources) binding.tvCancel.visible() binding.tvCancel.setOnClickListener { - dismiss() + dismissAllowingStateLoss() } binding.tvOk.visible() binding.tvOk.setOnClickListener { viewModel.importSelect { - dismiss() + dismissAllowingStateLoss() } } upSelectText() diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt index cf3eb8d1f..5558da7fc 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt @@ -107,7 +107,7 @@ class ChangeCoverDialog : BaseDialogFragment(), override fun changeTo(coverUrl: String) { callBack?.coverChangeTo(coverUrl) - dismiss() + dismissAllowingStateLoss() } interface CallBack { 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 289aa4b9a..e6be2e4be 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 @@ -190,7 +190,7 @@ class ChangeSourceDialog : BaseDialogFragment(), val book = searchBook.toBook() book.upInfoFromOld(callBack?.oldBook) callBack?.changeTo(book) - dismiss() + dismissAllowingStateLoss() } override val bookUrl: String? diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 0f87783db..6a6498459 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -71,7 +71,9 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView) binding.tvOk.setTextColor(requireContext().accentColor) binding.tvOk.visible() - binding.tvOk.setOnClickListener { dismiss() } + binding.tvOk.setOnClickListener { + dismissAllowingStateLoss() + } } private fun initData() { diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 42a4ab229..91ed1ab74 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -94,11 +94,13 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener val itemTouchCallback = ItemTouchCallback(adapter) itemTouchCallback.isCanDrag = true ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView) - binding.tvCancel.setOnClickListener { dismiss() } + binding.tvCancel.setOnClickListener { + dismissAllowingStateLoss() + } binding.tvOk.setTextColor(requireContext().accentColor) binding.tvOk.setOnClickListener { callBack?.upGroup(requestCode, groupId) - dismiss() + dismissAllowingStateLoss() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt index a3b8db620..d4a0d9506 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt @@ -94,14 +94,17 @@ class AutoReadDialog : BaseDialogFragment() { } private fun initEvent() { - binding.llMainMenu.setOnClickListener { callBack?.showMenuBar(); dismiss() } + binding.llMainMenu.setOnClickListener { + callBack?.showMenuBar() + dismissAllowingStateLoss() + } binding.llSetting.setOnClickListener { ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") } binding.llCatalog.setOnClickListener { callBack?.openChapterList() } binding.llAutoPageStop.setOnClickListener { callBack?.autoPageStop() - dismiss() + dismissAllowingStateLoss() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 771ae2873..7b4eee738 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -183,7 +183,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { binding.ivDelete.setOnClickListener { if (ReadBookConfig.deleteDur()) { postEvent(EventBus.UP_CONFIG, true) - dismiss() + dismissAllowingStateLoss() } else { toastOnUi("数量已是最少,不能删除.") } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt index e9f79e26c..8ade981b6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt @@ -69,7 +69,7 @@ class ClickActionConfigDialog : BaseDialogFragment() { private fun initViewEvent() { binding.ivClose.setOnClickListener { - dismiss() + dismissAllowingStateLoss() } binding.tvTopLeft.setOnClickListener { selectAction { action -> diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt index 6b0391738..52f7e7d36 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt @@ -122,13 +122,19 @@ class ReadAloudDialog : BaseDialogFragment() { } private fun initEvent() = with(binding) { - llMainMenu.setOnClickListener { callBack?.showMenuBar(); dismiss() } + llMainMenu.setOnClickListener { + callBack?.showMenuBar() + dismissAllowingStateLoss() + } llSetting.setOnClickListener { ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") } tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) } - ivStop.setOnClickListener { ReadAloud.stop(requireContext()); dismiss() } + ivStop.setOnClickListener { + ReadAloud.stop(requireContext()) + dismissAllowingStateLoss() + } ivPlayPause.setOnClickListener { callBack?.onClickReadAloud() } ivPlayPrev.setOnClickListener { ReadAloud.prevParagraph(requireContext()) } ivPlayNext.setOnClickListener { ReadAloud.nextParagraph(requireContext()) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index d92394e14..90f4a9b21 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -125,7 +125,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { } } tvPadding.setOnClickListener { - dismiss() + dismissAllowingStateLoss() callBack?.showPaddingConfig() } tvTip.setOnClickListener { @@ -174,7 +174,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { } private fun showBgTextConfig(index: Int): Boolean { - dismiss() + dismissAllowingStateLoss() changeBg(index) callBack?.showBgTextConfig() return true diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 0277a566e..fbef2f93e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -69,16 +69,16 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener tvFooterLeft.visible() tvFooterLeft.setOnClickListener { removePref(PreferKey.speakEngine) - dismiss() + dismissAllowingStateLoss() } tvOk.visible() tvOk.setOnClickListener { putPrefLong(PreferKey.speakEngine, engineId) - dismiss() + dismissAllowingStateLoss() } tvCancel.visible() tvCancel.setOnClickListener { - dismiss() + dismissAllowingStateLoss() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index eb8c8bdf0..96f23c186 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -79,14 +79,14 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { itemTouchCallback.isCanDrag = true ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recyclerView) tvCancel.setOnClickListener { - dismiss() + dismissAllowingStateLoss() } tvOk.setOnClickListener { adapter.getItems().forEach { tocRule -> if (selectedName == tocRule.name) { val callBack = activity as? CallBack callBack?.onTocRegexDialogResult(tocRule.rule) - dismiss() + dismissAllowingStateLoss() return@setOnClickListener } } diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt index 2f574f2cd..4eaa8aaea 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt @@ -152,12 +152,12 @@ class FilePickerDialog : DialogFragment(), when (item?.itemId) { R.id.menu_ok -> fileAdapter.currentPath?.let { setData(it) - dismiss() + dismissAllowingStateLoss() } else -> item?.title?.let { (parentFragment as? CallBack)?.onMenuClick(it.toString()) (activity as? CallBack)?.onMenuClick(it.toString()) - dismiss() + dismissAllowingStateLoss() } } return true @@ -175,7 +175,7 @@ class FilePickerDialog : DialogFragment(), allowExtensions?.contains(FileUtils.getExtension(path)) == true ) { setData(path) - dismiss() + dismissAllowingStateLoss() } else { toastOnUi("不能打开此文件") } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index 534667b88..2b49eea70 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -58,7 +58,9 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener recyclerView.adapter = adapter tvOk.setTextColor(requireContext().accentColor) tvOk.visible() - tvOk.setOnClickListener { dismiss() } + tvOk.setOnClickListener { + dismissAllowingStateLoss() + } appDb.rssSourceDao.liveGroup().observe(viewLifecycleOwner, { val groups = linkedSetOf() it.map { group -> diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index e1bb1f664..004d3204b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -94,7 +94,7 @@ class FontSelectDialog : BaseDialogFragment(), ) { _, i -> AppConfig.systemTypefaces = i onDefaultFontChange() - dismiss() + dismissAllowingStateLoss() } }.show() } @@ -223,7 +223,7 @@ class FontSelectDialog : BaseDialogFragment(), FileUtils.deleteFile(fontFolder.absolutePath) callBack?.selectFont(docItem.uri.toString()) }.onSuccess { - dialog?.dismiss() + dismissAllowingStateLoss() } } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt index cc65046e7..fc5ed7291 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt @@ -188,7 +188,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference label.isChecked = item.toString() == dialogValue root.setOnClickListener { onChanged?.invoke(item.toString()) - this@IconDialog.dismiss() + this@IconDialog.dismissAllowingStateLoss() } } }