Fix reader state on changed

This commit is contained in:
Koitharu
2024-02-18 09:08:22 +02:00
parent bd98d8eded
commit abc3e45907
2 changed files with 8 additions and 1 deletions

View File

@@ -22,6 +22,9 @@ abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
private val differ = AsyncListDiffer(this, DiffCallback())
val hasItems: Boolean
get() = itemCount != 0
init {
stateRestorationPolicy = StateRestorationPolicy.PREVENT
}

View File

@@ -29,7 +29,11 @@ abstract class BaseReaderFragment<B : ViewBinding> : BaseFragment<B>(), ZoomCont
readerAdapter = onCreateAdapter()
viewModel.content.observe(viewLifecycleOwner) {
onPagesChanged(it.pages, restoredState ?: it.state)
var pendingState = restoredState ?: it.state
if (pendingState == null && readerAdapter?.hasItems != true) {
pendingState = viewModel.getCurrentState()
}
onPagesChanged(it.pages, pendingState)
restoredState = null
}
}