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 }