Update reader state on chapter switch

This commit is contained in:
Koitharu
2024-07-07 08:55:21 +03:00
parent a158a488f2
commit c3ca734005

View File

@@ -283,7 +283,9 @@ constructor(
prevJob?.cancelAndJoin() prevJob?.cancelAndJoin()
content.value = ReaderContent(emptyList(), null) content.value = ReaderContent(emptyList(), null)
chaptersLoader.loadSingleChapter(id) chaptersLoader.loadSingleChapter(id)
content.value = ReaderContent(chaptersLoader.snapshot(), ReaderState(id, page, 0)) val newState = ReaderState(id, page, 0)
content.value = ReaderContent(chaptersLoader.snapshot(), newState)
saveCurrentState(newState)
} }
} }
@@ -305,14 +307,13 @@ constructor(
} }
content.value = ReaderContent(emptyList(), null) content.value = ReaderContent(emptyList(), null)
chaptersLoader.loadSingleChapter(newChapterId) chaptersLoader.loadSingleChapter(newChapterId)
content.value = ReaderContent( val newState = ReaderState(
chaptersLoader.snapshot(), chapterId = newChapterId,
ReaderState( page = if (delta == 0) prevState.page else 0,
chapterId = newChapterId, scroll = if (delta == 0) prevState.scroll else 0,
page = if (delta == 0) prevState.page else 0,
scroll = if (delta == 0) prevState.scroll else 0,
),
) )
content.value = ReaderContent(chaptersLoader.snapshot(), newState)
saveCurrentState(newState)
} }
} }