From 9e2dd726acf1911bc6021c83e6079e3e1c87185a Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Wed, 3 Jan 2024 11:21:46 +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 --- .../bookshelf/style1/books/BooksFragment.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) 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 c2d54b64e..2ef7c2fcf 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 @@ -25,13 +25,21 @@ import io.legado.app.ui.book.audio.AudioPlayActivity import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.main.MainViewModel -import io.legado.app.utils.* +import io.legado.app.utils.SystemUtils +import io.legado.app.utils.cnCompare +import io.legado.app.utils.observeEvent +import io.legado.app.utils.setEdgeEffectColor +import io.legado.app.utils.startActivity import io.legado.app.utils.viewbindingdelegate.viewBinding -import kotlinx.coroutines.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map +import kotlinx.coroutines.isActive +import kotlinx.coroutines.launch import kotlin.math.max /** @@ -69,6 +77,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books), private set private var upLastUpdateTimeJob: Job? = null private var defaultScrollBarSize = 0 + private var enableRefresh = true override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { this.savedInstanceState = savedInstanceState @@ -135,8 +144,9 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books), } } - fun setEnableRefresh(enableRefresh: Boolean) { - binding.refreshLayout.isEnabled = enableRefresh + fun setEnableRefresh(enable: Boolean) { + enableRefresh = enable + binding.refreshLayout.isEnabled = enable } /** @@ -166,9 +176,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books), AppLog.put("书架更新出错", it) }.conflate().collect { list -> binding.tvEmptyMsg.isGone = list.isNotEmpty() - binding.refreshLayout.run { - isEnabled = isEnabled && list.isNotEmpty() - } + binding.refreshLayout.isEnabled = enableRefresh && list.isNotEmpty() booksAdapter.setItems(list) recoverPositionState() delay(100)