Add ability to style subtitles (#177)

Adds settings for styling text subtitles such as srt/subrip

## Issues
Closes #11
This commit is contained in:
damontecres 2025-11-08 19:54:51 -05:00 committed by GitHub
parent 762e8f287d
commit 5720603447
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 529 additions and 11 deletions

View file

@ -666,6 +666,12 @@ sealed interface AppPreference<T> {
summaryOn = R.string.one_click_pause_summary_on,
summaryOff = R.string.disabled,
)
val SubtitleStyle =
AppDestinationPreference(
title = R.string.subtitle_style,
destination = Destination.Settings(PreferenceScreenOption.SUBTITLES),
)
}
}
@ -679,6 +685,7 @@ val basicPreferences =
AppPreference.RewatchNextUp,
AppPreference.PlayThemeMusic,
AppPreference.RememberSelectedTab,
AppPreference.SubtitleStyle,
AppPreference.ThemeColors,
),
),

View file

@ -1,7 +1,9 @@
package com.github.damontecres.wholphin.preferences
import androidx.compose.ui.graphics.toArgb
import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
import com.github.damontecres.wholphin.ui.preferences.subtitle.SubtitleSettings
import com.google.protobuf.InvalidProtocolBufferException
import java.io.InputStream
import java.io.OutputStream
@ -74,6 +76,13 @@ class AppPreferencesSerializer
navDrawerSwitchOnFocus =
AppPreference.NavDrawerSwitchOnFocus.defaultValue
showClock = AppPreference.ShowClock.defaultValue
subtitlesPreferences =
SubtitlePreferences
.newBuilder()
.apply {
resetSubtitles()
}.build()
}.build()
}.build()
@ -112,3 +121,21 @@ inline fun AppPreferences.updateInterfacePreferences(block: InterfacePreferences
update {
interfacePreferences = interfacePreferences.toBuilder().apply(block).build()
}
inline fun AppPreferences.updateSubtitlePreferences(block: SubtitlePreferences.Builder.() -> Unit): AppPreferences =
updateInterfacePreferences {
subtitlesPreferences = subtitlesPreferences.toBuilder().apply(block).build()
}
fun SubtitlePreferences.Builder.resetSubtitles() {
fontSize = SubtitleSettings.FontSize.defaultValue.toInt()
fontColor = SubtitleSettings.FontColor.defaultValue.toArgb()
fontBold = SubtitleSettings.FontBold.defaultValue
fontItalic = SubtitleSettings.FontItalic.defaultValue
fontOpacity = SubtitleSettings.FontOpacity.defaultValue.toInt()
edgeColor = SubtitleSettings.EdgeColor.defaultValue.toArgb()
edgeStyle = SubtitleSettings.EdgeStylePref.defaultValue
backgroundColor = SubtitleSettings.BackgroundColor.defaultValue.toArgb()
backgroundOpacity = SubtitleSettings.BackgroundOpacity.defaultValue.toInt()
backgroundStyle = SubtitleSettings.BackgroundStylePref.defaultValue
}