From cc31dfecd586dbf10565b06aae16517f268e4d24 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 19 Oct 2019 16:09:50 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/data/dao/BookSourceDao.kt | 3 +++ .../io/legado/app/ui/book/search/SearchViewModel.kt | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 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 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) } }