🚀 Change Paragraph Indentation to Slider

* Changed "Paragraph indentation" option in Reader to use Slider
* In range from 0pt to 10pt (1pt = " ")
This commit is contained in:
Acclorite 2024-09-08 21:57:03 +03:00
parent 0496004cc4
commit cf8632c48b
7 changed files with 28 additions and 21 deletions

View file

@ -27,7 +27,7 @@ object DataStoreConstants {
val FONT_SIZE = intPreferencesKey("font_size")
val LINE_HEIGHT = intPreferencesKey("line_height")
val PARAGRAPH_HEIGHT = intPreferencesKey("paragraph_height")
val PARAGRAPH_INDENTATION = booleanPreferencesKey("paragraph_indentation")
val PARAGRAPH_INDENTATION = intPreferencesKey("paragraph_indentation_int")
val TEXT_ALIGNMENT = stringPreferencesKey("text_alignment")
val LETTER_SPACING = intPreferencesKey("letter_spacing")
val CUTOUT_PADDING = booleanPreferencesKey("cutout_padding")

View file

@ -14,7 +14,7 @@ sealed class MainEvent {
data class OnChangeFontSize(val fontSize: Int) : MainEvent()
data class OnChangeLineHeight(val lineHeight: Int) : MainEvent()
data class OnChangeParagraphHeight(val paragraphHeight: Int) : MainEvent()
data class OnChangeParagraphIndentation(val bool: Boolean) : MainEvent()
data class OnChangeParagraphIndentation(val indentation: Int) : MainEvent()
data class OnChangeShowStartScreen(val bool: Boolean) : MainEvent()
data class OnChangeCheckForUpdates(val bool: Boolean) : MainEvent()
data class OnChangeSidePadding(val sidePadding: Int) : MainEvent()

View file

@ -63,7 +63,7 @@ data class MainState(
val fontSize: Int = provideDefaultValue { 16 },
val lineHeight: Int = provideDefaultValue { 4 },
val paragraphHeight: Int = provideDefaultValue { 8 },
val paragraphIndentation: Boolean = provideDefaultValue { false },
val paragraphIndentation: Int = provideDefaultValue { 0 },
val sidePadding: Int = provideDefaultValue { 6 },
val verticalPadding: Int = provideDefaultValue { 0 },
val doubleClickTranslation: Boolean = provideDefaultValue { false },

View file

@ -169,10 +169,10 @@ class MainViewModel @Inject constructor(
is MainEvent.OnChangeParagraphIndentation -> {
viewModelScope.launch(Dispatchers.IO) {
setDatastore.execute(DataStoreConstants.PARAGRAPH_INDENTATION, event.bool)
setDatastore.execute(DataStoreConstants.PARAGRAPH_INDENTATION, event.indentation)
updateStateWithSavedHandle {
it.copy(
paragraphIndentation = event.bool
paragraphIndentation = event.indentation
)
}
}

View file

@ -247,6 +247,13 @@ private fun ReaderScreen(lazyListState: LazyListState) {
false -> FontStyle.Normal
}
}
val paragraphIndentation = remember(mainState.value.paragraphIndentation) {
var indentation = ""
repeat(mainState.value.paragraphIndentation) {
indentation += " "
}
indentation
}
val density = LocalDensity.current
val layoutDirection = LocalLayoutDirection.current
@ -457,7 +464,7 @@ private fun ReaderScreen(lazyListState: LazyListState) {
fontSize = mainState.value.fontSize.sp,
letterSpacing = letterSpacing,
sidePadding = sidePadding,
paragraphIndentation = mainState.value.paragraphIndentation,
paragraphIndentation = paragraphIndentation,
fullscreenMode = mainState.value.fullscreen,
doubleClickTranslationEnabled = mainState.value.doubleClickTranslation,
toolbarHidden = toolbarHidden

View file

@ -41,7 +41,7 @@ import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.
* @param fontSize Line's font size.
* @param letterSpacing Letter spacing.
* @param sidePadding Line's side padding.
* @param paragraphIndentation Whether Paragraph Indentation is enabled for this line.
* @param paragraphIndentation Paragraph Indentation for this line.
* @param fullscreenMode Whether Reader is in fullscreen mode.
* @param doubleClickTranslationEnabled Whether Double Click Translation is enabled.
* @param toolbarHidden Whether selection toolBar is hidden.
@ -59,7 +59,7 @@ fun LazyItemScope.ReaderTextParagraph(
fontSize: TextUnit,
letterSpacing: TextUnit,
sidePadding: Dp,
paragraphIndentation: Boolean,
paragraphIndentation: String,
fullscreenMode: Boolean,
doubleClickTranslationEnabled: Boolean,
toolbarHidden: Boolean
@ -82,10 +82,7 @@ fun LazyItemScope.ReaderTextParagraph(
) {
BasicText(
text = buildAnnotatedString {
if (paragraphIndentation) {
append(" ")
}
append(paragraphIndentation)
append(line)
},
modifier = Modifier.then(

View file

@ -5,7 +5,7 @@ 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
import ua.acclorite.book_story.presentation.screens.settings.components.SliderWithTitle
/**
* Paragraph Indentation setting.
@ -16,12 +16,15 @@ fun ParagraphIndentationSetting() {
val state = LocalMainViewModel.current.state
val onMainEvent = LocalMainViewModel.current.onEvent
SwitchWithTitle(
selected = state.value.paragraphIndentation,
title = stringResource(id = R.string.paragraph_indentation_option)
) {
SliderWithTitle(
value = state.value.paragraphIndentation to "pt",
fromValue = 0,
toValue = 10,
title = stringResource(id = R.string.paragraph_indentation_option),
onValueChange = {
onMainEvent(
MainEvent.OnChangeParagraphIndentation(!state.value.paragraphIndentation)
MainEvent.OnChangeParagraphIndentation(it)
)
}
)
}