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 2f3e1896b..d2b48fa49 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 @@ -44,6 +44,9 @@ 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 || '%'") + fun getEnabledByGroup(group: String): List + @get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = ''") val noGroup: List diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 0c21d1820..88979461a 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -7,6 +7,7 @@ import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchKeyword import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook +import io.legado.app.utils.getPrefString import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors @@ -30,7 +31,12 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { start?.invoke() task = execute { //onCleared时自动取消 - val bookSourceList = App.db.bookSourceDao().allEnabled + val searchGroup = context.getPrefString("searchGroup") ?: "" + val bookSourceList = if (searchGroup.isBlank()) { + App.db.bookSourceDao().allEnabled + } else { + App.db.bookSourceDao().getEnabledByGroup(searchGroup) + } for (item in bookSourceList) { //task取消时自动取消 by (scope = this@execute) WebBook(item).searchBook( @@ -43,7 +49,8 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { .onSuccess(Dispatchers.IO) { it?.let { list -> list.map { searchBook -> - if (searchBook.name.contains(key) || searchBook.author.contains(key)) + if (searchBook.name.contains(key) || searchBook.author.contains(key)) { + } App.db.searchBookDao().insert(searchBook) } }