🚀 Progress Bar Font Size option

* Changes font size of progress bar's text

Part-of: #148
This commit is contained in:
Acclorite 2025-01-12 22:48:14 +02:00
parent 0c216bcb51
commit 8f9d849e3e
14 changed files with 71 additions and 3 deletions

View file

@ -56,6 +56,7 @@ object DataStoreConstants {
val PROGRESS_BAR = booleanPreferencesKey("progress_bar")
val PROGRESS_BAR_PADDING = intPreferencesKey("progress_bar_padding")
val PROGRESS_BAR_ALIGNMENT = stringPreferencesKey("progress_bar_alignment")
val PROGRESS_BAR_FONT_SIZE = intPreferencesKey("progress_bar_font_size")
// Browse settings
val BROWSE_FILES_STRUCTURE = stringPreferencesKey("browse_files_structure")

View file

@ -56,6 +56,7 @@ fun ReaderContent(
progressBar: Boolean,
progressBarPadding: Dp,
progressBarAlignment: HorizontalAlignment,
progressBarFontSize: TextUnit,
paragraphHeight: Dp,
sidePadding: Dp,
bottomBarPadding: Dp,
@ -130,6 +131,7 @@ fun ReaderContent(
progressBar = progressBar,
progressBarPadding = progressBarPadding,
progressBarAlignment = progressBarAlignment,
progressBarFontSize = progressBarFontSize,
paragraphHeight = paragraphHeight,
sidePadding = sidePadding,
bottomBarPadding = bottomBarPadding,

View file

@ -56,6 +56,7 @@ fun ReaderLayout(
progressBar: Boolean,
progressBarPadding: Dp,
progressBarAlignment: HorizontalAlignment,
progressBarFontSize: TextUnit,
paragraphHeight: Dp,
sidePadding: Dp,
backgroundColor: Color,
@ -223,6 +224,7 @@ fun ReaderLayout(
progress = progress,
progressBarPadding = progressBarPadding,
progressBarAlignment = progressBarAlignment,
progressBarFontSize = progressBarFontSize,
fontColor = fontColor,
sidePadding = sidePadding
)

View file

@ -4,13 +4,13 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.selection.DisableSelection
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import ua.acclorite.book_story.domain.util.HorizontalAlignment
@Composable
@ -18,6 +18,7 @@ fun ReaderProgressBar(
progress: String,
progressBarPadding: Dp,
progressBarAlignment: HorizontalAlignment,
progressBarFontSize: TextUnit,
fontColor: Color,
sidePadding: Dp
) {
@ -32,9 +33,10 @@ fun ReaderProgressBar(
) {
DisableSelection {
Text(
progress,
style = MaterialTheme.typography.bodyLarge,
text = progress,
color = fontColor,
fontSize = progressBarFontSize,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}

View file

@ -60,6 +60,7 @@ fun ReaderScaffold(
progressBar: Boolean,
progressBarPadding: Dp,
progressBarAlignment: HorizontalAlignment,
progressBarFontSize: TextUnit,
paragraphHeight: Dp,
sidePadding: Dp,
bottomBarPadding: Dp,
@ -161,6 +162,7 @@ fun ReaderScaffold(
progressBar = progressBar,
progressBarPadding = progressBarPadding,
progressBarAlignment = progressBarAlignment,
progressBarFontSize = progressBarFontSize,
paragraphHeight = paragraphHeight,
sidePadding = sidePadding,
backgroundColor = backgroundColor,

View file

@ -10,6 +10,7 @@ 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.progress.components.ProgressBarAlignmentOption
import ua.acclorite.book_story.presentation.settings.reader.progress.components.ProgressBarFontSizeOption
import ua.acclorite.book_story.presentation.settings.reader.progress.components.ProgressBarOption
import ua.acclorite.book_story.presentation.settings.reader.progress.components.ProgressBarPaddingOption
@ -29,6 +30,10 @@ fun LazyListScope.ProgressSubcategory(
ProgressBarOption()
}
item {
ProgressBarFontSizeOption()
}
item {
ProgressBarPaddingOption()
}

View file

@ -0,0 +1,31 @@
package ua.acclorite.book_story.presentation.settings.reader.progress.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.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 ProgressBarFontSizeOption() {
val mainModel = hiltViewModel<MainModel>()
val state = mainModel.state.collectAsStateWithLifecycle()
ExpandingTransition(visible = state.value.progressBar) {
SliderWithTitle(
value = state.value.progressBarFontSize to "pt",
fromValue = 4,
toValue = 16,
title = stringResource(id = R.string.progress_bar_font_size_option),
onValueChange = {
mainModel.onEvent(
MainEvent.OnChangeProgressBarFontSize(it)
)
}
)
}
}

View file

@ -17,6 +17,7 @@ fun ProgressBarOption() {
SwitchWithTitle(
selected = state.value.progressBar,
title = stringResource(id = R.string.progress_bar_option),
description = stringResource(id = R.string.progress_bar_option_desc),
onClick = {
mainModel.onEvent(
MainEvent.OnChangeProgressBar(

View file

@ -58,4 +58,5 @@ sealed class MainEvent {
data class OnChangeProgressBar(val value: Boolean) : MainEvent()
data class OnChangeProgressBarPadding(val value: Int) : MainEvent()
data class OnChangeProgressBarAlignment(val value: String) : MainEvent()
data class OnChangeProgressBarFontSize(val value: Int) : MainEvent()
}

View file

@ -488,6 +488,14 @@ class MainModel @Inject constructor(
it.copy(progressBarAlignment = this.toHorizontalAlignment())
}
)
is MainEvent.OnChangeProgressBarFontSize -> handleDatastoreUpdate(
key = DataStoreConstants.PROGRESS_BAR_FONT_SIZE,
value = event.value,
updateState = {
it.copy(progressBarFontSize = this)
}
)
}
}

View file

@ -105,6 +105,7 @@ data class MainState(
val progressBar: Boolean = provideDefaultValue { false },
val progressBarPadding: Int = provideDefaultValue { 4 },
val progressBarAlignment: HorizontalAlignment = provideDefaultValue { HorizontalAlignment.CENTER },
val progressBarFontSize: Int = provideDefaultValue { 8 },
// Browse Settings
val browseFilesStructure: BrowseFilesStructure = provideDefaultValue {
@ -354,6 +355,10 @@ data class MainState(
progressBarAlignment = provideValue(
PROGRESS_BAR_ALIGNMENT, convert = { toHorizontalAlignment() }
) { progressBarAlignment },
progressBarFontSize = provideValue(
PROGRESS_BAR_FONT_SIZE
) { progressBarFontSize },
)
}
}

View file

@ -224,6 +224,9 @@ data class ReaderScreen(val bookId: Int) : Screen, Parcelable {
val progressBarPadding = remember(mainState.value.progressBarPadding) {
(mainState.value.progressBarPadding * 3).dp
}
val progressBarFontSize = remember(mainState.value.progressBarFontSize) {
(mainState.value.progressBarFontSize * 2).sp
}
val layoutDirection = LocalLayoutDirection.current
val cutoutInsets = WindowInsets.displayCutout
@ -396,6 +399,7 @@ data class ReaderScreen(val bookId: Int) : Screen, Parcelable {
progressBar = mainState.value.progressBar,
progressBarPadding = progressBarPadding,
progressBarAlignment = mainState.value.progressBarAlignment,
progressBarFontSize = progressBarFontSize,
paragraphHeight = paragraphHeight,
sidePadding = sidePadding,
bottomBarPadding = bottomBarPadding,

View file

@ -203,8 +203,10 @@
<string name="images_width_option">Розмір</string>
<string name="images_color_effects_option">Ефекти кольору</string>
<string name="progress_bar_option">Панель прогресу</string>
<string name="progress_bar_option_desc">Показувати панель прогресу внизу</string>
<string name="progress_bar_padding_option">Поля</string>
<string name="progress_bar_alignment_option">Розташування</string>
<string name="progress_bar_font_size_option">Розмір шрифта</string>
<!-- Browse -->
<string name="browse_files_structure_option">Структура файлів</string>

View file

@ -260,8 +260,10 @@
<string name="images_width_option">Size</string>
<string name="images_color_effects_option">Color effects</string>
<string name="progress_bar_option">Progress bar</string>
<string name="progress_bar_option_desc">Display progress bar at the bottom</string>
<string name="progress_bar_padding_option">Margins</string>
<string name="progress_bar_alignment_option">Alignment</string>
<string name="progress_bar_font_size_option">Font size</string>
<!-- Browse -->
<string name="browse_files_structure_option">Files structure</string>