pull/94/head
kunfei 5 years ago
parent 9f5863e80e
commit 3241539522
  1. 12
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt

@ -55,7 +55,11 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
withContext(IO) { withContext(IO) {
book = App.db.bookDao().getBook(viewModel.bookUrl) book = App.db.bookDao().getBook(viewModel.bookUrl)
} }
tv_current_chapter_info.text = book?.durChapterTitle book?.let {
durChapterIndex = it.durChapterIndex
tv_current_chapter_info.text = it.durChapterTitle
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
}
} }
} }
@ -64,12 +68,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
tocLiveData = App.db.bookChapterDao().observeByBook(viewModel.bookUrl) tocLiveData = App.db.bookChapterDao().observeByBook(viewModel.bookUrl)
tocLiveData?.observe(viewLifecycleOwner, Observer { tocLiveData?.observe(viewLifecycleOwner, Observer {
adapter.setItems(it) adapter.setItems(it)
if (it.isEmpty()) return@Observer
book?.let { book ->
durChapterIndex = book.durChapterIndex
tv_current_chapter_info.text = it[durChapterIndex].title
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
}
}) })
} }
@ -96,7 +95,6 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
tocLiveData = App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl, newText) tocLiveData = App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl, newText)
tocLiveData?.observe(viewLifecycleOwner, Observer { tocLiveData?.observe(viewLifecycleOwner, Observer {
adapter.setItems(it) adapter.setItems(it)
mLayoutManager.scrollToPositionWithOffset(0, 0)
}) })
} }
} }

Loading…
Cancel
Save