🚀 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:
parent
0496004cc4
commit
cf8632c48b
7 changed files with 28 additions and 21 deletions
|
|
@ -27,7 +27,7 @@ object DataStoreConstants {
|
||||||
val FONT_SIZE = intPreferencesKey("font_size")
|
val FONT_SIZE = intPreferencesKey("font_size")
|
||||||
val LINE_HEIGHT = intPreferencesKey("line_height")
|
val LINE_HEIGHT = intPreferencesKey("line_height")
|
||||||
val PARAGRAPH_HEIGHT = intPreferencesKey("paragraph_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 TEXT_ALIGNMENT = stringPreferencesKey("text_alignment")
|
||||||
val LETTER_SPACING = intPreferencesKey("letter_spacing")
|
val LETTER_SPACING = intPreferencesKey("letter_spacing")
|
||||||
val CUTOUT_PADDING = booleanPreferencesKey("cutout_padding")
|
val CUTOUT_PADDING = booleanPreferencesKey("cutout_padding")
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ sealed class MainEvent {
|
||||||
data class OnChangeFontSize(val fontSize: Int) : MainEvent()
|
data class OnChangeFontSize(val fontSize: Int) : MainEvent()
|
||||||
data class OnChangeLineHeight(val lineHeight: Int) : MainEvent()
|
data class OnChangeLineHeight(val lineHeight: Int) : MainEvent()
|
||||||
data class OnChangeParagraphHeight(val paragraphHeight: 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 OnChangeShowStartScreen(val bool: Boolean) : MainEvent()
|
||||||
data class OnChangeCheckForUpdates(val bool: Boolean) : MainEvent()
|
data class OnChangeCheckForUpdates(val bool: Boolean) : MainEvent()
|
||||||
data class OnChangeSidePadding(val sidePadding: Int) : MainEvent()
|
data class OnChangeSidePadding(val sidePadding: Int) : MainEvent()
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ data class MainState(
|
||||||
val fontSize: Int = provideDefaultValue { 16 },
|
val fontSize: Int = provideDefaultValue { 16 },
|
||||||
val lineHeight: Int = provideDefaultValue { 4 },
|
val lineHeight: Int = provideDefaultValue { 4 },
|
||||||
val paragraphHeight: Int = provideDefaultValue { 8 },
|
val paragraphHeight: Int = provideDefaultValue { 8 },
|
||||||
val paragraphIndentation: Boolean = provideDefaultValue { false },
|
val paragraphIndentation: Int = provideDefaultValue { 0 },
|
||||||
val sidePadding: Int = provideDefaultValue { 6 },
|
val sidePadding: Int = provideDefaultValue { 6 },
|
||||||
val verticalPadding: Int = provideDefaultValue { 0 },
|
val verticalPadding: Int = provideDefaultValue { 0 },
|
||||||
val doubleClickTranslation: Boolean = provideDefaultValue { false },
|
val doubleClickTranslation: Boolean = provideDefaultValue { false },
|
||||||
|
|
|
||||||
|
|
@ -169,10 +169,10 @@ class MainViewModel @Inject constructor(
|
||||||
|
|
||||||
is MainEvent.OnChangeParagraphIndentation -> {
|
is MainEvent.OnChangeParagraphIndentation -> {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
setDatastore.execute(DataStoreConstants.PARAGRAPH_INDENTATION, event.bool)
|
setDatastore.execute(DataStoreConstants.PARAGRAPH_INDENTATION, event.indentation)
|
||||||
updateStateWithSavedHandle {
|
updateStateWithSavedHandle {
|
||||||
it.copy(
|
it.copy(
|
||||||
paragraphIndentation = event.bool
|
paragraphIndentation = event.indentation
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -247,6 +247,13 @@ private fun ReaderScreen(lazyListState: LazyListState) {
|
||||||
false -> FontStyle.Normal
|
false -> FontStyle.Normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val paragraphIndentation = remember(mainState.value.paragraphIndentation) {
|
||||||
|
var indentation = ""
|
||||||
|
repeat(mainState.value.paragraphIndentation) {
|
||||||
|
indentation += " "
|
||||||
|
}
|
||||||
|
indentation
|
||||||
|
}
|
||||||
|
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
val layoutDirection = LocalLayoutDirection.current
|
val layoutDirection = LocalLayoutDirection.current
|
||||||
|
|
@ -457,7 +464,7 @@ private fun ReaderScreen(lazyListState: LazyListState) {
|
||||||
fontSize = mainState.value.fontSize.sp,
|
fontSize = mainState.value.fontSize.sp,
|
||||||
letterSpacing = letterSpacing,
|
letterSpacing = letterSpacing,
|
||||||
sidePadding = sidePadding,
|
sidePadding = sidePadding,
|
||||||
paragraphIndentation = mainState.value.paragraphIndentation,
|
paragraphIndentation = paragraphIndentation,
|
||||||
fullscreenMode = mainState.value.fullscreen,
|
fullscreenMode = mainState.value.fullscreen,
|
||||||
doubleClickTranslationEnabled = mainState.value.doubleClickTranslation,
|
doubleClickTranslationEnabled = mainState.value.doubleClickTranslation,
|
||||||
toolbarHidden = toolbarHidden
|
toolbarHidden = toolbarHidden
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.
|
||||||
* @param fontSize Line's font size.
|
* @param fontSize Line's font size.
|
||||||
* @param letterSpacing Letter spacing.
|
* @param letterSpacing Letter spacing.
|
||||||
* @param sidePadding Line's side padding.
|
* @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 fullscreenMode Whether Reader is in fullscreen mode.
|
||||||
* @param doubleClickTranslationEnabled Whether Double Click Translation is enabled.
|
* @param doubleClickTranslationEnabled Whether Double Click Translation is enabled.
|
||||||
* @param toolbarHidden Whether selection toolBar is hidden.
|
* @param toolbarHidden Whether selection toolBar is hidden.
|
||||||
|
|
@ -59,7 +59,7 @@ fun LazyItemScope.ReaderTextParagraph(
|
||||||
fontSize: TextUnit,
|
fontSize: TextUnit,
|
||||||
letterSpacing: TextUnit,
|
letterSpacing: TextUnit,
|
||||||
sidePadding: Dp,
|
sidePadding: Dp,
|
||||||
paragraphIndentation: Boolean,
|
paragraphIndentation: String,
|
||||||
fullscreenMode: Boolean,
|
fullscreenMode: Boolean,
|
||||||
doubleClickTranslationEnabled: Boolean,
|
doubleClickTranslationEnabled: Boolean,
|
||||||
toolbarHidden: Boolean
|
toolbarHidden: Boolean
|
||||||
|
|
@ -82,10 +82,7 @@ fun LazyItemScope.ReaderTextParagraph(
|
||||||
) {
|
) {
|
||||||
BasicText(
|
BasicText(
|
||||||
text = buildAnnotatedString {
|
text = buildAnnotatedString {
|
||||||
if (paragraphIndentation) {
|
append(paragraphIndentation)
|
||||||
append(" ")
|
|
||||||
}
|
|
||||||
|
|
||||||
append(line)
|
append(line)
|
||||||
},
|
},
|
||||||
modifier = Modifier.then(
|
modifier = Modifier.then(
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import androidx.compose.ui.res.stringResource
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
import ua.acclorite.book_story.presentation.core.components.LocalMainViewModel
|
import ua.acclorite.book_story.presentation.core.components.LocalMainViewModel
|
||||||
import ua.acclorite.book_story.presentation.data.MainEvent
|
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.
|
* Paragraph Indentation setting.
|
||||||
|
|
@ -16,12 +16,15 @@ fun ParagraphIndentationSetting() {
|
||||||
val state = LocalMainViewModel.current.state
|
val state = LocalMainViewModel.current.state
|
||||||
val onMainEvent = LocalMainViewModel.current.onEvent
|
val onMainEvent = LocalMainViewModel.current.onEvent
|
||||||
|
|
||||||
SwitchWithTitle(
|
SliderWithTitle(
|
||||||
selected = state.value.paragraphIndentation,
|
value = state.value.paragraphIndentation to "pt",
|
||||||
title = stringResource(id = R.string.paragraph_indentation_option)
|
fromValue = 0,
|
||||||
) {
|
toValue = 10,
|
||||||
onMainEvent(
|
title = stringResource(id = R.string.paragraph_indentation_option),
|
||||||
MainEvent.OnChangeParagraphIndentation(!state.value.paragraphIndentation)
|
onValueChange = {
|
||||||
)
|
onMainEvent(
|
||||||
}
|
MainEvent.OnChangeParagraphIndentation(it)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue