From aeb3732d753f34d7babb08a3a35efa4e21ce5208 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Oct 2025 08:52:55 +0000 Subject: [PATCH] Fix screen rotation causing reader to jump back to initial page - Modified BaseReaderFragment to always use getCurrentState() when available - getCurrentState() contains the most recent reading position saved in onPause/onDestroyView - content.state may contain the initial state from when content was first loaded - This ensures the current page position is preserved across configuration changes like screen rotation Co-authored-by: NathanBap <101987516+NathanBap@users.noreply.github.com> --- .../kotatsu/reader/ui/pager/BaseReaderFragment.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/BaseReaderFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/BaseReaderFragment.kt index 57fe76149..c1acaeda0 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/BaseReaderFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/BaseReaderFragment.kt @@ -25,8 +25,15 @@ abstract class BaseReaderFragment : BaseFragment(), ZoomCont readerAdapter = onCreateAdapter() viewModel.content.observe(viewLifecycleOwner) { + // Use getCurrentState() to handle configuration changes (e.g., screen rotation) properly. + // getCurrentState() always has the most recent reading position, while content.state + // may contain the initial state from when content was first loaded. + val currentState = viewModel.getCurrentState() if (it.state == null && it.pages.isNotEmpty() && readerAdapter?.hasItems != true) { - onPagesChanged(it.pages, viewModel.getCurrentState()) + onPagesChanged(it.pages, currentState) + } else if (currentState != null) { + // If we have a current state, use it instead of content.state + onPagesChanged(it.pages, currentState) } else { onPagesChanged(it.pages, it.state) }