diff --git a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt index 21c5cf785..7d2ee168c 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt @@ -17,6 +17,7 @@ import io.legado.app.utils.setEdgeEffectColor import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch @@ -50,7 +51,7 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_bookmark when { searchKey.isNullOrBlank() -> appDb.bookmarkDao.flowByBook(book.name, book.author) else -> appDb.bookmarkDao.flowSearch(book.name, book.author, searchKey) - }.collect { + }.collectLatest { adapter.setItems(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index 985f61aff..7448f8457 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -25,6 +25,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -110,7 +111,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt when { searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl) else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey) - }.collect { + }.collectLatest { if (!(searchKey.isNullOrBlank() && it.isEmpty())) { adapter.setItems(it, adapter.diffCallBack) adapter.upDisplayTile() diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index 861d8e8a1..a42730342 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -14,6 +14,7 @@ import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.AppLog import io.legado.app.constant.AppPattern import io.legado.app.data.appDb import io.legado.app.data.entities.ReplaceRule @@ -37,6 +38,8 @@ import io.legado.app.ui.widget.recycler.VerticalDivider 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 /** @@ -190,7 +193,9 @@ class ReplaceRuleActivity : VMBaseActivity { appDb.replaceRuleDao.flowSearch("%$searchKey%") } - }.collect { + }.catch { + AppLog.put("替换规则管理界面更新数据出错", it) + }.collectLatest { if (dataInit) { setResult(Activity.RESULT_OK) } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 442fef0c5..2b0a57d76 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -11,6 +11,7 @@ import androidx.appcompat.widget.SearchView import androidx.recyclerview.widget.ItemTouchHelper import io.legado.app.R import io.legado.app.base.VMBaseActivity +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 @@ -32,6 +33,8 @@ import io.legado.app.ui.widget.recycler.VerticalDivider 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 /** @@ -243,7 +246,9 @@ class RssSourceActivity : VMBaseActivity { appDb.rssSourceDao.flowSearch("%$searchKey%") } - }.collect { + }.catch { + AppLog.put("订阅源管理界面更新数据出错", it) + }.collectLatest { adapter.setItems(it, adapter.diffItemCallback) } }