From b4d3bd2ffe90152770f99d7908304e1c155735a6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 24 Feb 2022 22:41:22 +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/book/arrange/ArrangeBookActivity.kt | 17 ++++++++------- .../legado/app/ui/book/cache/CacheActivity.kt | 11 ++++++---- .../ui/book/changecover/ChangeCoverDialog.kt | 10 ++++----- .../changesource/ChangeBookSourceDialog.kt | 12 +++++------ .../changesource/ChangeChapterSourceDialog.kt | 12 +++++------ .../app/ui/book/group/GroupManageDialog.kt | 3 ++- .../app/ui/book/group/GroupSelectDialog.kt | 3 ++- .../app/ui/book/local/ImportBookActivity.kt | 3 ++- .../ui/book/local/rule/TxtTocRuleActivity.kt | 3 ++- .../ui/book/read/config/SpeakEngineDialog.kt | 3 ++- .../app/ui/book/read/config/TocRegexDialog.kt | 3 ++- .../app/ui/book/search/SearchActivity.kt | 17 +++++++-------- .../book/source/manage/BookSourceActivity.kt | 13 ++++++------ .../bookshelf/style1/books/BooksFragment.kt | 2 +- .../bookshelf/style2/BookshelfFragment2.kt | 2 +- .../app/ui/main/explore/ExploreFragment.kt | 21 +++++++++---------- .../io/legado/app/ui/main/rss/RssFragment.kt | 3 ++- .../app/ui/replace/GroupManageDialog.kt | 3 ++- .../app/ui/replace/ReplaceRuleActivity.kt | 4 ++-- .../ui/rss/favorites/RssFavoritesActivity.kt | 3 ++- .../ui/rss/source/manage/GroupManageDialog.kt | 3 ++- .../ui/rss/source/manage/RssSourceActivity.kt | 6 +++--- .../ui/rss/subscription/RuleSubActivity.kt | 3 ++- 23 files changed, 83 insertions(+), 77 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index c8be06b79..4b429ad6d 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -31,6 +31,8 @@ import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.conflate +import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -110,7 +112,7 @@ class ArrangeBookActivity : VMBaseActivity appDb.bookDao.flowAudio() AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() else -> appDb.bookDao.flowByGroup(groupId) - }.collect { list -> - val books = when (getPrefInt(PreferKey.bookshelfSort)) { - 1 -> list.sortedByDescending { it.latestChapterTime } - 2 -> list.sortedWith { o1, o2 -> + }.conflate().map { books -> + when (getPrefInt(PreferKey.bookshelfSort)) { + 1 -> books.sortedByDescending { it.latestChapterTime } + 2 -> books.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) } - 3 -> list.sortedBy { it.order } - else -> list.sortedByDescending { it.durChapterTime } + 3 -> books.sortedBy { it.order } + else -> books.sortedByDescending { it.durChapterTime } } + }.conflate().collect { books -> adapter.setItems(books) } } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index c6d3ae03d..1fd092be1 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -31,6 +31,8 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.conflate +import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -156,11 +158,11 @@ class CacheActivity : VMBaseActivity() AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() else -> appDb.bookDao.flowByGroup(groupId) - }.collect { list -> - val booksDownload = list.filter { + }.conflate().map { books -> + val booksDownload = books.filter { it.type == 0 } - val books = when (getPrefInt(PreferKey.bookshelfSort)) { + when (getPrefInt(PreferKey.bookshelfSort)) { 1 -> booksDownload.sortedByDescending { it.latestChapterTime } 2 -> booksDownload.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) @@ -168,6 +170,7 @@ class CacheActivity : VMBaseActivity() 3 -> booksDownload.sortedBy { it.order } else -> booksDownload.sortedByDescending { it.durChapterTime } } + }.conflate().collect { books -> adapter.setItems(books) initCacheSize(books) } @@ -177,7 +180,7 @@ class CacheActivity : VMBaseActivity() @SuppressLint("NotifyDataSetChanged") private fun initGroupData() { launch { - appDb.bookGroupDao.flowAll().collect { + appDb.bookGroupDao.flowAll().conflate().collect { groupList.clear() groupList.addAll(it) adapter.notifyDataSetChanged() diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt index 7c4cc94fc..0183cca4b 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt @@ -67,12 +67,10 @@ class ChangeCoverDialog() : BaseDialogFragment(R.layout.dialog_change_cover), private fun initData() { launch { - viewModel.dataFlow - .conflate() - .collect { - adapter.setItems(it) - delay(1000) - } + viewModel.dataFlow.conflate().collect { + adapter.setItems(it) + delay(1000) + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt index 01e9c5d83..dd9f3681b 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt @@ -145,15 +145,13 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ binding.toolBar.menu.applyTint(requireContext()) } launch { - viewModel.searchDataFlow - .conflate() - .collect { - adapter.setItems(it) - delay(1000) - } + viewModel.searchDataFlow.conflate().collect { + adapter.setItems(it) + delay(1000) + } } launch { - appDb.bookSourceDao.flowGroupEnabled().collect { + appDb.bookSourceDao.flowGroupEnabled().conflate().collect { groups.clear() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt index 0600fc96e..2bb303621 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt @@ -177,15 +177,13 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c binding.toolBar.menu.applyTint(requireContext()) } launch { - viewModel.searchDataFlow - .conflate() - .collect { - searchBookAdapter.setItems(it) - delay(1000) - } + viewModel.searchDataFlow.conflate().collect { + searchBookAdapter.setItems(it) + delay(1000) + } } launch { - appDb.bookSourceDao.flowGroupEnabled().collect { + appDb.bookSourceDao.flowGroupEnabled().conflate().collect { groups.clear() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index a05ca5fc1..f4b0a41f1 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -28,6 +28,7 @@ import io.legado.app.utils.setLayout import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.visible +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch @@ -67,7 +68,7 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view), private fun initData() { launch { - appDb.bookGroupDao.flowAll().collect { + appDb.bookGroupDao.flowAll().conflate().collect { adapter.setItems(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index cbf4df1aa..34eb818a4 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -27,6 +27,7 @@ import io.legado.app.utils.applyTint import io.legado.app.utils.setLayout import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch @@ -86,7 +87,7 @@ class GroupSelectDialog() : BaseDialogFragment(R.layout.dialog_book_group_picker private fun initData() { launch { - appDb.bookGroupDao.flowSelect().collect { + appDb.bookGroupDao.flowSelect().conflate().collect { adapter.setItems(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index 0bb325869..b4118dc5a 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -26,6 +26,7 @@ import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File @@ -121,7 +122,7 @@ class ImportBookActivity : VMBaseActivity(), @@ -66,7 +67,7 @@ class TxtTocRuleActivity : VMBaseActivity + appDb.txtTocRuleDao.observeAll().conflate().collect { tocRules -> adapter.setItems(tocRules) upCountView() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 9d644e0dd..873276c0c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -29,6 +29,7 @@ import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch /** @@ -133,7 +134,7 @@ class SpeakEngineDialog(val callBack: CallBack) : BaseDialogFragment(R.layout.di private fun initData() { launch { - appDb.httpTTSDao.flowAll().collect { + appDb.httpTTSDao.flowAll().conflate().collect { adapter.setItems(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 26d6ec9c0..dd6cf5339 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -30,6 +30,7 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch class TocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex), @@ -89,7 +90,7 @@ class TocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex), private fun initData() { launch { - appDb.txtTocRuleDao.observeAll().collect { tocRules -> + appDb.txtTocRuleDao.observeAll().conflate().collect { tocRules -> initSelectedName(tocRules) adapter.setItems(tocRules) } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index c86089468..3a4a6a517 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -197,15 +197,13 @@ class SearchActivity : VMBaseActivity groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) @@ -287,8 +285,7 @@ class SearchActivity : VMBaseActivity appDb.searchKeywordDao.flowByUsage() else -> appDb.searchKeywordDao.flowSearch(key) - }.collect { + }.conflate().collect { historyKeyAdapter.setItems(it) if (it.isEmpty()) { binding.tvClearHistory.invisible() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 680abc426..85cbba6a8 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -295,14 +295,13 @@ class BookSourceActivity : VMBaseActivity - groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) - } - upGroupMenu() + appDb.bookSourceDao.flowGroup().conflate().collect { + groups.clear() + it.forEach { group -> + groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) } + upGroupMenu() + } } } 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 c8936cde2..3d11c05ce 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 @@ -121,7 +121,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books), } }.catch { AppLog.put("书架更新出错", it) - }.collect { list -> + }.conflate().collect { list -> binding.tvEmptyMsg.isGone = list.isNotEmpty() booksAdapter.setItems(list) delay(100) 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 88c84f71c..162ff28a8 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 @@ -140,7 +140,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), } }.catch { AppLog.put("书架更新出错", it) - }.collect { list -> + }.conflate().collect { list -> books = list booksAdapter.notifyDataSetChanged() binding.tvEmptyMsg.isGone = getItemCount() > 0 diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 4c1b8689d..3ae28997f 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -28,6 +28,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch /** @@ -102,21 +103,20 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo private fun initGroupData() { launch { - appDb.bookSourceDao.flowExploreGroup() - .collect { - groups.clear() - it.map { group -> - groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) - } - upGroupsMenu() + appDb.bookSourceDao.flowExploreGroup().conflate().collect { + groups.clear() + it.map { group -> + groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) } + upGroupsMenu() + } } } private fun upExploreData(searchKey: String? = null) { exploreFlowJob?.cancel() exploreFlowJob = launch { - val exploreFlow = when { + when { searchKey.isNullOrBlank() -> { appDb.bookSourceDao.flowExplore() } @@ -127,10 +127,9 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo else -> { appDb.bookSourceDao.flowExplore("%$searchKey%") } - } - exploreFlow.catch { + }.catch { AppLog.put("发现界面更新数据出错", it) - }.collect { + }.conflate().collect { binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty() adapter.setItems(it, diffItemCallBack) } 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 5866fd2b1..f0e6ee09c 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 @@ -28,6 +28,7 @@ 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.conflate import kotlinx.coroutines.launch @@ -121,7 +122,7 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), private fun initGroupData() { groupsFlowJob?.cancel() groupsFlowJob = launch { - appDb.rssSourceDao.flowGroup().collect { + appDb.rssSourceDao.flowGroup().conflate().collect { groups.clear() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt index 4bee342c4..84d49f1f9 100644 --- a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt @@ -27,6 +27,7 @@ import io.legado.app.utils.requestInputMethod import io.legado.app.utils.setLayout import io.legado.app.utils.splitNotBlank import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch @@ -61,7 +62,7 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view), private fun initData() { launch { - appDb.replaceRuleDao.flowGroup().collect { + appDb.replaceRuleDao.flowGroup().conflate().collect { val groups = linkedSetOf() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) 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 5e62cd9a6..171c59b54 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 @@ -194,9 +194,9 @@ class ReplaceRuleActivity : VMBaseActivity { appDb.replaceRuleDao.flowSearch("%$searchKey%") } - }.conflate().catch { + }.catch { AppLog.put("替换规则管理界面更新数据出错", it) - }.collect { + }.conflate().collect { if (dataInit) { setResult(Activity.RESULT_OK) } diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt index 43369679c..c459bea4a 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt @@ -10,6 +10,7 @@ import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.startActivity import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch @@ -34,7 +35,7 @@ class RssFavoritesActivity : BaseActivity(), private fun initData() { launch { - appDb.rssStarDao.liveAll().collect { + appDb.rssStarDao.liveAll().conflate().collect { adapter.setItems(it) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index e63231fbd..c2ff80ab2 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -25,6 +25,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch @@ -59,7 +60,7 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view), private fun initData() { launch { - appDb.rssSourceDao.flowGroup().collect { + appDb.rssSourceDao.flowGroup().conflate().collect { val groups = linkedSetOf() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) 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 33a7492cc..071efd119 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 @@ -191,7 +191,7 @@ class RssSourceActivity : VMBaseActivity groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) @@ -247,9 +247,9 @@ class RssSourceActivity : VMBaseActivity { appDb.rssSourceDao.flowSearch("%$searchKey%") } - }.conflate().catch { + }.catch { AppLog.put("订阅源管理界面更新数据出错", it) - }.collect { + }.conflate().collect { adapter.setItems(it, adapter.diffItemCallback) delay(100) } diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt index 9e160ab8d..4aa9a374a 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt @@ -20,6 +20,7 @@ import io.legado.app.utils.showDialogFragment import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -61,7 +62,7 @@ class RuleSubActivity : BaseActivity(), private fun initData() { launch { - appDb.ruleSubDao.flowAll().collect { + appDb.ruleSubDao.flowAll().conflate().collect { binding.tvEmptyMsg.isGone = it.isNotEmpty() adapter.setItems(it) }