Skip to content

Commit

Permalink
🛠️ Hide systemBars only after successfully loading a book in Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Acclorite committed Jan 29, 2025
1 parent b637d9c commit c37fd7b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import ua.acclorite.book_story.domain.reader.ReaderText.Chapter
@Immutable
sealed class ReaderEvent {

data object OnLoadText : ReaderEvent()
data class OnLoadText(
val activity: ComponentActivity,
val fullscreenMode: Boolean
) : ReaderEvent()

data class OnMenuVisibility(
val show: Boolean,
Expand Down
28 changes: 14 additions & 14 deletions app/src/main/java/ua/acclorite/book_story/ui/reader/ReaderModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,21 @@ class ReaderModel @Inject constructor(
errorMessage = UIText.StringResource(R.string.error_could_not_get_text)
)
}
systemBarsVisibility(show = true, activity = event.activity)
return@launch
}

systemBarsVisibility(
show = !event.fullscreenMode,
activity = event.activity
)

val lastOpened = getLatestHistory.execute(_state.value.book.id)?.time
yield()

_state.update {
it.copy(
showMenu = false,
book = it.book.copy(
lastOpened = lastOpened
),
Expand Down Expand Up @@ -131,23 +138,19 @@ class ReaderModel @Inject constructor(

is ReaderEvent.OnMenuVisibility -> {
launch {
if (_state.value.lockMenu) {
return@launch
}

val shouldShow = event.show
if (_state.value.lockMenu) return@launch

yield()

systemBarsVisibility(
show = shouldShow || !event.fullscreenMode,
show = event.show || !event.fullscreenMode,
activity = event.activity
)
_state.update {
it.copy(
showMenu = shouldShow,
showMenu = event.show,
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)
}
Expand Down Expand Up @@ -475,14 +478,11 @@ class ReaderModel @Inject constructor(
}

onEvent(
ReaderEvent.OnMenuVisibility(
show = false,
fullscreenMode = fullscreenMode,
saveCheckpoint = false,
activity = activity
ReaderEvent.OnLoadText(
activity = activity,
fullscreenMode = fullscreenMode
)
)
onEvent(ReaderEvent.OnLoadText)
}
}

Expand Down

0 comments on commit c37fd7b

Please sign in to comment.