pull/32/head
kunfei 5 years ago
parent f6acc94ea3
commit 8a4a1b1b14
  1. 4
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  2. 16
      app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt

@ -19,8 +19,8 @@ interface SearchBookDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg searchBook: SearchBook) fun insert(vararg searchBook: SearchBook): List<Long>
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(searchBook: SearchBook) fun insert(searchBook: SearchBook): Long
} }

@ -20,19 +20,23 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
val search = WebBook(item).searchBook(key, searchPage) val search = WebBook(item).searchBook(key, searchPage)
.onSuccess { searchBookS -> .onSuccess { searchBookS ->
searchBookS?.let { searchBookS?.let {
for (searchBook in searchBookS) { execute {
when (key) { for (searchBook in searchBookS) {
searchBook.name -> searchBook.searchOrder = 0 when (key) {
searchBook.author -> searchBook.searchOrder = 1 searchBook.name -> searchBook.searchOrder = 0
else -> searchBook.searchOrder = 1000 searchBook.author -> searchBook.searchOrder = 1
else -> searchBook.searchOrder = 1000
}
App.db.searchBookDao().insert(searchBook)
} }
App.db.searchBookDao().insert(searchBook)
} }
} }
} }
tasks.add(search) tasks.add(search)
} }
}.onError {
it.printStackTrace()
} }
} }

Loading…
Cancel
Save