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