From f5d3b27ae039194964330d9a772fe61ddbde1c63 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 25 Mar 2022 21:30:41 +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 --- .../changesource/ChangeBookSourceDialog.kt | 19 +++++++++++++++++++ .../changesource/ChangeChapterSourceDialog.kt | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt index 4ad7d64f6..a1197acd8 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt @@ -23,6 +23,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.DialogBookChangeSourceBinding import io.legado.app.help.config.AppConfig +import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.manage.BookSourceActivity @@ -54,6 +55,23 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) { viewModel.startSearch() } + private val searchFinishCallback: (isEmpty: Boolean) -> Unit = { + if (it) { + val searchGroup = getPrefString("searchGroup") + if (!searchGroup.isNullOrEmpty()) { + launch { + alert("搜索结果为空") { + setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组") + cancelButton() + okButton { + putPrefString("searchGroup", "") + viewModel.startSearch() + } + } + } + } + } + } override fun onStart() { super.onStart() @@ -69,6 +87,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ initSearchView() initBottomBar() initLiveData() + viewModel.searchFinishCallback = searchFinishCallback } private fun showTitle() { diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt index 303fac5af..a819b15d6 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt @@ -25,6 +25,7 @@ import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.DialogChapterChangeSourceBinding import io.legado.app.help.BookHelp import io.legado.app.help.config.AppConfig +import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.elevation import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.book.source.edit.BookSourceEditActivity @@ -79,6 +80,23 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c dismissAllowingStateLoss() } private var searchBook: SearchBook? = null + private val searchFinishCallback: (isEmpty: Boolean) -> Unit = { + if (it) { + val searchGroup = getPrefString("searchGroup") + if (!searchGroup.isNullOrEmpty()) { + launch { + alert("搜索结果为空") { + setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组") + cancelButton() + okButton { + putPrefString("searchGroup", "") + viewModel.startSearch() + } + } + } + } + } + } override fun onStart() { super.onStart() @@ -96,6 +114,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c initSearchView() initBottomBar() initLiveData() + viewModel.searchFinishCallback = searchFinishCallback } private fun showTitle() {