🚀 Chapter's Title Alignment option
This commit is contained in:
parent
e93eeea497
commit
18f42afba1
14 changed files with 87 additions and 4 deletions
|
|
@ -47,6 +47,7 @@ object DataStoreConstants {
|
||||||
val BOTTOM_BAR_PADDING = intPreferencesKey("bottom_bar_padding")
|
val BOTTOM_BAR_PADDING = intPreferencesKey("bottom_bar_padding")
|
||||||
val HIGHLIGHTED_READING = booleanPreferencesKey("highlighted_reading")
|
val HIGHLIGHTED_READING = booleanPreferencesKey("highlighted_reading")
|
||||||
val HIGHLIGHTED_READING_THICKNESS = intPreferencesKey("highlighted_reading_thickness")
|
val HIGHLIGHTED_READING_THICKNESS = intPreferencesKey("highlighted_reading_thickness")
|
||||||
|
val CHAPTER_TITLE_ALIGNMENT = stringPreferencesKey("chapter_title_alignment")
|
||||||
|
|
||||||
// Browse settings
|
// Browse settings
|
||||||
val BROWSE_FILES_STRUCTURE = stringPreferencesKey("browse_files_structure")
|
val BROWSE_FILES_STRUCTURE = stringPreferencesKey("browse_files_structure")
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ fun ReaderContent(
|
||||||
fontFamily: FontWithName,
|
fontFamily: FontWithName,
|
||||||
lineHeight: TextUnit,
|
lineHeight: TextUnit,
|
||||||
fontStyle: FontStyle,
|
fontStyle: FontStyle,
|
||||||
|
chapterTitleAlignment: ReaderTextAlignment,
|
||||||
textAlignment: ReaderTextAlignment,
|
textAlignment: ReaderTextAlignment,
|
||||||
horizontalAlignment: Alignment.Horizontal,
|
horizontalAlignment: Alignment.Horizontal,
|
||||||
fontSize: TextUnit,
|
fontSize: TextUnit,
|
||||||
|
|
@ -122,6 +123,7 @@ fun ReaderContent(
|
||||||
fontFamily = fontFamily,
|
fontFamily = fontFamily,
|
||||||
lineHeight = lineHeight,
|
lineHeight = lineHeight,
|
||||||
fontStyle = fontStyle,
|
fontStyle = fontStyle,
|
||||||
|
chapterTitleAlignment = chapterTitleAlignment,
|
||||||
textAlignment = textAlignment,
|
textAlignment = textAlignment,
|
||||||
horizontalAlignment = horizontalAlignment,
|
horizontalAlignment = horizontalAlignment,
|
||||||
fontSize = fontSize,
|
fontSize = fontSize,
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ fun ReaderLayout(
|
||||||
fontFamily: FontWithName,
|
fontFamily: FontWithName,
|
||||||
lineHeight: TextUnit,
|
lineHeight: TextUnit,
|
||||||
fontStyle: FontStyle,
|
fontStyle: FontStyle,
|
||||||
|
chapterTitleAlignment: ReaderTextAlignment,
|
||||||
textAlignment: ReaderTextAlignment,
|
textAlignment: ReaderTextAlignment,
|
||||||
horizontalAlignment: Alignment.Horizontal,
|
horizontalAlignment: Alignment.Horizontal,
|
||||||
fontSize: TextUnit,
|
fontSize: TextUnit,
|
||||||
|
|
@ -160,6 +161,7 @@ fun ReaderLayout(
|
||||||
fontColor = fontColor,
|
fontColor = fontColor,
|
||||||
lineHeight = lineHeight,
|
lineHeight = lineHeight,
|
||||||
fontStyle = fontStyle,
|
fontStyle = fontStyle,
|
||||||
|
chapterTitleAlignment = chapterTitleAlignment,
|
||||||
textAlignment = textAlignment,
|
textAlignment = textAlignment,
|
||||||
horizontalAlignment = horizontalAlignment,
|
horizontalAlignment = horizontalAlignment,
|
||||||
fontSize = fontSize,
|
fontSize = fontSize,
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ fun LazyItemScope.ReaderLayoutText(
|
||||||
fontColor: Color,
|
fontColor: Color,
|
||||||
lineHeight: TextUnit,
|
lineHeight: TextUnit,
|
||||||
fontStyle: FontStyle,
|
fontStyle: FontStyle,
|
||||||
|
chapterTitleAlignment: ReaderTextAlignment,
|
||||||
textAlignment: ReaderTextAlignment,
|
textAlignment: ReaderTextAlignment,
|
||||||
horizontalAlignment: Alignment.Horizontal,
|
horizontalAlignment: Alignment.Horizontal,
|
||||||
fontSize: TextUnit,
|
fontSize: TextUnit,
|
||||||
|
|
@ -48,6 +49,7 @@ fun LazyItemScope.ReaderLayoutText(
|
||||||
is ReaderText.Chapter -> {
|
is ReaderText.Chapter -> {
|
||||||
ReaderLayoutTextChapter(
|
ReaderLayoutTextChapter(
|
||||||
chapter = textEntry,
|
chapter = textEntry,
|
||||||
|
chapterTitleAlignment = chapterTitleAlignment,
|
||||||
fontColor = fontColor,
|
fontColor = fontColor,
|
||||||
sidePadding = sidePadding,
|
sidePadding = sidePadding,
|
||||||
highlightedReading = highlightedReading,
|
highlightedReading = highlightedReading,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package ua.acclorite.book_story.presentation.reader
|
package ua.acclorite.book_story.presentation.reader
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
|
@ -16,11 +17,13 @@ import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import ua.acclorite.book_story.domain.reader.ReaderText.Chapter
|
import ua.acclorite.book_story.domain.reader.ReaderText.Chapter
|
||||||
|
import ua.acclorite.book_story.domain.reader.ReaderTextAlignment
|
||||||
import ua.acclorite.book_story.presentation.core.components.common.HighlightedText
|
import ua.acclorite.book_story.presentation.core.components.common.HighlightedText
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ReaderLayoutTextChapter(
|
fun ReaderLayoutTextChapter(
|
||||||
chapter: Chapter,
|
chapter: Chapter,
|
||||||
|
chapterTitleAlignment: ReaderTextAlignment,
|
||||||
fontColor: Color,
|
fontColor: Color,
|
||||||
sidePadding: Dp,
|
sidePadding: Dp,
|
||||||
highlightedReading: Boolean,
|
highlightedReading: Boolean,
|
||||||
|
|
@ -34,16 +37,22 @@ fun ReaderLayoutTextChapter(
|
||||||
},
|
},
|
||||||
highlightThickness = highlightedReadingThickness,
|
highlightThickness = highlightedReadingThickness,
|
||||||
style = MaterialTheme.typography.headlineMedium.copy(
|
style = MaterialTheme.typography.headlineMedium.copy(
|
||||||
color = fontColor
|
color = fontColor,
|
||||||
|
textAlign = chapterTitleAlignment.textAlignment
|
||||||
),
|
),
|
||||||
modifier = Modifier.padding(horizontal = sidePadding)
|
modifier = Modifier
|
||||||
|
.padding(horizontal = sidePadding)
|
||||||
|
.fillMaxWidth()
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Text(
|
Text(
|
||||||
text = chapter.title,
|
text = chapter.title,
|
||||||
|
textAlign = chapterTitleAlignment.textAlignment,
|
||||||
style = MaterialTheme.typography.headlineMedium,
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
color = fontColor,
|
color = fontColor,
|
||||||
modifier = Modifier.padding(horizontal = sidePadding)
|
modifier = Modifier
|
||||||
|
.padding(horizontal = sidePadding)
|
||||||
|
.fillMaxWidth()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ fun ReaderScaffold(
|
||||||
fontFamily: FontWithName,
|
fontFamily: FontWithName,
|
||||||
lineHeight: TextUnit,
|
lineHeight: TextUnit,
|
||||||
fontStyle: FontStyle,
|
fontStyle: FontStyle,
|
||||||
|
chapterTitleAlignment: ReaderTextAlignment,
|
||||||
textAlignment: ReaderTextAlignment,
|
textAlignment: ReaderTextAlignment,
|
||||||
horizontalAlignment: Alignment.Horizontal,
|
horizontalAlignment: Alignment.Horizontal,
|
||||||
fontSize: TextUnit,
|
fontSize: TextUnit,
|
||||||
|
|
@ -153,6 +154,7 @@ fun ReaderScaffold(
|
||||||
fontFamily = fontFamily,
|
fontFamily = fontFamily,
|
||||||
lineHeight = lineHeight,
|
lineHeight = lineHeight,
|
||||||
fontStyle = fontStyle,
|
fontStyle = fontStyle,
|
||||||
|
chapterTitleAlignment = chapterTitleAlignment,
|
||||||
textAlignment = textAlignment,
|
textAlignment = textAlignment,
|
||||||
horizontalAlignment = horizontalAlignment,
|
horizontalAlignment = horizontalAlignment,
|
||||||
fontSize = fontSize,
|
fontSize = fontSize,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import ua.acclorite.book_story.R
|
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.text.components.ChapterTitleAlignmentOption
|
||||||
import ua.acclorite.book_story.presentation.settings.reader.text.components.LineHeightOption
|
import ua.acclorite.book_story.presentation.settings.reader.text.components.LineHeightOption
|
||||||
import ua.acclorite.book_story.presentation.settings.reader.text.components.ParagraphHeightOption
|
import ua.acclorite.book_story.presentation.settings.reader.text.components.ParagraphHeightOption
|
||||||
import ua.acclorite.book_story.presentation.settings.reader.text.components.ParagraphIndentationOption
|
import ua.acclorite.book_story.presentation.settings.reader.text.components.ParagraphIndentationOption
|
||||||
|
|
@ -30,6 +31,10 @@ fun LazyListScope.TextSubcategory(
|
||||||
TextAlignmentOption()
|
TextAlignmentOption()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
ChapterTitleAlignmentOption()
|
||||||
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
LineHeightOption()
|
LineHeightOption()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package ua.acclorite.book_story.presentation.settings.reader.text.components
|
||||||
|
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
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.ReaderTextAlignment
|
||||||
|
import ua.acclorite.book_story.domain.ui.ButtonItem
|
||||||
|
import ua.acclorite.book_story.presentation.core.components.settings.SegmentedButtonWithTitle
|
||||||
|
import ua.acclorite.book_story.ui.main.MainEvent
|
||||||
|
import ua.acclorite.book_story.ui.main.MainModel
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ChapterTitleAlignmentOption() {
|
||||||
|
val mainModel = hiltViewModel<MainModel>()
|
||||||
|
val state = mainModel.state.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
|
SegmentedButtonWithTitle(
|
||||||
|
title = stringResource(id = R.string.chapter_title_alignment_option),
|
||||||
|
buttons = ReaderTextAlignment.entries.map {
|
||||||
|
ButtonItem(
|
||||||
|
id = it.toString(),
|
||||||
|
title = when (it) {
|
||||||
|
ReaderTextAlignment.START -> stringResource(id = R.string.text_alignment_start)
|
||||||
|
ReaderTextAlignment.JUSTIFY -> stringResource(id = R.string.text_alignment_justify)
|
||||||
|
ReaderTextAlignment.CENTER -> stringResource(id = R.string.text_alignment_center)
|
||||||
|
ReaderTextAlignment.END -> stringResource(id = R.string.text_alignment_end)
|
||||||
|
},
|
||||||
|
textStyle = MaterialTheme.typography.labelLarge,
|
||||||
|
selected = it == state.value.chapterTitleAlignment
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
mainModel.onEvent(
|
||||||
|
MainEvent.OnChangeChapterTitleAlignment(
|
||||||
|
it.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -49,4 +49,5 @@ sealed class MainEvent {
|
||||||
data class OnChangeBottomBarPadding(val value: Int) : MainEvent()
|
data class OnChangeBottomBarPadding(val value: Int) : MainEvent()
|
||||||
data class OnChangeHighlightedReading(val value: Boolean) : MainEvent()
|
data class OnChangeHighlightedReading(val value: Boolean) : MainEvent()
|
||||||
data class OnChangeHighlightedReadingThickness(val value: Int) : MainEvent()
|
data class OnChangeHighlightedReadingThickness(val value: Int) : MainEvent()
|
||||||
|
data class OnChangeChapterTitleAlignment(val value: String) : MainEvent()
|
||||||
}
|
}
|
||||||
|
|
@ -414,6 +414,14 @@ class MainModel @Inject constructor(
|
||||||
it.copy(highlightedReadingThickness = this)
|
it.copy(highlightedReadingThickness = this)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
is MainEvent.OnChangeChapterTitleAlignment -> handleDatastoreUpdate(
|
||||||
|
key = DataStoreConstants.CHAPTER_TITLE_ALIGNMENT,
|
||||||
|
value = event.value,
|
||||||
|
updateState = {
|
||||||
|
it.copy(chapterTitleAlignment = toTextAlignment())
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ data class MainState(
|
||||||
val verticalPadding: Int = provideDefaultValue { 0 },
|
val verticalPadding: Int = provideDefaultValue { 0 },
|
||||||
val doubleClickTranslation: Boolean = provideDefaultValue { false },
|
val doubleClickTranslation: Boolean = provideDefaultValue { false },
|
||||||
val fastColorPresetChange: Boolean = provideDefaultValue { true },
|
val fastColorPresetChange: Boolean = provideDefaultValue { true },
|
||||||
val textAlignment: ReaderTextAlignment = provideDefaultValue { ReaderTextAlignment.START },
|
val textAlignment: ReaderTextAlignment = provideDefaultValue { ReaderTextAlignment.JUSTIFY },
|
||||||
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 },
|
||||||
|
|
@ -92,6 +92,7 @@ data class MainState(
|
||||||
val bottomBarPadding: Int = provideDefaultValue { 0 },
|
val bottomBarPadding: Int = provideDefaultValue { 0 },
|
||||||
val highlightedReading: Boolean = provideDefaultValue { false },
|
val highlightedReading: Boolean = provideDefaultValue { false },
|
||||||
val highlightedReadingThickness: Int = provideDefaultValue { 2 },
|
val highlightedReadingThickness: Int = provideDefaultValue { 2 },
|
||||||
|
val chapterTitleAlignment: ReaderTextAlignment = provideDefaultValue { ReaderTextAlignment.JUSTIFY },
|
||||||
|
|
||||||
// Browse Settings
|
// Browse Settings
|
||||||
val browseFilesStructure: BrowseFilesStructure = provideDefaultValue {
|
val browseFilesStructure: BrowseFilesStructure = provideDefaultValue {
|
||||||
|
|
@ -305,6 +306,10 @@ data class MainState(
|
||||||
highlightedReadingThickness = provideValue(
|
highlightedReadingThickness = provideValue(
|
||||||
HIGHLIGHTED_READING_THICKNESS
|
HIGHLIGHTED_READING_THICKNESS
|
||||||
) { highlightedReadingThickness },
|
) { highlightedReadingThickness },
|
||||||
|
|
||||||
|
chapterTitleAlignment = provideValue(
|
||||||
|
CHAPTER_TITLE_ALIGNMENT, convert = { toTextAlignment() }
|
||||||
|
) { chapterTitleAlignment },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -340,6 +340,7 @@ data class ReaderScreen(val bookId: Int) : Screen, Parcelable {
|
||||||
fontFamily = fontFamily,
|
fontFamily = fontFamily,
|
||||||
lineHeight = lineHeight,
|
lineHeight = lineHeight,
|
||||||
fontStyle = fontStyle,
|
fontStyle = fontStyle,
|
||||||
|
chapterTitleAlignment = mainState.value.chapterTitleAlignment,
|
||||||
textAlignment = mainState.value.textAlignment,
|
textAlignment = mainState.value.textAlignment,
|
||||||
horizontalAlignment = horizontalAlignment,
|
horizontalAlignment = horizontalAlignment,
|
||||||
fontSize = mainState.value.fontSize.sp,
|
fontSize = mainState.value.fontSize.sp,
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@
|
||||||
<string name="fast_color_preset_change_option">Швидка зміна пресета кольорів</string>
|
<string name="fast_color_preset_change_option">Швидка зміна пресета кольорів</string>
|
||||||
<string name="fast_color_preset_change_option_desc">Проведіть верхню панель вліво або вправо, щоб змінити пресет кольорів</string>
|
<string name="fast_color_preset_change_option_desc">Проведіть верхню панель вліво або вправо, щоб змінити пресет кольорів</string>
|
||||||
<string name="text_alignment_option">Розташування текста</string>
|
<string name="text_alignment_option">Розташування текста</string>
|
||||||
|
<string name="chapter_title_alignment_option">Розташування заголовка розділу</string>
|
||||||
<string name="letter_spacing_option">Відстань між літерами</string>
|
<string name="letter_spacing_option">Відстань між літерами</string>
|
||||||
<string name="cutout_padding_option">Поле вирізу</string>
|
<string name="cutout_padding_option">Поле вирізу</string>
|
||||||
<string name="cutout_padding_option_desc">Додайте поле до області вирізу</string>
|
<string name="cutout_padding_option_desc">Додайте поле до області вирізу</string>
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@
|
||||||
<string name="fast_color_preset_change_option">Fast color preset change</string>
|
<string name="fast_color_preset_change_option">Fast color preset change</string>
|
||||||
<string name="fast_color_preset_change_option_desc">Swipe top bar left or right to change color preset</string>
|
<string name="fast_color_preset_change_option_desc">Swipe top bar left or right to change color preset</string>
|
||||||
<string name="text_alignment_option">Text alignment</string>
|
<string name="text_alignment_option">Text alignment</string>
|
||||||
|
<string name="chapter_title_alignment_option">Chapter\'s title alignment</string>
|
||||||
<string name="letter_spacing_option">Letter spacing</string>
|
<string name="letter_spacing_option">Letter spacing</string>
|
||||||
<string name="cutout_padding_option">Cutout margin</string>
|
<string name="cutout_padding_option">Cutout margin</string>
|
||||||
<string name="cutout_padding_option_desc">Apply margin to the cutout area</string>
|
<string name="cutout_padding_option_desc">Apply margin to the cutout area</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue