|
|
|
@ -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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|