🛠️ Hide systemBars only after successfully loading a book in Reader

This commit is contained in:
Acclorite 2025-01-29 17:06:00 +02:00
parent b637d9cac9
commit c37fd7b06f
2 changed files with 18 additions and 15 deletions

View file

@ -7,7 +7,10 @@ import ua.acclorite.book_story.domain.reader.ReaderText.Chapter
@Immutable @Immutable
sealed class ReaderEvent { sealed class ReaderEvent {
data object OnLoadText : ReaderEvent() data class OnLoadText(
val activity: ComponentActivity,
val fullscreenMode: Boolean
) : ReaderEvent()
data class OnMenuVisibility( data class OnMenuVisibility(
val show: Boolean, val show: Boolean,

View file

@ -80,14 +80,21 @@ class ReaderModel @Inject constructor(
errorMessage = UIText.StringResource(R.string.error_could_not_get_text) errorMessage = UIText.StringResource(R.string.error_could_not_get_text)
) )
} }
systemBarsVisibility(show = true, activity = event.activity)
return@launch return@launch
} }
systemBarsVisibility(
show = !event.fullscreenMode,
activity = event.activity
)
val lastOpened = getLatestHistory.execute(_state.value.book.id)?.time val lastOpened = getLatestHistory.execute(_state.value.book.id)?.time
yield() yield()
_state.update { _state.update {
it.copy( it.copy(
showMenu = false,
book = it.book.copy( book = it.book.copy(
lastOpened = lastOpened lastOpened = lastOpened
), ),
@ -131,23 +138,19 @@ class ReaderModel @Inject constructor(
is ReaderEvent.OnMenuVisibility -> { is ReaderEvent.OnMenuVisibility -> {
launch { launch {
if (_state.value.lockMenu) { if (_state.value.lockMenu) return@launch
return@launch
}
val shouldShow = event.show
yield() yield()
systemBarsVisibility( systemBarsVisibility(
show = shouldShow || !event.fullscreenMode, show = event.show || !event.fullscreenMode,
activity = event.activity activity = event.activity
) )
_state.update { _state.update {
it.copy( it.copy(
showMenu = shouldShow, showMenu = event.show,
checkpoint = _state.value.listState.run { checkpoint = _state.value.listState.run {
if (!shouldShow || !event.saveCheckpoint) return@run it.checkpoint if (!event.show || !event.saveCheckpoint) return@run it.checkpoint
Checkpoint(firstVisibleItemIndex, firstVisibleItemScrollOffset) Checkpoint(firstVisibleItemIndex, firstVisibleItemScrollOffset)
} }
@ -475,14 +478,11 @@ class ReaderModel @Inject constructor(
} }
onEvent( onEvent(
ReaderEvent.OnMenuVisibility( ReaderEvent.OnLoadText(
show = false, activity = activity,
fullscreenMode = fullscreenMode, fullscreenMode = fullscreenMode
saveCheckpoint = false,
activity = activity
) )
) )
onEvent(ReaderEvent.OnLoadText)
} }
} }