From 196843350ef667485a4b94fa8f4441c41110f18d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 26 Feb 2022 23:34:01 +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 --- .../app/ui/book/changecover/ChangeCoverDialog.kt | 12 ++++++++---- .../ui/book/changesource/ChangeBookSourceDialog.kt | 12 ++++++++---- .../book/changesource/ChangeChapterSourceDialog.kt | 12 ++++++++---- .../io/legado/app/ui/book/search/SearchActivity.kt | 3 ++- 4 files changed, 26 insertions(+), 13 deletions(-) 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 0183cca4b..d891165d6 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 @@ -6,6 +6,7 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar import androidx.fragment.app.viewModels +import androidx.lifecycle.whenStarted import androidx.recyclerview.widget.GridLayoutManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -14,6 +15,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.utils.applyTint import io.legado.app.utils.setLayout import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch @@ -66,10 +68,12 @@ class ChangeCoverDialog() : BaseDialogFragment(R.layout.dialog_change_cover), } private fun initData() { - launch { - viewModel.dataFlow.conflate().collect { - adapter.setItems(it) - delay(1000) + launch(Dispatchers.Default) { + whenStarted { + 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 dd9f3681b..319a5f0ba 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 @@ -9,6 +9,7 @@ import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.Toolbar import androidx.core.os.bundleOf import androidx.fragment.app.viewModels +import androidx.lifecycle.whenStarted import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R @@ -28,6 +29,7 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch @@ -144,10 +146,12 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ } binding.toolBar.menu.applyTint(requireContext()) } - launch { - viewModel.searchDataFlow.conflate().collect { - adapter.setItems(it) - delay(1000) + launch(Dispatchers.Default) { + whenStarted { + viewModel.searchDataFlow.conflate().collect { + adapter.setItems(it) + delay(1000) + } } } launch { 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 2bb303621..3d7024729 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 @@ -9,6 +9,7 @@ import androidx.appcompat.widget.Toolbar import androidx.core.os.bundleOf import androidx.core.view.isVisible import androidx.fragment.app.viewModels +import androidx.lifecycle.whenStarted import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -30,6 +31,7 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.launch @@ -176,10 +178,12 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c } binding.toolBar.menu.applyTint(requireContext()) } - launch { - viewModel.searchDataFlow.conflate().collect { - searchBookAdapter.setItems(it) - delay(1000) + launch(Dispatchers.Default) { + whenStarted { + viewModel.searchDataFlow.conflate().collect { + searchBookAdapter.setItems(it) + delay(1000) + } } } launch { 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 ca986697c..0a3a983d1 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 @@ -29,6 +29,7 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.widget.recycler.LoadMoreView import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.Dispatchers.Default import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Job import kotlinx.coroutines.delay @@ -198,7 +199,7 @@ class SearchActivity : VMBaseActivity