pull/1440/head
gedoor 4 years ago
parent 785412ab2b
commit 15d6c1381f
  1. 5
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt

@ -27,7 +27,6 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlin.math.min
class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapter_list), class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapter_list),
ChapterListAdapter.Callback, ChapterListAdapter.Callback,
@ -115,7 +114,7 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
}.collect { }.collect {
if (!(searchKey.isNullOrBlank() && it.isEmpty())) { if (!(searchKey.isNullOrBlank() && it.isEmpty())) {
adapter.setItems(it, adapter.diffCallBack) adapter.setItems(it, adapter.diffCallBack)
if (searchKey.isNullOrBlank()) { if (searchKey.isNullOrBlank() && mLayoutManager.findFirstVisibleItemPosition() < 0) {
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
} }
} }
@ -127,7 +126,7 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
get() = viewModel.bookData.value?.isLocalBook() == true get() = viewModel.bookData.value?.isLocalBook() == true
override fun durChapterIndex(): Int { override fun durChapterIndex(): Int {
return min(durChapterIndex, adapter.itemCount) return durChapterIndex
} }
override fun openChapter(bookChapter: BookChapter) { override fun openChapter(bookChapter: BookChapter) {

Loading…
Cancel
Save