From 0e1d20c5ce732a50f2c5c066bff24d3f4cf25c41 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 1 Dec 2022 17:25:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/explore/ExploreShowViewModel.kt | 7 ++++--- .../java/io/legado/app/ui/book/search/SearchViewModel.kt | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt index 03961d139..76e2287ec 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt @@ -5,17 +5,16 @@ import android.content.Intent import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import io.legado.app.base.BaseViewModel +import io.legado.app.constant.AppLog import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.model.webBook.WebBook import io.legado.app.utils.printOnDebug import io.legado.app.utils.stackTraceStr - import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.mapLatest -import kotlinx.coroutines.launch @OptIn(ExperimentalCoroutinesApi::class) @@ -29,7 +28,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application private var page = 1 init { - viewModelScope.launch { + execute { appDb.bookDao.flowAll().mapLatest { books -> books.map { "${it.name}-${it.author}" } }.collect { @@ -37,6 +36,8 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application bookshelf.addAll(it) upAdapterLiveData.postValue("isInBookshelf") } + }.onError { + AppLog.put("加载书架数据失败", it) } } 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 a75582147..44e4121f1 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 @@ -4,6 +4,7 @@ import android.app.Application import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import io.legado.app.base.BaseViewModel +import io.legado.app.constant.AppLog import io.legado.app.data.appDb import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchKeyword @@ -70,6 +71,8 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { bookshelf.addAll(it) upAdapterLiveData.postValue("isInBookshelf") } + }.onError { + AppLog.put("加载书架数据失败", it) } }