From 884eba851bbf213cc6c2637a75cdefa2c7170aae Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 19 Oct 2019 16:23:55 +0800 Subject: [PATCH] up --- .../app/ui/book/search/SearchViewModel.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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 88979461a..184d8c782 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.getPrefBoolean import io.legado.app.utils.getPrefString import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.asCoroutineDispatcher @@ -48,11 +49,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { .timeout(30000L) .onSuccess(Dispatchers.IO) { it?.let { list -> - list.map { searchBook -> - if (searchBook.name.contains(key) || searchBook.author.contains(key)) { - } - App.db.searchBookDao().insert(searchBook) - } + searchSuccess(list) } } } @@ -63,6 +60,17 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } } + private fun searchSuccess(searchBooks: List) { + searchBooks.forEach { searchBook -> + if (context.getPrefBoolean("precisionSearch")) { + if (searchBook.name.contains(searchKey) + || searchBook.author.contains(searchKey) + ) App.db.searchBookDao().insert(searchBook) + } else + App.db.searchBookDao().insert(searchBook) + } + } + fun stop() { task?.cancel() }