|
|
@ -36,6 +36,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme |
|
|
|
private var durChapterIndex = 0 |
|
|
|
private var durChapterIndex = 0 |
|
|
|
private lateinit var mLayoutManager: UpLinearLayoutManager |
|
|
|
private lateinit var mLayoutManager: UpLinearLayoutManager |
|
|
|
private var tocLiveData: LiveData<List<BookChapter>>? = null |
|
|
|
private var tocLiveData: LiveData<List<BookChapter>>? = null |
|
|
|
|
|
|
|
private var scrollToDurChapter = false |
|
|
|
|
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
viewModel.chapterCallBack = this |
|
|
|
viewModel.chapterCallBack = this |
|
|
@ -74,7 +75,6 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme |
|
|
|
book?.let { |
|
|
|
book?.let { |
|
|
|
durChapterIndex = it.durChapterIndex |
|
|
|
durChapterIndex = it.durChapterIndex |
|
|
|
tv_current_chapter_info.text = it.durChapterTitle |
|
|
|
tv_current_chapter_info.text = it.durChapterTitle |
|
|
|
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) |
|
|
|
|
|
|
|
initCacheFileNames(it) |
|
|
|
initCacheFileNames(it) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -85,7 +85,10 @@ 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 (!scrollToDurChapter) { |
|
|
|
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) |
|
|
|
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) |
|
|
|
|
|
|
|
scrollToDurChapter = true |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|