From 701453cc1b86f64057b6b837c74d492c6b8ef812 Mon Sep 17 00:00:00 2001 From: 821938089 <821938089@qq.com> Date: Tue, 19 Jul 2022 09:46:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=86=E7=BB=84=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/BookSourceDao.kt | 9 ++++- .../app/ui/book/search/SearchActivity.kt | 40 ++++++++++++------- .../app/ui/book/search/SearchAdapter.kt | 4 +- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 182023f72..f98063115 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -96,7 +96,14 @@ interface BookSourceDao { @Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'") fun getByGroup(group: String): List - @Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'") + @Query( + """select * from book_sources + where enabled = 1 + and (bookSourceGroup = :group + or bookSourceGroup like :group || ',%' + or bookSourceGroup like '%,' || :group + or bookSourceGroup like '%,' || :group || ',%')""" + ) fun getEnabledByGroup(group: String): List @Query("select * from book_sources where enabled = 1 and bookSourceType = :type") 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 d04b0b7d7..bb254de03 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 @@ -36,6 +36,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import splitties.init.appCtx class SearchActivity : VMBaseActivity(), BookAdapter.CallBack, @@ -65,21 +66,29 @@ class SearchActivity : VMBaseActivity() - private val searchFinishCallback: (isEmpty: Boolean) -> Unit = { - if (it) { - val searchGroup = AppConfig.searchGroup - if (searchGroup.isNotEmpty()) { - launch { - alert("搜索结果为空") { - setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组") - noButton() - yesButton { - AppConfig.searchGroup = "" - viewModel.searchKey = "" - viewModel.search(searchView.query.toString()) - } + private val searchFinishCallback: (isEmpty: Boolean) -> Unit = searchFinish@{ isEmpty -> + val searchGroup = AppConfig.searchGroup + if (!isEmpty || searchGroup.isEmpty()) return@searchFinish + launch { + alert("搜索结果为空") { + val precisionSearch = appCtx.getPrefBoolean(PreferKey.precisionSearch) + if (precisionSearch) { + setMessage("${searchGroup}分组搜索结果为空,是否关闭精准搜索?") + yesButton { + appCtx.putPrefBoolean(PreferKey.precisionSearch, false) + precisionSearchMenuItem?.isChecked = false + viewModel.searchKey = "" + viewModel.search(searchView.query.toString()) + } + } else { + setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组?") + yesButton { + AppConfig.searchGroup = "" + viewModel.searchKey = "" + viewModel.search(searchView.query.toString()) } } + noButton() } } } @@ -359,10 +368,11 @@ class SearchActivity : VMBaseActivity { putExtra("name", name) putExtra("author", author) + putExtra("bookUrl", bookUrl) } } @@ -370,7 +380,7 @@ class SearchActivity : VMBaseActivity