🚀 Horizontal gesture sensitivity option
* Additional option for Horizontal gesture (#127) - Sensitivity
This commit is contained in:
parent
efadc85d76
commit
96e0068150
13 changed files with 74 additions and 4 deletions
|
|
@ -45,6 +45,7 @@ object DataStoreConstants {
|
||||||
val SCREEN_BRIGHTNESS = doublePreferencesKey("screen_brightness")
|
val SCREEN_BRIGHTNESS = doublePreferencesKey("screen_brightness")
|
||||||
val HORIZONTAL_GESTURE = stringPreferencesKey("horizontal_gesture")
|
val HORIZONTAL_GESTURE = stringPreferencesKey("horizontal_gesture")
|
||||||
val HORIZONTAL_GESTURE_SCROLL = doublePreferencesKey("horizontal_gesture_scroll")
|
val HORIZONTAL_GESTURE_SCROLL = doublePreferencesKey("horizontal_gesture_scroll")
|
||||||
|
val HORIZONTAL_GESTURE_SENSITIVITY = doublePreferencesKey("horizontal_gesture_sensitivity")
|
||||||
val BOTTOM_BAR_PADDING = intPreferencesKey("bottom_bar_padding")
|
val BOTTOM_BAR_PADDING = intPreferencesKey("bottom_bar_padding")
|
||||||
|
|
||||||
// Browse settings
|
// Browse settings
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ fun ReaderContent(
|
||||||
verticalPadding: Dp,
|
verticalPadding: Dp,
|
||||||
horizontalGesture: ReaderHorizontalGesture,
|
horizontalGesture: ReaderHorizontalGesture,
|
||||||
horizontalGestureScroll: Float,
|
horizontalGestureScroll: Float,
|
||||||
|
horizontalGestureSensitivity: Dp,
|
||||||
paragraphHeight: Dp,
|
paragraphHeight: Dp,
|
||||||
sidePadding: Dp,
|
sidePadding: Dp,
|
||||||
bottomBarPadding: Dp,
|
bottomBarPadding: Dp,
|
||||||
|
|
@ -123,6 +124,7 @@ fun ReaderContent(
|
||||||
verticalPadding = verticalPadding,
|
verticalPadding = verticalPadding,
|
||||||
horizontalGesture = horizontalGesture,
|
horizontalGesture = horizontalGesture,
|
||||||
horizontalGestureScroll = horizontalGestureScroll,
|
horizontalGestureScroll = horizontalGestureScroll,
|
||||||
|
horizontalGestureSensitivity = horizontalGestureSensitivity,
|
||||||
paragraphHeight = paragraphHeight,
|
paragraphHeight = paragraphHeight,
|
||||||
sidePadding = sidePadding,
|
sidePadding = sidePadding,
|
||||||
bottomBarPadding = bottomBarPadding,
|
bottomBarPadding = bottomBarPadding,
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ import androidx.compose.ui.draw.alpha
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.layout.onGloballyPositioned
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.IntOffset
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import ua.acclorite.book_story.domain.reader.ReaderHorizontalGesture
|
import ua.acclorite.book_story.domain.reader.ReaderHorizontalGesture
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
@ -27,10 +27,12 @@ fun Modifier.readerHorizontalGesture(
|
||||||
listState: LazyListState,
|
listState: LazyListState,
|
||||||
horizontalGesture: ReaderHorizontalGesture,
|
horizontalGesture: ReaderHorizontalGesture,
|
||||||
horizontalGestureScroll: Float,
|
horizontalGestureScroll: Float,
|
||||||
|
horizontalGestureSensitivity: Dp,
|
||||||
isLoading: Boolean
|
isLoading: Boolean
|
||||||
): Modifier {
|
): Modifier {
|
||||||
if (horizontalGesture == ReaderHorizontalGesture.OFF || isLoading) return this
|
if (horizontalGesture == ReaderHorizontalGesture.OFF || isLoading) return this
|
||||||
val inverted = rememberUpdatedState(horizontalGesture == ReaderHorizontalGesture.INVERSE)
|
val inverted = rememberUpdatedState(horizontalGesture == ReaderHorizontalGesture.INVERSE)
|
||||||
|
val sensitivity = rememberUpdatedState(horizontalGestureSensitivity)
|
||||||
|
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
|
|
@ -61,7 +63,7 @@ fun Modifier.readerHorizontalGesture(
|
||||||
@Composable
|
@Composable
|
||||||
fun calculateAlpha(): Float {
|
fun calculateAlpha(): Float {
|
||||||
return animateFloatAsState(
|
return animateFloatAsState(
|
||||||
1f - (abs(with(density) { horizontalOffset.floatValue.toDp() }.value) / 16f)
|
1f - (abs(with(density) { horizontalOffset.floatValue.toDp() }.value) / sensitivity.value.value)
|
||||||
).value
|
).value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,12 +93,12 @@ fun Modifier.readerHorizontalGesture(
|
||||||
val horizontalOffsetDp = with(density) { horizontalOffset.floatValue.toDp() }
|
val horizontalOffsetDp = with(density) { horizontalOffset.floatValue.toDp() }
|
||||||
|
|
||||||
when {
|
when {
|
||||||
horizontalOffsetDp > 16.dp -> {
|
horizontalOffsetDp > sensitivity.value -> {
|
||||||
if (inverted.value) scrollForward()
|
if (inverted.value) scrollForward()
|
||||||
else scrollBackward()
|
else scrollBackward()
|
||||||
}
|
}
|
||||||
|
|
||||||
horizontalOffsetDp < (-16).dp -> {
|
horizontalOffsetDp < -sensitivity.value -> {
|
||||||
if (inverted.value) scrollBackward()
|
if (inverted.value) scrollBackward()
|
||||||
else scrollForward()
|
else scrollForward()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ fun ReaderLayout(
|
||||||
verticalPadding: Dp,
|
verticalPadding: Dp,
|
||||||
horizontalGesture: ReaderHorizontalGesture,
|
horizontalGesture: ReaderHorizontalGesture,
|
||||||
horizontalGestureScroll: Float,
|
horizontalGestureScroll: Float,
|
||||||
|
horizontalGestureSensitivity: Dp,
|
||||||
paragraphHeight: Dp,
|
paragraphHeight: Dp,
|
||||||
sidePadding: Dp,
|
sidePadding: Dp,
|
||||||
backgroundColor: Color,
|
backgroundColor: Color,
|
||||||
|
|
@ -132,6 +133,7 @@ fun ReaderLayout(
|
||||||
listState = listState,
|
listState = listState,
|
||||||
horizontalGesture = horizontalGesture,
|
horizontalGesture = horizontalGesture,
|
||||||
horizontalGestureScroll = horizontalGestureScroll,
|
horizontalGestureScroll = horizontalGestureScroll,
|
||||||
|
horizontalGestureSensitivity = horizontalGestureSensitivity,
|
||||||
isLoading = isLoading
|
isLoading = isLoading
|
||||||
),
|
),
|
||||||
verticalArrangement = Arrangement.spacedBy(paragraphHeight),
|
verticalArrangement = Arrangement.spacedBy(paragraphHeight),
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ fun ReaderScaffold(
|
||||||
verticalPadding: Dp,
|
verticalPadding: Dp,
|
||||||
horizontalGesture: ReaderHorizontalGesture,
|
horizontalGesture: ReaderHorizontalGesture,
|
||||||
horizontalGestureScroll: Float,
|
horizontalGestureScroll: Float,
|
||||||
|
horizontalGestureSensitivity: Dp,
|
||||||
paragraphHeight: Dp,
|
paragraphHeight: Dp,
|
||||||
sidePadding: Dp,
|
sidePadding: Dp,
|
||||||
bottomBarPadding: Dp,
|
bottomBarPadding: Dp,
|
||||||
|
|
@ -149,6 +150,7 @@ fun ReaderScaffold(
|
||||||
verticalPadding = verticalPadding,
|
verticalPadding = verticalPadding,
|
||||||
horizontalGesture = horizontalGesture,
|
horizontalGesture = horizontalGesture,
|
||||||
horizontalGestureScroll = horizontalGestureScroll,
|
horizontalGestureScroll = horizontalGestureScroll,
|
||||||
|
horizontalGestureSensitivity = horizontalGestureSensitivity,
|
||||||
paragraphHeight = paragraphHeight,
|
paragraphHeight = paragraphHeight,
|
||||||
sidePadding = sidePadding,
|
sidePadding = sidePadding,
|
||||||
backgroundColor = backgroundColor,
|
backgroundColor = backgroundColor,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import ua.acclorite.book_story.R
|
||||||
import ua.acclorite.book_story.presentation.settings.components.SettingsSubcategory
|
import ua.acclorite.book_story.presentation.settings.components.SettingsSubcategory
|
||||||
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGestureOption
|
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGestureOption
|
||||||
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGestureScrollOption
|
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGestureScrollOption
|
||||||
|
import ua.acclorite.book_story.presentation.settings.reader.reading_mode.components.HorizontalGestureSensitivityOption
|
||||||
|
|
||||||
fun LazyListScope.ReadingModeSubcategory(
|
fun LazyListScope.ReadingModeSubcategory(
|
||||||
titleColor: @Composable () -> Color = { MaterialTheme.colorScheme.primary },
|
titleColor: @Composable () -> Color = { MaterialTheme.colorScheme.primary },
|
||||||
|
|
@ -31,5 +32,9 @@ fun LazyListScope.ReadingModeSubcategory(
|
||||||
item {
|
item {
|
||||||
HorizontalGestureScrollOption()
|
HorizontalGestureScrollOption()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
HorizontalGestureSensitivityOption()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package ua.acclorite.book_story.presentation.settings.reader.reading_mode.components
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
import ua.acclorite.book_story.R
|
||||||
|
import ua.acclorite.book_story.domain.reader.ReaderHorizontalGesture
|
||||||
|
import ua.acclorite.book_story.presentation.core.components.settings.SliderWithTitle
|
||||||
|
import ua.acclorite.book_story.ui.main.MainEvent
|
||||||
|
import ua.acclorite.book_story.ui.main.MainModel
|
||||||
|
import ua.acclorite.book_story.ui.theme.ExpandingTransition
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun HorizontalGestureSensitivityOption() {
|
||||||
|
val mainModel = hiltViewModel<MainModel>()
|
||||||
|
val state = mainModel.state.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
|
ExpandingTransition(
|
||||||
|
visible = when (state.value.horizontalGesture) {
|
||||||
|
ReaderHorizontalGesture.OFF -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
SliderWithTitle(
|
||||||
|
value = state.value.horizontalGestureSensitivity to "%",
|
||||||
|
toValue = 100,
|
||||||
|
title = stringResource(id = R.string.horizontal_gesture_sensitivity_option),
|
||||||
|
onValueChange = {
|
||||||
|
mainModel.onEvent(
|
||||||
|
MainEvent.OnChangeHorizontalGestureSensitivity(it)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -47,5 +47,6 @@ sealed class MainEvent {
|
||||||
data class OnChangeScreenBrightness(val value: Float) : MainEvent()
|
data class OnChangeScreenBrightness(val value: Float) : MainEvent()
|
||||||
data class OnChangeHorizontalGesture(val value: String) : MainEvent()
|
data class OnChangeHorizontalGesture(val value: String) : MainEvent()
|
||||||
data class OnChangeHorizontalGestureScroll(val value: Float) : MainEvent()
|
data class OnChangeHorizontalGestureScroll(val value: Float) : MainEvent()
|
||||||
|
data class OnChangeHorizontalGestureSensitivity(val value: Float) : MainEvent()
|
||||||
data class OnChangeBottomBarPadding(val value: Int) : MainEvent()
|
data class OnChangeBottomBarPadding(val value: Int) : MainEvent()
|
||||||
}
|
}
|
||||||
|
|
@ -395,6 +395,14 @@ class MainModel @Inject constructor(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
is MainEvent.OnChangeHorizontalGestureSensitivity -> handleDatastoreUpdate(
|
||||||
|
key = DataStoreConstants.HORIZONTAL_GESTURE_SENSITIVITY,
|
||||||
|
value = event.value.toDouble(),
|
||||||
|
updateState = {
|
||||||
|
it.copy(horizontalGestureSensitivity = this.toFloat())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
is MainEvent.OnChangeBottomBarPadding -> handleDatastoreUpdate(
|
is MainEvent.OnChangeBottomBarPadding -> handleDatastoreUpdate(
|
||||||
key = DataStoreConstants.BOTTOM_BAR_PADDING,
|
key = DataStoreConstants.BOTTOM_BAR_PADDING,
|
||||||
value = event.value,
|
value = event.value,
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ data class MainState(
|
||||||
ReaderHorizontalGesture.OFF
|
ReaderHorizontalGesture.OFF
|
||||||
},
|
},
|
||||||
val horizontalGestureScroll: Float = provideDefaultValue { 0.7f },
|
val horizontalGestureScroll: Float = provideDefaultValue { 0.7f },
|
||||||
|
val horizontalGestureSensitivity: Float = provideDefaultValue { 0.6f },
|
||||||
val bottomBarPadding: Int = provideDefaultValue { 0 },
|
val bottomBarPadding: Int = provideDefaultValue { 0 },
|
||||||
|
|
||||||
// Browse Settings
|
// Browse Settings
|
||||||
|
|
@ -297,6 +298,10 @@ data class MainState(
|
||||||
HORIZONTAL_GESTURE_SCROLL, convert = { toFloat() }
|
HORIZONTAL_GESTURE_SCROLL, convert = { toFloat() }
|
||||||
) { horizontalGestureScroll },
|
) { horizontalGestureScroll },
|
||||||
|
|
||||||
|
horizontalGestureSensitivity = provideValue(
|
||||||
|
HORIZONTAL_GESTURE_SENSITIVITY, convert = { toFloat() }
|
||||||
|
) { horizontalGestureSensitivity },
|
||||||
|
|
||||||
bottomBarPadding = provideValue(
|
bottomBarPadding = provideValue(
|
||||||
BOTTOM_BAR_PADDING
|
BOTTOM_BAR_PADDING
|
||||||
) { bottomBarPadding },
|
) { bottomBarPadding },
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,9 @@ data class ReaderScreen(val bookId: Int) : Screen, Parcelable {
|
||||||
) {
|
) {
|
||||||
(mainState.value.perceptionExpanderThickness * 0.25f).dp
|
(mainState.value.perceptionExpanderThickness * 0.25f).dp
|
||||||
}
|
}
|
||||||
|
val horizontalGestureSensitivity = remember(mainState.value.horizontalGestureSensitivity) {
|
||||||
|
(36f + mainState.value.horizontalGestureSensitivity * (4f - 36f)).dp
|
||||||
|
}
|
||||||
|
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
val layoutDirection = LocalLayoutDirection.current
|
val layoutDirection = LocalLayoutDirection.current
|
||||||
|
|
@ -321,6 +324,7 @@ data class ReaderScreen(val bookId: Int) : Screen, Parcelable {
|
||||||
verticalPadding = verticalPadding,
|
verticalPadding = verticalPadding,
|
||||||
horizontalGesture = mainState.value.horizontalGesture,
|
horizontalGesture = mainState.value.horizontalGesture,
|
||||||
horizontalGestureScroll = mainState.value.horizontalGestureScroll,
|
horizontalGestureScroll = mainState.value.horizontalGestureScroll,
|
||||||
|
horizontalGestureSensitivity = horizontalGestureSensitivity,
|
||||||
paragraphHeight = paragraphHeight,
|
paragraphHeight = paragraphHeight,
|
||||||
sidePadding = sidePadding,
|
sidePadding = sidePadding,
|
||||||
bottomBarPadding = bottomBarPadding,
|
bottomBarPadding = bottomBarPadding,
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,7 @@
|
||||||
<string name="screen_brightness_option">Яскравість</string>
|
<string name="screen_brightness_option">Яскравість</string>
|
||||||
<string name="horizontal_gesture_option">Горизонтальний жест</string>
|
<string name="horizontal_gesture_option">Горизонтальний жест</string>
|
||||||
<string name="horizontal_gesture_scroll_option">Частка прокрутки</string>
|
<string name="horizontal_gesture_scroll_option">Частка прокрутки</string>
|
||||||
|
<string name="horizontal_gesture_sensitivity_option">Чутливість</string>
|
||||||
<string name="bottom_bar_padding_option">Відступ нижньої панелі</string>
|
<string name="bottom_bar_padding_option">Відступ нижньої панелі</string>
|
||||||
|
|
||||||
<!-- Browse -->
|
<!-- Browse -->
|
||||||
|
|
|
||||||
|
|
@ -268,6 +268,7 @@
|
||||||
<string name="screen_brightness_option">Brightness</string>
|
<string name="screen_brightness_option">Brightness</string>
|
||||||
<string name="horizontal_gesture_option">Horizontal gesture</string>
|
<string name="horizontal_gesture_option">Horizontal gesture</string>
|
||||||
<string name="horizontal_gesture_scroll_option">Scroll fraction</string>
|
<string name="horizontal_gesture_scroll_option">Scroll fraction</string>
|
||||||
|
<string name="horizontal_gesture_sensitivity_option">Sensitivity</string>
|
||||||
<string name="bottom_bar_padding_option">Bottom bar margin</string>
|
<string name="bottom_bar_padding_option">Bottom bar margin</string>
|
||||||
|
|
||||||
<!-- Browse -->
|
<!-- Browse -->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue