🚀 Chapter's Title Alignment option

This commit is contained in:
Acclorite 2025-01-04 21:57:10 +02:00
parent e93eeea497
commit 18f42afba1
14 changed files with 87 additions and 4 deletions

View file

@ -47,6 +47,7 @@ object DataStoreConstants {
val BOTTOM_BAR_PADDING = intPreferencesKey("bottom_bar_padding")
val HIGHLIGHTED_READING = booleanPreferencesKey("highlighted_reading")
val HIGHLIGHTED_READING_THICKNESS = intPreferencesKey("highlighted_reading_thickness")
val CHAPTER_TITLE_ALIGNMENT = stringPreferencesKey("chapter_title_alignment")
// Browse settings
val BROWSE_FILES_STRUCTURE = stringPreferencesKey("browse_files_structure")

View file

@ -58,6 +58,7 @@ fun ReaderContent(
fontFamily: FontWithName,
lineHeight: TextUnit,
fontStyle: FontStyle,
chapterTitleAlignment: ReaderTextAlignment,
textAlignment: ReaderTextAlignment,
horizontalAlignment: Alignment.Horizontal,
fontSize: TextUnit,
@ -122,6 +123,7 @@ fun ReaderContent(
fontFamily = fontFamily,
lineHeight = lineHeight,
fontStyle = fontStyle,
chapterTitleAlignment = chapterTitleAlignment,
textAlignment = textAlignment,
horizontalAlignment = horizontalAlignment,
fontSize = fontSize,

View file

@ -51,6 +51,7 @@ fun ReaderLayout(
fontFamily: FontWithName,
lineHeight: TextUnit,
fontStyle: FontStyle,
chapterTitleAlignment: ReaderTextAlignment,
textAlignment: ReaderTextAlignment,
horizontalAlignment: Alignment.Horizontal,
fontSize: TextUnit,
@ -160,6 +161,7 @@ fun ReaderLayout(
fontColor = fontColor,
lineHeight = lineHeight,
fontStyle = fontStyle,
chapterTitleAlignment = chapterTitleAlignment,
textAlignment = textAlignment,
horizontalAlignment = horizontalAlignment,
fontSize = fontSize,

View file

@ -23,6 +23,7 @@ fun LazyItemScope.ReaderLayoutText(
fontColor: Color,
lineHeight: TextUnit,
fontStyle: FontStyle,
chapterTitleAlignment: ReaderTextAlignment,
textAlignment: ReaderTextAlignment,
horizontalAlignment: Alignment.Horizontal,
fontSize: TextUnit,
@ -48,6 +49,7 @@ fun LazyItemScope.ReaderLayoutText(
is ReaderText.Chapter -> {
ReaderLayoutTextChapter(
chapter = textEntry,
chapterTitleAlignment = chapterTitleAlignment,
fontColor = fontColor,
sidePadding = sidePadding,
highlightedReading = highlightedReading,

View file

@ -1,6 +1,7 @@
package ua.acclorite.book_story.presentation.reader
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
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 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
@Composable
fun ReaderLayoutTextChapter(
chapter: Chapter,
chapterTitleAlignment: ReaderTextAlignment,
fontColor: Color,
sidePadding: Dp,
highlightedReading: Boolean,
@ -34,16 +37,22 @@ fun ReaderLayoutTextChapter(
},
highlightThickness = highlightedReadingThickness,
style = MaterialTheme.typography.headlineMedium.copy(
color = fontColor
color = fontColor,
textAlign = chapterTitleAlignment.textAlignment
),
modifier = Modifier.padding(horizontal = sidePadding)
modifier = Modifier
.padding(horizontal = sidePadding)
.fillMaxWidth()
)
} else {
Text(
text = chapter.title,
textAlign = chapterTitleAlignment.textAlignment,
style = MaterialTheme.typography.headlineMedium,
color = fontColor,
modifier = Modifier.padding(horizontal = sidePadding)
modifier = Modifier
.padding(horizontal = sidePadding)
.fillMaxWidth()
)
}
Spacer(modifier = Modifier.height(16.dp))

View file

@ -62,6 +62,7 @@ fun ReaderScaffold(
fontFamily: FontWithName,
lineHeight: TextUnit,
fontStyle: FontStyle,
chapterTitleAlignment: ReaderTextAlignment,
textAlignment: ReaderTextAlignment,
horizontalAlignment: Alignment.Horizontal,
fontSize: TextUnit,
@ -153,6 +154,7 @@ fun ReaderScaffold(
fontFamily = fontFamily,
lineHeight = lineHeight,
fontStyle = fontStyle,
chapterTitleAlignment = chapterTitleAlignment,
textAlignment = textAlignment,
horizontalAlignment = horizontalAlignment,
fontSize = fontSize,

View file

@ -9,6 +9,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import ua.acclorite.book_story.R
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.ParagraphHeightOption
import ua.acclorite.book_story.presentation.settings.reader.text.components.ParagraphIndentationOption
@ -30,6 +31,10 @@ fun LazyListScope.TextSubcategory(
TextAlignmentOption()
}
item {
ChapterTitleAlignmentOption()
}
item {
LineHeightOption()
}

View file

@ -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
)
)
}
)
}

View file

@ -49,4 +49,5 @@ sealed class MainEvent {
data class OnChangeBottomBarPadding(val value: Int) : MainEvent()
data class OnChangeHighlightedReading(val value: Boolean) : MainEvent()
data class OnChangeHighlightedReadingThickness(val value: Int) : MainEvent()
data class OnChangeChapterTitleAlignment(val value: String) : MainEvent()
}

View file

@ -414,6 +414,14 @@ class MainModel @Inject constructor(
it.copy(highlightedReadingThickness = this)
}
)
is MainEvent.OnChangeChapterTitleAlignment -> handleDatastoreUpdate(
key = DataStoreConstants.CHAPTER_TITLE_ALIGNMENT,
value = event.value,
updateState = {
it.copy(chapterTitleAlignment = toTextAlignment())
}
)
}
}

View file

@ -70,7 +70,7 @@ data class MainState(
val verticalPadding: Int = provideDefaultValue { 0 },
val doubleClickTranslation: Boolean = provideDefaultValue { false },
val fastColorPresetChange: Boolean = provideDefaultValue { true },
val textAlignment: ReaderTextAlignment = provideDefaultValue { ReaderTextAlignment.START },
val textAlignment: ReaderTextAlignment = provideDefaultValue { ReaderTextAlignment.JUSTIFY },
val letterSpacing: Int = provideDefaultValue { 0 },
val cutoutPadding: Boolean = provideDefaultValue { false },
val fullscreen: Boolean = provideDefaultValue { true },
@ -92,6 +92,7 @@ data class MainState(
val bottomBarPadding: Int = provideDefaultValue { 0 },
val highlightedReading: Boolean = provideDefaultValue { false },
val highlightedReadingThickness: Int = provideDefaultValue { 2 },
val chapterTitleAlignment: ReaderTextAlignment = provideDefaultValue { ReaderTextAlignment.JUSTIFY },
// Browse Settings
val browseFilesStructure: BrowseFilesStructure = provideDefaultValue {
@ -305,6 +306,10 @@ data class MainState(
highlightedReadingThickness = provideValue(
HIGHLIGHTED_READING_THICKNESS
) { highlightedReadingThickness },
chapterTitleAlignment = provideValue(
CHAPTER_TITLE_ALIGNMENT, convert = { toTextAlignment() }
) { chapterTitleAlignment },
)
}
}

View file

@ -340,6 +340,7 @@ data class ReaderScreen(val bookId: Int) : Screen, Parcelable {
fontFamily = fontFamily,
lineHeight = lineHeight,
fontStyle = fontStyle,
chapterTitleAlignment = mainState.value.chapterTitleAlignment,
textAlignment = mainState.value.textAlignment,
horizontalAlignment = horizontalAlignment,
fontSize = mainState.value.fontSize.sp,

View file

@ -173,6 +173,7 @@
<string name="fast_color_preset_change_option">Швидка зміна пресета кольорів</string>
<string name="fast_color_preset_change_option_desc">Проведіть верхню панель вліво або вправо, щоб змінити пресет кольорів</string>
<string name="text_alignment_option">Розташування текста</string>
<string name="chapter_title_alignment_option">Розташування заголовка розділу</string>
<string name="letter_spacing_option">Відстань між літерами</string>
<string name="cutout_padding_option">Поле вирізу</string>
<string name="cutout_padding_option_desc">Додайте поле до області вирізу</string>

View file

@ -226,6 +226,7 @@
<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="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="cutout_padding_option">Cutout margin</string>
<string name="cutout_padding_option_desc">Apply margin to the cutout area</string>