Revert "Fix page position loss when switching reader modes"

This reverts commit 5f879f6c83.
This commit is contained in:
Koitharu
2025-10-14 13:47:21 +03:00
parent 803c825d91
commit 8423b48fb9

View File

@@ -25,16 +25,18 @@ abstract class BaseReaderFragment<B : ViewBinding> : BaseFragment<B>(), ZoomCont
readerAdapter = onCreateAdapter()
viewModel.content.observe(viewLifecycleOwner) {
// Determine which state to use for restoring position:
// - content.state: explicitly set state (e.g., after mode switch or chapter change)
// - getCurrentState(): current reading position saved in SavedStateHandle
// 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()
val pendingState = when {
it.state == null && it.pages.isNotEmpty() && readerAdapter?.hasItems != true -> currentState
readerAdapter?.hasItems != true && it.state != currentState && currentState != null -> currentState
else -> it.state
if (it.state == null && it.pages.isNotEmpty() && readerAdapter?.hasItems != true) {
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)
}
onPagesChanged(it.pages, pendingState)
}
}