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