From 32415395227095cde1fdeade7261ec88e79c78a5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 15:23:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/chapterlist/ChapterListFragment.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 29cea56a3..9c7254b84 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -55,7 +55,11 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme withContext(IO) { 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(R.layout.fragme tocLiveData = App.db.bookChapterDao().observeByBook(viewModel.bookUrl) tocLiveData?.observe(viewLifecycleOwner, Observer { 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(R.layout.fragme tocLiveData = App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl, newText) tocLiveData?.observe(viewLifecycleOwner, Observer { adapter.setItems(it) - mLayoutManager.scrollToPositionWithOffset(0, 0) }) } }