Revert "Fix page position loss when switching reader modes"
This reverts commit 5f879f6c83.
This commit is contained in:
@@ -25,16 +25,18 @@ abstract class BaseReaderFragment<B : ViewBinding> : BaseFragment<B>(), ZoomCont
|
|||||||
readerAdapter = onCreateAdapter()
|
readerAdapter = onCreateAdapter()
|
||||||
|
|
||||||
viewModel.content.observe(viewLifecycleOwner) {
|
viewModel.content.observe(viewLifecycleOwner) {
|
||||||
// Determine which state to use for restoring position:
|
// Use getCurrentState() to handle configuration changes (e.g., screen rotation) properly.
|
||||||
// - content.state: explicitly set state (e.g., after mode switch or chapter change)
|
// getCurrentState() always has the most recent reading position, while content.state
|
||||||
// - getCurrentState(): current reading position saved in SavedStateHandle
|
// may contain the initial state from when content was first loaded.
|
||||||
val currentState = viewModel.getCurrentState()
|
val currentState = viewModel.getCurrentState()
|
||||||
val pendingState = when {
|
if (it.state == null && it.pages.isNotEmpty() && readerAdapter?.hasItems != true) {
|
||||||
it.state == null && it.pages.isNotEmpty() && readerAdapter?.hasItems != true -> currentState
|
onPagesChanged(it.pages, currentState)
|
||||||
readerAdapter?.hasItems != true && it.state != currentState && currentState != null -> currentState
|
} else if (currentState != null) {
|
||||||
else -> it.state
|
// 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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user