From 181b5914f2c7e68b588207896b552a522fc9fa5b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 13 Feb 2022 23:27:17 +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 --- .../ui/main/bookshelf/style1/books/BooksFragment.kt | 8 ++++---- .../ui/main/bookshelf/style2/BookshelfFragment2.kt | 11 ++++++----- .../java/io/legado/app/ui/main/rss/RssFragment.kt | 4 ++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt index 7b3cf27e0..f23ddd7ff 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt @@ -10,10 +10,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.BaseFragment -import io.legado.app.constant.AppConst -import io.legado.app.constant.BookType -import io.legado.app.constant.EventBus -import io.legado.app.constant.PreferKey +import io.legado.app.constant.* import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.databinding.FragmentBooksBinding @@ -27,6 +24,7 @@ import io.legado.app.ui.main.MainViewModel import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.catch import kotlinx.coroutines.launch import kotlin.math.max @@ -109,6 +107,8 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books), AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() else -> appDb.bookDao.flowByGroup(groupId) + }.catch { + AppLog.put("书架更新出错", it) }.collect { list -> binding.tvEmptyMsg.isGone = list.isNotEmpty() val books = when (getPrefInt(PreferKey.bookshelfSort)) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt index b04206928..7e05728aa 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt @@ -9,10 +9,7 @@ import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R -import io.legado.app.constant.AppConst -import io.legado.app.constant.BookType -import io.legado.app.constant.EventBus -import io.legado.app.constant.PreferKey +import io.legado.app.constant.* import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup @@ -29,6 +26,8 @@ import io.legado.app.ui.main.bookshelf.BaseBookshelfFragment import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import kotlin.math.max @@ -122,7 +121,9 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() else -> appDb.bookDao.flowByGroup(groupId) - }.collect { list -> + }.catch { + AppLog.put("书架更新出错", it) + }.collectLatest { list -> books = when (getPrefInt(PreferKey.bookshelfSort)) { 1 -> list.sortedByDescending { it.latestChapterTime diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index a5c92c271..5866fd2b1 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -9,6 +9,7 @@ import androidx.appcompat.widget.SearchView import androidx.fragment.app.viewModels import io.legado.app.R import io.legado.app.base.VMBaseFragment +import io.legado.app.constant.AppLog import io.legado.app.constant.AppPattern import io.legado.app.data.appDb import io.legado.app.data.entities.RssSource @@ -26,6 +27,7 @@ import io.legado.app.ui.rss.subscription.RuleSubActivity import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.catch import kotlinx.coroutines.launch @@ -139,6 +141,8 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), appDb.rssSourceDao.flowEnabledByGroup("%$key%") } else -> appDb.rssSourceDao.flowEnabled("%$searchKey%") + }.catch { + AppLog.put("订阅界面更新数据出错", it) }.collect { adapter.setItems(it) }