This commit is contained in:
Horis
2025-11-29 13:58:08 +08:00
parent dfe8129113
commit 21679eff53
3 changed files with 15 additions and 17 deletions
@@ -8,7 +8,6 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle.State.STARTED import androidx.lifecycle.Lifecycle.State.STARTED
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
@@ -19,6 +18,7 @@ import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
/** /**
@@ -70,14 +70,13 @@ class ChangeCoverDialog() : BaseDialogFragment(R.layout.dialog_change_cover),
private fun initData() { private fun initData() {
lifecycleScope.launch { lifecycleScope.launch {
repeatOnLifecycle(STARTED) { lifecycle.currentStateFlow.first { it.isAtLeast(STARTED) }
viewModel.dataFlow.conflate().collect { viewModel.dataFlow.conflate().collect {
adapter.setItems(it) adapter.setItems(it)
delay(1000) delay(1000)
} }
} }
} }
}
override fun observeLiveBus() { override fun observeLiveBus() {
super.observeLiveBus() super.observeLiveBus()
@@ -49,6 +49,7 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
/** /**
@@ -231,13 +232,12 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.menu.applyTint(requireContext())
} }
lifecycleScope.launch { lifecycleScope.launch {
repeatOnLifecycle(STARTED) { lifecycle.currentStateFlow.first { it.isAtLeast(STARTED) }
viewModel.searchDataFlow.conflate().collect { viewModel.searchDataFlow.conflate().collect {
adapter.setItems(it) adapter.setItems(it)
delay(1000) delay(1000)
} }
} }
}
lifecycleScope.launch { lifecycleScope.launch {
repeatOnLifecycle(STARTED) { repeatOnLifecycle(STARTED) {
@@ -13,7 +13,6 @@ import androidx.core.view.isVisible
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle.State.STARTED import androidx.lifecycle.Lifecycle.State.STARTED
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
@@ -49,6 +48,7 @@ import io.legado.app.utils.visible
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -232,13 +232,12 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.menu.applyTint(requireContext())
} }
lifecycleScope.launch { lifecycleScope.launch {
repeatOnLifecycle(STARTED) { lifecycle.currentStateFlow.first { it.isAtLeast(STARTED) }
viewModel.searchDataFlow.conflate().collect { viewModel.searchDataFlow.conflate().collect {
searchBookAdapter.setItems(it) searchBookAdapter.setItems(it)
delay(1000) delay(1000)
} }
} }
}
lifecycleScope.launch { lifecycleScope.launch {
appDb.bookSourceDao.flowEnabledGroups().conflate().collect { appDb.bookSourceDao.flowEnabledGroups().conflate().collect {
groups.clear() groups.clear()