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 0b639bfe6..6336c5697 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 @@ -42,7 +42,10 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.* -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.conflate +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.map /** * 书源管理界面 @@ -269,8 +272,9 @@ class BookSourceActivity : VMBaseActivity + }.collect { data -> adapter.setItems(data, adapter.diffItemCallback) + delay(500) } } } 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 7d2ee168c..11dc587f0 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,7 +17,8 @@ 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.delay +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch @@ -51,8 +52,9 @@ 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) - }.collectLatest { + }.conflate().collect { adapter.setItems(it) + delay(100) } } } 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 7448f8457..fa3c60bbc 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 @@ -21,13 +21,10 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.ColorUtils import io.legado.app.utils.observeEvent import io.legado.app.utils.viewbindingdelegate.viewBinding -import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.* 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 +import kotlinx.coroutines.flow.conflate class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapter_list), ChapterListAdapter.Callback, @@ -111,7 +108,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt when { searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl) else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey) - }.collectLatest { + }.conflate().collect { if (!(searchKey.isNullOrBlank() && it.isEmpty())) { adapter.setItems(it, adapter.diffCallBack) adapter.upDisplayTile() @@ -119,6 +116,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) } } + delay(100) } } } 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 f9b0ffa0d..c8936cde2 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 @@ -24,8 +24,8 @@ 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.delay import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch @@ -121,9 +121,10 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books), } }.catch { AppLog.put("书架更新出错", it) - }.collectLatest { list -> + }.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 6a8a5c778..88c84f71c 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 @@ -26,8 +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.delay import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch @@ -140,10 +140,11 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), } }.catch { AppLog.put("书架更新出错", it) - }.collectLatest { list -> + }.collect { list -> books = list booksAdapter.notifyDataSetChanged() binding.tvEmptyMsg.isGone = getItemCount() > 0 + delay(100) } } } 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 a42730342..5e62cd9a6 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 @@ -38,8 +38,9 @@ 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.delay import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch /** @@ -193,14 +194,15 @@ class ReplaceRuleActivity : VMBaseActivity { appDb.replaceRuleDao.flowSearch("%$searchKey%") } - }.catch { + }.conflate().catch { AppLog.put("替换规则管理界面更新数据出错", it) - }.collectLatest { + }.collect { if (dataInit) { setResult(Activity.RESULT_OK) } adapter.setItems(it, adapter.diffItemCallBack) dataInit = true + delay(100) } } } 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 2b0a57d76..33a7492cc 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 @@ -33,8 +33,9 @@ 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.delay import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch /** @@ -246,10 +247,11 @@ class RssSourceActivity : VMBaseActivity { appDb.rssSourceDao.flowSearch("%$searchKey%") } - }.catch { + }.conflate().catch { AppLog.put("订阅源管理界面更新数据出错", it) - }.collectLatest { + }.collect { adapter.setItems(it, adapter.diffItemCallback) + delay(100) } } }