Fix random scrolling when bookmarking a chapter

This commit is contained in:
Jobobby04 2022-01-15 20:44:51 -05:00
parent e8100fc958
commit cccf956fae

View File

@ -49,18 +49,20 @@ class ReaderChapterDialog(private val activity: ReaderActivity) : ReaderChapterA
dialog.show() dialog.show()
} }
private fun refreshList() { private fun refreshList(scroll: Boolean = true) {
val chapters = presenter.getChapters(activity) val chapters = presenter.getChapters(activity)
.sortedWith(getChapterSort(presenter.manga!!)) .sortedWith(getChapterSort(presenter.manga!!))
adapter?.clear() adapter?.clear()
adapter?.updateDataSet(chapters) adapter?.updateDataSet(chapters)
if (scroll) {
(binding.chapterRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( (binding.chapterRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
adapter?.getGlobalPositionOf(chapters.find { it.isCurrent }) ?: 0, adapter?.getGlobalPositionOf(chapters.find { it.isCurrent }) ?: 0,
(binding.chapterRecycler.height / 2).dpToPx (binding.chapterRecycler.height / 2).dpToPx
) )
} }
}
fun destroy() { fun destroy() {
adapter = null adapter = null
@ -68,6 +70,6 @@ class ReaderChapterDialog(private val activity: ReaderActivity) : ReaderChapterA
override fun bookmarkChapter(chapter: Chapter) { override fun bookmarkChapter(chapter: Chapter) {
presenter.toggleBookmark(chapter) presenter.toggleBookmark(chapter)
refreshList() refreshList(scroll = false)
} }
} }