new: add adjustable subtitle text size in player and preferences UI
This commit is contained in:
+4
@@ -27,6 +27,10 @@ internal class InMemoryPreferencesRepository : PreferencesRepository {
|
||||
subtitleState.update { it.copy(showTranslation = enabled) }
|
||||
}
|
||||
|
||||
override suspend fun setSubtitleTextScale(scale: Float) {
|
||||
subtitleState.update { it.copy(textScale = scale) }
|
||||
}
|
||||
|
||||
override suspend fun setPlaybackSpeed(speed: Float) {
|
||||
playbackState.update { it.copy(speed = speed) }
|
||||
}
|
||||
|
||||
+2
@@ -13,5 +13,7 @@ interface PreferencesRepository {
|
||||
|
||||
suspend fun setShowTranslation(enabled: Boolean)
|
||||
|
||||
suspend fun setSubtitleTextScale(scale: Float)
|
||||
|
||||
suspend fun setPlaybackSpeed(speed: Float)
|
||||
}
|
||||
|
||||
+20
-2
@@ -1,12 +1,30 @@
|
||||
package fr.ajaury.gwenedeg.preferences.model
|
||||
|
||||
/**
|
||||
* User preferences controlling which subtitle lines are displayed on the player.
|
||||
* User preferences controlling the subtitle display on the player.
|
||||
*
|
||||
* @property showTranscription whether the Breton (BZH) transcription line is shown.
|
||||
* @property showTranslation whether the French (FR) translation line is shown.
|
||||
* @property textScale multiplier applied to the subtitle font size (see [TEXT_SCALE_STEPS]).
|
||||
*/
|
||||
data class SubtitlePreferences(
|
||||
val showTranscription: Boolean = true,
|
||||
val showTranslation: Boolean = true,
|
||||
)
|
||||
val textScale: Float = DEFAULT_TEXT_SCALE,
|
||||
) {
|
||||
companion object {
|
||||
const val DEFAULT_TEXT_SCALE = 1f
|
||||
|
||||
/** Allowed text-scale steps: 0.1 increments up to x1, then 0.2 increments up to x2. */
|
||||
val TEXT_SCALE_STEPS: List<Float> =
|
||||
listOf(0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.2f, 1.4f, 1.6f, 1.8f, 2.0f)
|
||||
|
||||
/** The next allowed step above [scale], or the maximum when already at the top. */
|
||||
fun nextTextScale(scale: Float): Float =
|
||||
TEXT_SCALE_STEPS.firstOrNull { it > scale } ?: TEXT_SCALE_STEPS.last()
|
||||
|
||||
/** The previous allowed step below [scale], or the minimum when already at the bottom. */
|
||||
fun previousTextScale(scale: Float): Float =
|
||||
TEXT_SCALE_STEPS.lastOrNull { it < scale } ?: TEXT_SCALE_STEPS.first()
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -32,6 +32,8 @@ internal class DataStorePreferencesRepository(
|
||||
|
||||
override suspend fun setShowTranslation(enabled: Boolean) = edit { it[ShowTranslationKey] = enabled }
|
||||
|
||||
override suspend fun setSubtitleTextScale(scale: Float) = edit { it[SubtitleTextScaleKey] = scale }
|
||||
|
||||
override suspend fun setPlaybackSpeed(speed: Float) = edit { it[PlaybackSpeedKey] = speed }
|
||||
|
||||
private suspend fun edit(transform: (MutablePreferences) -> Unit) {
|
||||
@@ -43,6 +45,7 @@ internal class DataStorePreferencesRepository(
|
||||
return SubtitlePreferences(
|
||||
showTranscription = this[ShowTranscriptionKey] ?: defaults.showTranscription,
|
||||
showTranslation = this[ShowTranslationKey] ?: defaults.showTranslation,
|
||||
textScale = this[SubtitleTextScaleKey] ?: defaults.textScale,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,6 +57,7 @@ internal class DataStorePreferencesRepository(
|
||||
private companion object {
|
||||
val ShowTranscriptionKey = booleanPreferencesKey("show_transcription")
|
||||
val ShowTranslationKey = booleanPreferencesKey("show_translation")
|
||||
val SubtitleTextScaleKey = floatPreferencesKey("subtitle_text_scale")
|
||||
val PlaybackSpeedKey = floatPreferencesKey("playback_speed")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user