pull/37/head
kunfei 5 years ago
parent cc31dfecd5
commit 884eba851b
  1. 18
      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.data.entities.SearchKeyword
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
@ -48,11 +49,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
.timeout(30000L) .timeout(30000L)
.onSuccess(Dispatchers.IO) { .onSuccess(Dispatchers.IO) {
it?.let { list -> it?.let { list ->
list.map { searchBook -> searchSuccess(list)
if (searchBook.name.contains(key) || searchBook.author.contains(key)) {
}
App.db.searchBookDao().insert(searchBook)
}
} }
} }
} }
@ -63,6 +60,17 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
} }
} }
private fun searchSuccess(searchBooks: List<SearchBook>) {
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() { fun stop() {
task?.cancel() task?.cancel()
} }

Loading…
Cancel
Save