pull/1440/head
gedoor 3 years ago
parent 6b35a1251a
commit 785412ab2b
  1. 6
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt

@ -38,7 +38,6 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
private var durChapterIndex = 0 private var durChapterIndex = 0
private lateinit var mLayoutManager: UpLinearLayoutManager private lateinit var mLayoutManager: UpLinearLayoutManager
private var tocFlowJob: Job? = null private var tocFlowJob: Job? = null
private var isFirstSetData = true
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run {
viewModel.chapterCallBack = this@ChapterListFragment viewModel.chapterCallBack = this@ChapterListFragment
@ -114,10 +113,11 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl) searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl)
else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey) else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey)
}.collect { }.collect {
if (!(searchKey.isNullOrBlank() && it.isEmpty())) {
adapter.setItems(it, adapter.diffCallBack) adapter.setItems(it, adapter.diffCallBack)
if (isFirstSetData) { if (searchKey.isNullOrBlank()) {
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
isFirstSetData = false }
} }
} }
} }

Loading…
Cancel
Save