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 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 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 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
|
## [v0.21.1] - 2026-10-12
|
||||||
### Fixed
|
### 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
|
* 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
|
var nextTransition: ChapterTransition.Next? = null
|
||||||
private set
|
private set
|
||||||
@@ -68,13 +68,15 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
|
|||||||
|
|
||||||
val lastPage = pages.last()
|
val lastPage = pages.last()
|
||||||
|
|
||||||
// Insert preprocessed pages into current page list
|
// Insert preprocessed pages into current page list. Pages of the adjacent chapters are split too, and
|
||||||
preprocessed.keys.sortedDescending()
|
// placed by their index, so only this chapter's belong here.
|
||||||
.forEach { key ->
|
preprocessed.filter { it.chapter.chapter.id == chapters.currChapter.chapter.id }
|
||||||
if (lastPage.index == key) {
|
.sortedByDescending { it.index }
|
||||||
insertPageLastPage = preprocessed[key]
|
.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)
|
newItems.addAll(pages)
|
||||||
@@ -105,7 +107,8 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
|
|||||||
newItems.reverse()
|
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
|
items = newItems
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
|
|
||||||
@@ -161,9 +164,12 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
|
|||||||
|
|
||||||
val currentIndex = items.indexOf(currentPage)
|
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) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user