From 6fe2f6529f4830669725b9407410efa483db576e Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 14 Oct 2022 11:08:27 +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/book/search/SearchActivity.kt | 20 +++++------ .../legado/app/ui/book/search/SearchScope.kt | 33 +++++++++++++------ 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 739181f19..210b27160 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -21,7 +21,6 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchKeyword import io.legado.app.databinding.ActivityBookSearchBinding -import io.legado.app.help.config.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.* import io.legado.app.ui.about.AppLogDialog @@ -68,13 +67,12 @@ class SearchActivity : VMBaseActivity Unit = searchFinish@{ isEmpty -> - val searchGroup = AppConfig.searchGroup - if (!isEmpty || searchGroup.isEmpty()) return@searchFinish + if (!isEmpty || viewModel.searchScope.isAll()) return@searchFinish launch { alert("搜索结果为空") { val precisionSearch = appCtx.getPrefBoolean(PreferKey.precisionSearch) if (precisionSearch) { - setMessage("${searchGroup}分组搜索结果为空,是否关闭精准搜索?") + setMessage("${viewModel.searchScope.display}分组搜索结果为空,是否关闭精准搜索?") yesButton { appCtx.putPrefBoolean(PreferKey.precisionSearch, false) precisionSearchMenuItem?.isChecked = false @@ -82,10 +80,10 @@ class SearchActivity : VMBaseActivity { - val list = arrayListOf() - if (scope.contains("::")) { - list.add(scope.substringBefore("::")) - } else { - scope.splitNotBlank(",").forEach { - list.add(it) + val displayNames: List + get() { + val list = arrayListOf() + if (scope.contains("::")) { + list.add(scope.substringBefore("::")) + } else { + scope.splitNotBlank(",").forEach { + list.add(it) + } } - } - if (list.isEmpty()) { - list.add("全部书源") + if (list.isEmpty()) { + list.add("全部书源") } return list } @@ -72,6 +81,10 @@ data class SearchScope(private var scope: String) { return list.sortedBy { it.customOrder } } + fun isAll(): Boolean { + return scope.isEmpty() + } + fun save() { AppConfig.searchScope = scope }