🚀 "Keep Screen On" option
* Added "Keep screen on" option in Reader * If true, keeps screen awake in Reader infinitely, does not apply to other screens
This commit is contained in:
parent
5d7f3e09ac
commit
5e628d9b28
10 changed files with 72 additions and 7 deletions
|
|
@ -31,6 +31,7 @@ object DataStoreConstants {
|
||||||
val LETTER_SPACING = intPreferencesKey("letter_spacing")
|
val LETTER_SPACING = intPreferencesKey("letter_spacing")
|
||||||
val CUTOUT_PADDING = booleanPreferencesKey("cutout_padding")
|
val CUTOUT_PADDING = booleanPreferencesKey("cutout_padding")
|
||||||
val FULLSCREEN = booleanPreferencesKey("fullscreen")
|
val FULLSCREEN = booleanPreferencesKey("fullscreen")
|
||||||
|
val KEEP_SCREEN_ON = booleanPreferencesKey("keep_screen_on")
|
||||||
|
|
||||||
// Browse settings
|
// Browse settings
|
||||||
val BROWSE_FILES_STRUCTURE = stringPreferencesKey("browse_files_structure")
|
val BROWSE_FILES_STRUCTURE = stringPreferencesKey("browse_files_structure")
|
||||||
|
|
|
||||||
|
|
@ -34,4 +34,5 @@ sealed class MainEvent {
|
||||||
data class OnChangeAbsoluteDark(val bool: Boolean) : MainEvent()
|
data class OnChangeAbsoluteDark(val bool: Boolean) : MainEvent()
|
||||||
data class OnChangeCutoutPadding(val bool: Boolean) : MainEvent()
|
data class OnChangeCutoutPadding(val bool: Boolean) : MainEvent()
|
||||||
data class OnChangeFullscreen(val bool: Boolean) : MainEvent()
|
data class OnChangeFullscreen(val bool: Boolean) : MainEvent()
|
||||||
|
data class OnChangeKeepScreenOn(val bool: Boolean) : MainEvent()
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +71,7 @@ data class MainState(
|
||||||
val letterSpacing: Int = provideDefaultValue { 0 },
|
val letterSpacing: Int = provideDefaultValue { 0 },
|
||||||
val cutoutPadding: Boolean = provideDefaultValue { false },
|
val cutoutPadding: Boolean = provideDefaultValue { false },
|
||||||
val fullscreen: Boolean = provideDefaultValue { true },
|
val fullscreen: Boolean = provideDefaultValue { true },
|
||||||
|
val keepScreenOn: Boolean = provideDefaultValue { true },
|
||||||
|
|
||||||
// Browse Settings
|
// Browse Settings
|
||||||
val browseFilesStructure: BrowseFilesStructure = provideDefaultValue {
|
val browseFilesStructure: BrowseFilesStructure = provideDefaultValue {
|
||||||
|
|
@ -224,6 +225,10 @@ data class MainState(
|
||||||
fullscreen = provideValue(
|
fullscreen = provideValue(
|
||||||
FULLSCREEN
|
FULLSCREEN
|
||||||
) { fullscreen },
|
) { fullscreen },
|
||||||
|
|
||||||
|
keepScreenOn = provideValue(
|
||||||
|
KEEP_SCREEN_ON
|
||||||
|
) { keepScreenOn },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -415,6 +415,20 @@ class MainViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is MainEvent.OnChangeKeepScreenOn -> {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
setDatastore.execute(
|
||||||
|
DataStoreConstants.KEEP_SCREEN_ON,
|
||||||
|
event.bool
|
||||||
|
)
|
||||||
|
updateStateWithSavedHandle {
|
||||||
|
it.copy(
|
||||||
|
keepScreenOn = event.bool
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,8 @@ import androidx.compose.ui.unit.em
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
import ua.acclorite.book_story.presentation.core.components.CustomAnimatedVisibility
|
import ua.acclorite.book_story.presentation.core.components.CustomAnimatedVisibility
|
||||||
import ua.acclorite.book_story.presentation.core.components.CustomSelectionContainer
|
import ua.acclorite.book_story.presentation.core.components.CustomSelectionContainer
|
||||||
|
|
@ -140,6 +142,14 @@ fun ReaderScreenRoot(screen: Screen.Reader) {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
LaunchedEffect(mainState.value.keepScreenOn) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
when (mainState.value.keepScreenOn) {
|
||||||
|
true -> context.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
false -> context.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
LaunchedEffect(lazyListState) {
|
LaunchedEffect(lazyListState) {
|
||||||
viewModel.onUpdateProgress {
|
viewModel.onUpdateProgress {
|
||||||
onLibraryEvent(LibraryEvent.OnUpdateBook(it))
|
onLibraryEvent(LibraryEvent.OnUpdateBook(it))
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import android.app.SearchManager
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.WindowManager
|
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.compose.runtime.snapshotFlow
|
import androidx.compose.runtime.snapshotFlow
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
|
|
@ -23,7 +22,6 @@ 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.withContext
|
|
||||||
import kotlinx.coroutines.yield
|
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
|
||||||
|
|
@ -417,10 +415,6 @@ class ReaderViewModel @Inject constructor(
|
||||||
|
|
||||||
clear()
|
clear()
|
||||||
launch {
|
launch {
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
activity.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
|
||||||
}
|
|
||||||
|
|
||||||
onEvent(
|
onEvent(
|
||||||
ReaderEvent.OnShowHideMenu(
|
ReaderEvent.OnShowHideMenu(
|
||||||
show = false,
|
show = false,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.settings
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import ua.acclorite.book_story.R
|
||||||
|
import ua.acclorite.book_story.presentation.core.components.LocalMainViewModel
|
||||||
|
import ua.acclorite.book_story.presentation.data.MainEvent
|
||||||
|
import ua.acclorite.book_story.presentation.screens.settings.components.SwitchWithTitle
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep Screen On setting.
|
||||||
|
* If true, keeps screen awake in Reader.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun KeepScreenOnSetting() {
|
||||||
|
val state = LocalMainViewModel.current.state
|
||||||
|
val onMainEvent = LocalMainViewModel.current.onEvent
|
||||||
|
|
||||||
|
SwitchWithTitle(
|
||||||
|
selected = state.value.keepScreenOn,
|
||||||
|
title = stringResource(id = R.string.keep_screen_on_option),
|
||||||
|
description = stringResource(id = R.string.keep_screen_on_option_desc),
|
||||||
|
onClick = {
|
||||||
|
onMainEvent(
|
||||||
|
MainEvent.OnChangeKeepScreenOn(
|
||||||
|
!state.value.keepScreenOn
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -17,6 +17,7 @@ import androidx.compose.ui.unit.dp
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
import ua.acclorite.book_story.presentation.core.components.CategoryTitle
|
import ua.acclorite.book_story.presentation.core.components.CategoryTitle
|
||||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.settings.FullscreenSetting
|
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.settings.FullscreenSetting
|
||||||
|
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.settings.KeepScreenOnSetting
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Misc subcategory.
|
* Misc subcategory.
|
||||||
|
|
@ -51,6 +52,10 @@ fun LazyListScope.MiscSubcategory(
|
||||||
FullscreenSetting()
|
FullscreenSetting()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
KeepScreenOnSetting()
|
||||||
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
Spacer(
|
Spacer(
|
||||||
modifier = Modifier.height(bottomPadding)
|
modifier = Modifier.height(bottomPadding)
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@
|
||||||
<string name="dark_theme_option">Темна тема</string>
|
<string name="dark_theme_option">Темна тема</string>
|
||||||
<string name="pure_dark_option">Суцільна темрява (ОЛЕД)</string>
|
<string name="pure_dark_option">Суцільна темрява (ОЛЕД)</string>
|
||||||
<string name="absolute_dark_option">Абсолютна темрява</string>
|
<string name="absolute_dark_option">Абсолютна темрява</string>
|
||||||
<string name="absolute_dark_option_desc">Змініть колір фона на повністю чорний</string>
|
<string name="absolute_dark_option_desc">Змінити колір фона на повністю чорний</string>
|
||||||
<string name="theme_contrast_option">Контрастність теми</string>
|
<string name="theme_contrast_option">Контрастність теми</string>
|
||||||
<string name="app_theme_option">Тема застосунка</string>
|
<string name="app_theme_option">Тема застосунка</string>
|
||||||
<string name="check_for_updates_option">Перевіряти на оновлення</string>
|
<string name="check_for_updates_option">Перевіряти на оновлення</string>
|
||||||
|
|
@ -242,6 +242,8 @@
|
||||||
<string name="cutout_padding_option_desc">Застосувати відступ до ділянки виїмки</string>
|
<string name="cutout_padding_option_desc">Застосувати відступ до ділянки виїмки</string>
|
||||||
<string name="fullscreen_option">Повний екран</string>
|
<string name="fullscreen_option">Повний екран</string>
|
||||||
<string name="fullscreen_option_desc">Сховати системні панелі та прибрати відступи</string>
|
<string name="fullscreen_option_desc">Сховати системні панелі та прибрати відступи</string>
|
||||||
|
<string name="keep_screen_on_option">Тримати екран увімкненим</string>
|
||||||
|
<string name="keep_screen_on_option_desc">Тримати екран увімкненим нескінченно</string>
|
||||||
|
|
||||||
<!-- Browse -->
|
<!-- Browse -->
|
||||||
<string name="browse_files_structure_option">Структура файлів</string>
|
<string name="browse_files_structure_option">Структура файлів</string>
|
||||||
|
|
|
||||||
|
|
@ -259,6 +259,8 @@
|
||||||
<string name="cutout_padding_option_desc">Apply padding to cutout area</string>
|
<string name="cutout_padding_option_desc">Apply padding to cutout area</string>
|
||||||
<string name="fullscreen_option">Fullscreen</string>
|
<string name="fullscreen_option">Fullscreen</string>
|
||||||
<string name="fullscreen_option_desc">Hide system bars and remove padding</string>
|
<string name="fullscreen_option_desc">Hide system bars and remove padding</string>
|
||||||
|
<string name="keep_screen_on_option">Keep screen on</string>
|
||||||
|
<string name="keep_screen_on_option_desc">Keep screen awake infinitely</string>
|
||||||
|
|
||||||
<!-- Browse -->
|
<!-- Browse -->
|
||||||
<string name="browse_files_structure_option">Files structure</string>
|
<string name="browse_files_structure_option">Files structure</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue