From 8a4a1b1b14f7ed01db7cb3c976b671de73823319 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 5 Aug 2019 09:15:04 +0800 Subject: [PATCH] up --- .../java/io/legado/app/data/dao/SearchBookDao.kt | 4 ++-- .../io/legado/app/ui/search/SearchViewModel.kt | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt index 0bde5a81c..157a4f1e4 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt @@ -19,8 +19,8 @@ interface SearchBookDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(vararg searchBook: SearchBook) + fun insert(vararg searchBook: SearchBook): List @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(searchBook: SearchBook) + fun insert(searchBook: SearchBook): Long } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt index cfe671ce5..865b1b3b7 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt @@ -20,19 +20,23 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { val search = WebBook(item).searchBook(key, searchPage) .onSuccess { searchBookS -> searchBookS?.let { - for (searchBook in searchBookS) { - when (key) { - searchBook.name -> searchBook.searchOrder = 0 - searchBook.author -> searchBook.searchOrder = 1 - else -> searchBook.searchOrder = 1000 + execute { + for (searchBook in searchBookS) { + when (key) { + searchBook.name -> searchBook.searchOrder = 0 + searchBook.author -> searchBook.searchOrder = 1 + else -> searchBook.searchOrder = 1000 + } + App.db.searchBookDao().insert(searchBook) } - App.db.searchBookDao().insert(searchBook) } } } tasks.add(search) } + }.onError { + it.printStackTrace() } }