🚀 Hide Bars On Fast Scroll option
* Added "Hide bars on fast scroll" option in Reader * If true, hides bars during fast scroll
This commit is contained in:
parent
11e21bf60b
commit
0496004cc4
10 changed files with 61 additions and 6 deletions
|
|
@ -33,6 +33,7 @@ object DataStoreConstants {
|
||||||
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")
|
val KEEP_SCREEN_ON = booleanPreferencesKey("keep_screen_on")
|
||||||
|
val HIDE_BARS_ON_FAST_SCROLL = booleanPreferencesKey("hide_bars_on_fast_scroll")
|
||||||
|
|
||||||
// Browse settings
|
// Browse settings
|
||||||
val BROWSE_FILES_STRUCTURE = stringPreferencesKey("browse_files_structure")
|
val BROWSE_FILES_STRUCTURE = stringPreferencesKey("browse_files_structure")
|
||||||
|
|
|
||||||
|
|
@ -36,4 +36,5 @@ sealed class MainEvent {
|
||||||
data class OnChangeFullscreen(val bool: Boolean) : MainEvent()
|
data class OnChangeFullscreen(val bool: Boolean) : MainEvent()
|
||||||
data class OnChangeKeepScreenOn(val bool: Boolean) : MainEvent()
|
data class OnChangeKeepScreenOn(val bool: Boolean) : MainEvent()
|
||||||
data class OnChangeVerticalPadding(val padding: Int) : MainEvent()
|
data class OnChangeVerticalPadding(val padding: Int) : MainEvent()
|
||||||
|
data class OnChangeHideBarsOnFastScroll(val bool: Boolean) : MainEvent()
|
||||||
}
|
}
|
||||||
|
|
@ -73,6 +73,7 @@ data class MainState(
|
||||||
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 },
|
val keepScreenOn: Boolean = provideDefaultValue { true },
|
||||||
|
val hideBarsOnFastScroll: Boolean = provideDefaultValue { true },
|
||||||
|
|
||||||
// Browse Settings
|
// Browse Settings
|
||||||
val browseFilesStructure: BrowseFilesStructure = provideDefaultValue {
|
val browseFilesStructure: BrowseFilesStructure = provideDefaultValue {
|
||||||
|
|
@ -234,6 +235,10 @@ data class MainState(
|
||||||
verticalPadding = provideValue(
|
verticalPadding = provideValue(
|
||||||
VERTICAL_PADDING
|
VERTICAL_PADDING
|
||||||
) { verticalPadding },
|
) { verticalPadding },
|
||||||
|
|
||||||
|
hideBarsOnFastScroll = provideValue(
|
||||||
|
HIDE_BARS_ON_FAST_SCROLL
|
||||||
|
) { hideBarsOnFastScroll },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -443,6 +443,20 @@ class MainViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is MainEvent.OnChangeHideBarsOnFastScroll -> {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
setDatastore.execute(
|
||||||
|
DataStoreConstants.HIDE_BARS_ON_FAST_SCROLL,
|
||||||
|
event.bool
|
||||||
|
)
|
||||||
|
updateStateWithSavedHandle {
|
||||||
|
it.copy(
|
||||||
|
hideBarsOnFastScroll = event.bool
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,17 +191,20 @@ private fun ReaderScreen(lazyListState: LazyListState) {
|
||||||
available: Offset,
|
available: Offset,
|
||||||
source: NestedScrollSource
|
source: NestedScrollSource
|
||||||
): Offset {
|
): Offset {
|
||||||
val velocity = consumed.y
|
consumed.y.let { velocity ->
|
||||||
|
if(velocity in -70f..70f) return@let
|
||||||
|
if(!state.value.showMenu) return@let
|
||||||
|
if(state.value.lockMenu) return@let
|
||||||
|
if(!mainState.value.hideBarsOnFastScroll) return@let
|
||||||
|
|
||||||
if ((velocity > 70 || velocity < -70) && state.value.showMenu && !state.value.lockMenu) {
|
|
||||||
onEvent(
|
onEvent(
|
||||||
ReaderEvent.OnShowHideMenu(
|
ReaderEvent.OnShowHideMenu(
|
||||||
|
show = false,
|
||||||
fullscreenMode = mainState.value.fullscreen,
|
fullscreenMode = mainState.value.fullscreen,
|
||||||
activity = context
|
activity = context
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onPostScroll(consumed, available, source)
|
return super.onPostScroll(consumed, available, source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide Bars On Fast Scroll setting.
|
||||||
|
* If true, hides bars during fast scroll.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun HideBarsOnFastScrollSetting() {
|
||||||
|
val state = LocalMainViewModel.current.state
|
||||||
|
val onMainEvent = LocalMainViewModel.current.onEvent
|
||||||
|
|
||||||
|
SwitchWithTitle(
|
||||||
|
selected = state.value.hideBarsOnFastScroll,
|
||||||
|
title = stringResource(id = R.string.hide_bars_on_fast_scroll_option)
|
||||||
|
) {
|
||||||
|
onMainEvent(
|
||||||
|
MainEvent.OnChangeHideBarsOnFastScroll(!state.value.hideBarsOnFastScroll)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,7 +19,6 @@ fun KeepScreenOnSetting() {
|
||||||
SwitchWithTitle(
|
SwitchWithTitle(
|
||||||
selected = state.value.keepScreenOn,
|
selected = state.value.keepScreenOn,
|
||||||
title = stringResource(id = R.string.keep_screen_on_option),
|
title = stringResource(id = R.string.keep_screen_on_option),
|
||||||
description = stringResource(id = R.string.keep_screen_on_option_desc),
|
|
||||||
onClick = {
|
onClick = {
|
||||||
onMainEvent(
|
onMainEvent(
|
||||||
MainEvent.OnChangeKeepScreenOn(
|
MainEvent.OnChangeKeepScreenOn(
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,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.screens.settings.components.SettingsSubcategory
|
import ua.acclorite.book_story.presentation.screens.settings.components.SettingsSubcategory
|
||||||
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.HideBarsOnFastScrollSetting
|
||||||
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.settings.KeepScreenOnSetting
|
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.components.settings.KeepScreenOnSetting
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,5 +41,9 @@ fun LazyListScope.MiscSubcategory(
|
||||||
item {
|
item {
|
||||||
KeepScreenOnSetting()
|
KeepScreenOnSetting()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
HideBarsOnFastScrollSetting()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -242,7 +242,7 @@
|
||||||
<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">Тримати екран увімкненим</string>
|
||||||
<string name="keep_screen_on_option_desc">Тримати екран увімкненим нескінченно</string>
|
<string name="hide_bars_on_fast_scroll_option">Ховати панелі при швидкому прокручуванні</string>
|
||||||
|
|
||||||
<!-- Browse -->
|
<!-- Browse -->
|
||||||
<string name="browse_files_structure_option">Структура файлів</string>
|
<string name="browse_files_structure_option">Структура файлів</string>
|
||||||
|
|
|
||||||
|
|
@ -259,7 +259,7 @@
|
||||||
<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">Keep screen on</string>
|
||||||
<string name="keep_screen_on_option_desc">Keep screen awake infinitely</string>
|
<string name="hide_bars_on_fast_scroll_option">Hide bars on fast scroll</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