|
|
|
@ -25,11 +25,26 @@ abstract class BaseReaderFragment<B : ViewBinding> : BaseFragment<B>(), ZoomCont
|
|
|
|
readerAdapter = onCreateAdapter()
|
|
|
|
readerAdapter = onCreateAdapter()
|
|
|
|
|
|
|
|
|
|
|
|
viewModel.content.observe(viewLifecycleOwner) {
|
|
|
|
viewModel.content.observe(viewLifecycleOwner) {
|
|
|
|
if (it.state == null && it.pages.isNotEmpty() && readerAdapter?.hasItems != true) {
|
|
|
|
// Determine which state to use for restoring position:
|
|
|
|
onPagesChanged(it.pages, viewModel.getCurrentState())
|
|
|
|
// - content.state: explicitly set state (e.g., after mode switch or chapter change)
|
|
|
|
} else {
|
|
|
|
// - getCurrentState(): current reading position saved in SavedStateHandle
|
|
|
|
onPagesChanged(it.pages, it.state)
|
|
|
|
val currentState = viewModel.getCurrentState()
|
|
|
|
|
|
|
|
val pendingState = when {
|
|
|
|
|
|
|
|
// If content.state is null and we have pages, use getCurrentState
|
|
|
|
|
|
|
|
it.state == null
|
|
|
|
|
|
|
|
&& it.pages.isNotEmpty()
|
|
|
|
|
|
|
|
&& readerAdapter?.hasItems != true -> currentState
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// use currentState only if it matches the current pages (to avoid the error message)
|
|
|
|
|
|
|
|
readerAdapter?.hasItems != true
|
|
|
|
|
|
|
|
&& it.state != currentState
|
|
|
|
|
|
|
|
&& currentState != null
|
|
|
|
|
|
|
|
&& it.pages.any { page -> page.chapterId == currentState.chapterId } -> currentState
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, use content.state (normal flow, mode switch, chapter change)
|
|
|
|
|
|
|
|
else -> it.state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onPagesChanged(it.pages, pendingState)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|