pull/1440/head
gedoor 3 years ago
parent 6b35a1251a
commit 785412ab2b
  1. 10
      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 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<TocViewModel>(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)
}
}
}
}

Loading…
Cancel
Save