🛠️ Fix hiding system bars in other screens
Fixed hiding system bars in other screens after quitting Reader.
This commit is contained in:
parent
cd583f56d4
commit
c23609a71c
4 changed files with 68 additions and 56 deletions
|
|
@ -2,6 +2,7 @@ package ua.acclorite.book_story.presentation.screens.reader
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Build
|
||||
import android.view.WindowManager
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.BackHandler
|
||||
|
|
@ -46,6 +47,8 @@ import androidx.compose.ui.text.font.FontStyle
|
|||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import ua.acclorite.book_story.R
|
||||
import ua.acclorite.book_story.domain.util.Constants
|
||||
|
|
@ -137,6 +140,11 @@ fun ReaderScreenRoot(screen: Screen.Reader) {
|
|||
DisposableEffect(Unit) {
|
||||
onDispose {
|
||||
viewModel.clearViewModel()
|
||||
WindowCompat.getInsetsController(
|
||||
context.window,
|
||||
context.window.decorView
|
||||
).show(WindowInsetsCompat.Type.systemBars())
|
||||
context.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -441,7 +449,7 @@ private fun ReaderScreen(
|
|||
onLibraryEvent(LibraryEvent.OnLoadList)
|
||||
onEvent(
|
||||
ReaderEvent.OnGoBack(
|
||||
context,
|
||||
context = context,
|
||||
refreshList = {
|
||||
onLibraryEvent(LibraryEvent.OnUpdateBook(it))
|
||||
onHistoryEvent(HistoryEvent.OnUpdateBook(it))
|
||||
|
|
@ -476,7 +484,7 @@ private fun ReaderScreen(
|
|||
BackHandler {
|
||||
onEvent(
|
||||
ReaderEvent.OnGoBack(
|
||||
context,
|
||||
context = context,
|
||||
refreshList = {
|
||||
onLibraryEvent(LibraryEvent.OnUpdateBook(it))
|
||||
onHistoryEvent(HistoryEvent.OnUpdateBook(it))
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ fun ReaderEndItem(
|
|||
if (state.value.book.category != Category.ALREADY_READ) {
|
||||
onEvent(
|
||||
ReaderEvent.OnMoveBookToAlreadyRead(
|
||||
context = context,
|
||||
onUpdateCategories = {
|
||||
onLibraryEvent(LibraryEvent.OnUpdateBook(it))
|
||||
onHistoryUpdateEvent(HistoryEvent.OnUpdateBook(it))
|
||||
|
|
@ -106,8 +107,7 @@ fun ReaderEndItem(
|
|||
updatePage = {
|
||||
onLibraryEvent(LibraryEvent.OnUpdateCurrentPage(it))
|
||||
},
|
||||
onNavigate = onNavigate,
|
||||
context = context
|
||||
onNavigate = onNavigate
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ fun ReaderEndItem(
|
|||
} else {
|
||||
onEvent(
|
||||
ReaderEvent.OnGoBack(
|
||||
context,
|
||||
context = context,
|
||||
refreshList = {
|
||||
onLibraryEvent(LibraryEvent.OnUpdateBook(it))
|
||||
onHistoryUpdateEvent(HistoryEvent.OnUpdateBook(it))
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ fun ReaderTopBar(
|
|||
) {
|
||||
onEvent(
|
||||
ReaderEvent.OnGoBack(
|
||||
context,
|
||||
context = context,
|
||||
refreshList = {
|
||||
onLibraryUpdateEvent(LibraryEvent.OnUpdateBook(it))
|
||||
onHistoryUpdateEvent(HistoryEvent.OnUpdateBook(it))
|
||||
|
|
@ -106,7 +106,7 @@ fun ReaderTopBar(
|
|||
onClick = {
|
||||
onEvent(
|
||||
ReaderEvent.OnGoBack(
|
||||
context,
|
||||
context = context,
|
||||
refreshList = {
|
||||
onLibraryUpdateEvent(LibraryEvent.OnUpdateBook(it))
|
||||
onHistoryUpdateEvent(HistoryEvent.OnUpdateBook(it))
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import kotlinx.coroutines.flow.debounce
|
|||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.yield
|
||||
import ua.acclorite.book_story.R
|
||||
import ua.acclorite.book_story.domain.model.Book
|
||||
import ua.acclorite.book_story.domain.model.Category
|
||||
|
|
@ -161,21 +162,23 @@ class ReaderViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
is ReaderEvent.OnShowHideMenu -> {
|
||||
launch {
|
||||
if (_state.value.lockMenu) {
|
||||
return@launch
|
||||
}
|
||||
|
||||
val shouldShow = event.show ?: !_state.value.showMenu
|
||||
|
||||
val insetsController = WindowCompat.getInsetsController(
|
||||
yield()
|
||||
|
||||
WindowCompat.getInsetsController(
|
||||
event.context.window,
|
||||
event.context.window.decorView
|
||||
)
|
||||
).apply {
|
||||
yield()
|
||||
|
||||
insetsController.systemBarsBehavior =
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
|
||||
insetsController.apply {
|
||||
systemBarsBehavior = WindowInsetsControllerCompat
|
||||
.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
if (shouldShow) {
|
||||
show(WindowInsetsCompat.Type.systemBars())
|
||||
} else {
|
||||
|
|
@ -189,32 +192,31 @@ class ReaderViewModel @Inject constructor(
|
|||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is ReaderEvent.OnGoBack -> {
|
||||
launch {
|
||||
yield()
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
lockMenu = true
|
||||
)
|
||||
}
|
||||
|
||||
val insetsController = WindowCompat.getInsetsController(
|
||||
event.context.window,
|
||||
event.context.window.decorView
|
||||
)
|
||||
|
||||
val listState = _state.value.listState
|
||||
_state.value.listState.apply {
|
||||
if (
|
||||
!_state.value.loading &&
|
||||
listState.layoutInfo.totalItemsCount != 0 &&
|
||||
_state.value.text.isNotEmpty()
|
||||
) {
|
||||
_state.value.loading
|
||||
|| layoutInfo.totalItemsCount < 1
|
||||
|| _state.value.text.isEmpty()
|
||||
) return@apply
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
book = it.book.copy(
|
||||
progress = calculateProgress(),
|
||||
scrollIndex = listState.firstVisibleItemIndex,
|
||||
scrollOffset = listState.firstVisibleItemScrollOffset
|
||||
scrollIndex = firstVisibleItemIndex,
|
||||
scrollOffset = firstVisibleItemScrollOffset
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -225,8 +227,11 @@ class ReaderViewModel @Inject constructor(
|
|||
event.refreshList(_state.value.book)
|
||||
}
|
||||
|
||||
insetsController.show(WindowInsetsCompat.Type.systemBars())
|
||||
event.context.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
WindowCompat.getInsetsController(
|
||||
event.context.window,
|
||||
event.context.window.decorView
|
||||
).show(WindowInsetsCompat.Type.systemBars())
|
||||
|
||||
event.navigate()
|
||||
}
|
||||
}
|
||||
|
|
@ -279,27 +284,21 @@ class ReaderViewModel @Inject constructor(
|
|||
|
||||
is ReaderEvent.OnMoveBookToAlreadyRead -> {
|
||||
launch {
|
||||
onEvent(
|
||||
ReaderEvent.OnGoBack(
|
||||
event.context,
|
||||
refreshList = {},
|
||||
navigate = {}
|
||||
)
|
||||
)
|
||||
yield()
|
||||
|
||||
_state.update {
|
||||
val listState = it.listState
|
||||
it.copy(
|
||||
lockMenu = true,
|
||||
book = it.book.copy(
|
||||
category = Category.ALREADY_READ,
|
||||
progress = 1f,
|
||||
scrollIndex = listState.firstVisibleItemIndex,
|
||||
scrollOffset = listState.firstVisibleItemScrollOffset
|
||||
scrollIndex = it.listState.firstVisibleItemIndex,
|
||||
scrollOffset = it.listState.firstVisibleItemScrollOffset
|
||||
)
|
||||
)
|
||||
}
|
||||
updateBooks.execute(listOf(_state.value.book))
|
||||
|
||||
updateBooks.execute(listOf(_state.value.book))
|
||||
event.onUpdateCategories(
|
||||
_state.value.book
|
||||
)
|
||||
|
|
@ -309,6 +308,11 @@ class ReaderViewModel @Inject constructor(
|
|||
}.size - 1
|
||||
)
|
||||
|
||||
WindowCompat.getInsetsController(
|
||||
event.context.window,
|
||||
event.context.window.decorView
|
||||
).show(WindowInsetsCompat.Type.systemBars())
|
||||
|
||||
event.onNavigate {
|
||||
navigate(
|
||||
Screen.Library,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue