mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-16 21:52:25 -07:00
Insert split pages only into the chapter they belong to
This commit is contained in:
@@ -41,6 +41,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
||||
- Fixed a crash when a back gesture was still in progress as the reader or a dialog closed ([@AntsyLich](https://github.com/AntsyLich))
|
||||
- Fixed Kitsu login and other requests that send data failing with "Failed to bypass Cloudflare" ([@AntsyLich](https://github.com/AntsyLich))
|
||||
- Fixed tracker start date being off by a day when adding tracking to an entry with read history in some timezones ([@hazptr](https://github.com/hazptr)) ([#4049](https://github.com/mihonapp/mihon/pull/4049))
|
||||
- Fixed the paged reader crashing when moving to another chapter after a wide page of a neighbouring chapter was split ([@AntsyLich](https://github.com/AntsyLich))
|
||||
|
||||
## [v0.21.1] - 2026-10-12
|
||||
### Fixed
|
||||
|
||||
+16
-10
@@ -26,7 +26,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
|
||||
/**
|
||||
* Holds preprocessed items so they don't get removed when changing chapter
|
||||
*/
|
||||
private var preprocessed: MutableMap<Int, InsertPage> = mutableMapOf()
|
||||
private var preprocessed: List<InsertPage> = emptyList()
|
||||
|
||||
var nextTransition: ChapterTransition.Next? = null
|
||||
private set
|
||||
@@ -68,13 +68,15 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
|
||||
|
||||
val lastPage = pages.last()
|
||||
|
||||
// Insert preprocessed pages into current page list
|
||||
preprocessed.keys.sortedDescending()
|
||||
.forEach { key ->
|
||||
if (lastPage.index == key) {
|
||||
insertPageLastPage = preprocessed[key]
|
||||
// Insert preprocessed pages into current page list. Pages of the adjacent chapters are split too, and
|
||||
// placed by their index, so only this chapter's belong here.
|
||||
preprocessed.filter { it.chapter.chapter.id == chapters.currChapter.chapter.id }
|
||||
.sortedByDescending { it.index }
|
||||
.forEach { page ->
|
||||
if (lastPage.index == page.index) {
|
||||
insertPageLastPage = page
|
||||
}
|
||||
preprocessed[key]?.let { pages.add(key + 1, it) }
|
||||
pages.add(page.index + 1, page)
|
||||
}
|
||||
|
||||
newItems.addAll(pages)
|
||||
@@ -105,7 +107,8 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
|
||||
newItems.reverse()
|
||||
}
|
||||
|
||||
preprocessed = mutableMapOf()
|
||||
val adjacentChapterIds = setOfNotNull(chapters.prevChapter?.chapter?.id, chapters.nextChapter?.chapter?.id)
|
||||
preprocessed = preprocessed.filter { it.chapter.chapter.id in adjacentChapterIds }
|
||||
items = newItems
|
||||
notifyDataSetChanged()
|
||||
|
||||
@@ -161,9 +164,12 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
|
||||
|
||||
val currentIndex = items.indexOf(currentPage)
|
||||
|
||||
// Put aside preprocessed pages for next chapter so they don't get removed when changing chapter
|
||||
// Put aside pages of an adjacent chapter until it becomes the current one, so they are not lost on the change
|
||||
if (currentPage.chapter.chapter.id != currentChapter?.chapter?.id) {
|
||||
preprocessed[newPage.index] = newPage
|
||||
val chapterId = newPage.chapter.chapter.id
|
||||
if (preprocessed.none { it.chapter.chapter.id == chapterId && it.index == newPage.index }) {
|
||||
preprocessed = preprocessed + newPage
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user