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,17 +49,19 @@ 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)
(binding.chapterRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( if (scroll) {
adapter?.getGlobalPositionOf(chapters.find { it.isCurrent }) ?: 0, (binding.chapterRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
(binding.chapterRecycler.height / 2).dpToPx adapter?.getGlobalPositionOf(chapters.find { it.isCurrent }) ?: 0,
) (binding.chapterRecycler.height / 2).dpToPx
)
}
} }
fun destroy() { fun destroy() {
@ -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)
} }
} }