From 785412ab2b2a3e5408a744281bb8ce187da5d333 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 27 Nov 2021 15:47:38 +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 --- .../io/legado/app/ui/book/toc/ChapterListFragment.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 93b82d1c6..8e37c5b88 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 @@ -38,7 +38,6 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt private var durChapterIndex = 0 private lateinit var mLayoutManager: UpLinearLayoutManager private var tocFlowJob: Job? = null - private var isFirstSetData = true override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run { viewModel.chapterCallBack = this@ChapterListFragment @@ -114,10 +113,11 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl) else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey) }.collect { - adapter.setItems(it, adapter.diffCallBack) - if (isFirstSetData) { - mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) - isFirstSetData = false + if (!(searchKey.isNullOrBlank() && it.isEmpty())) { + adapter.setItems(it, adapter.diffCallBack) + if (searchKey.isNullOrBlank()) { + mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) + } } } }