mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Add setting for subtitle outline size (#375)
Adds a settings allowing for adjusting the thickness of unstyled subtitle outlines, if outline is enabled. This is applied for both ExoPlayer & MPV Closes #179  Dev note: the ExoPlayer implementation is bad code, don't write code like this. It works though
This commit is contained in:
parent
a197f6911b
commit
ac10517028
9 changed files with 116 additions and 0 deletions
|
|
@ -73,12 +73,14 @@ import com.github.damontecres.wholphin.ui.components.ErrorMessage
|
|||
import com.github.damontecres.wholphin.ui.components.LoadingPage
|
||||
import com.github.damontecres.wholphin.ui.nav.Destination
|
||||
import com.github.damontecres.wholphin.ui.preferences.subtitle.SubtitleSettings.applyToMpv
|
||||
import com.github.damontecres.wholphin.ui.preferences.subtitle.SubtitleSettings.calculateEdgeSize
|
||||
import com.github.damontecres.wholphin.ui.preferences.subtitle.SubtitleSettings.toSubtitleStyle
|
||||
import com.github.damontecres.wholphin.ui.seasonEpisode
|
||||
import com.github.damontecres.wholphin.ui.skipStringRes
|
||||
import com.github.damontecres.wholphin.ui.tryRequestFocus
|
||||
import com.github.damontecres.wholphin.util.ExceptionHandler
|
||||
import com.github.damontecres.wholphin.util.LoadingState
|
||||
import com.github.damontecres.wholphin.util.Media3SubtitleOverride
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -329,6 +331,10 @@ fun PlaybackPage(
|
|||
},
|
||||
update = {
|
||||
it.setCues(cues)
|
||||
Media3SubtitleOverride(
|
||||
preferences.appPreferences.interfacePreferences.subtitlesPreferences
|
||||
.calculateEdgeSize(density),
|
||||
).apply(it)
|
||||
},
|
||||
onReset = {
|
||||
it.setCues(null)
|
||||
|
|
|
|||
|
|
@ -140,6 +140,23 @@ object SubtitleSettings {
|
|||
},
|
||||
)
|
||||
|
||||
val EdgeThickness =
|
||||
AppSliderPreference<AppPreferences>(
|
||||
title = R.string.edge_size,
|
||||
defaultValue = 4,
|
||||
min = 1,
|
||||
max = 32,
|
||||
interval = 1,
|
||||
getter = {
|
||||
it.interfacePreferences.subtitlesPreferences.edgeThickness
|
||||
.toLong()
|
||||
},
|
||||
setter = { prefs, value ->
|
||||
prefs.updateSubtitlePreferences { edgeThickness = value.toInt() }
|
||||
},
|
||||
summarizer = { value -> value?.let { "${it / 2.0}" } },
|
||||
)
|
||||
|
||||
val BackgroundColor =
|
||||
AppChoicePreference<AppPreferences, Color>(
|
||||
title = R.string.background_color,
|
||||
|
|
@ -230,6 +247,7 @@ object SubtitleSettings {
|
|||
listOf(
|
||||
EdgeStylePref,
|
||||
EdgeColor,
|
||||
EdgeThickness,
|
||||
),
|
||||
),
|
||||
PreferenceGroup(
|
||||
|
|
@ -278,6 +296,8 @@ object SubtitleSettings {
|
|||
)
|
||||
}
|
||||
|
||||
fun SubtitlePreferences.calculateEdgeSize(density: Density): Float = with(density) { (edgeThickness / 2f).dp.toPx() }
|
||||
|
||||
fun SubtitlePreferences.applyToMpv(
|
||||
configuration: Configuration,
|
||||
density: Density,
|
||||
|
|
@ -316,6 +336,8 @@ object SubtitleSettings {
|
|||
MPVLib.setPropertyDouble("sub-outline-size", 0.0)
|
||||
}
|
||||
}
|
||||
val outlineSizePx = calculateEdgeSize(density) * .8
|
||||
MPVLib.setPropertyDouble("sub-outline-size", outlineSizePx)
|
||||
|
||||
// if (fontBold) {
|
||||
// MPVLib.setPropertyString("sub-font", "Roboto Bold")
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import androidx.compose.runtime.setValue
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
|
|
@ -32,7 +33,9 @@ import com.github.damontecres.wholphin.preferences.AppPreferences
|
|||
import com.github.damontecres.wholphin.ui.preferences.PreferenceScreenOption
|
||||
import com.github.damontecres.wholphin.ui.preferences.PreferencesContent
|
||||
import com.github.damontecres.wholphin.ui.preferences.PreferencesViewModel
|
||||
import com.github.damontecres.wholphin.ui.preferences.subtitle.SubtitleSettings.calculateEdgeSize
|
||||
import com.github.damontecres.wholphin.ui.preferences.subtitle.SubtitleSettings.toSubtitleStyle
|
||||
import com.github.damontecres.wholphin.util.Media3SubtitleOverride
|
||||
|
||||
@OptIn(UnstableApi::class)
|
||||
@Composable
|
||||
|
|
@ -41,6 +44,7 @@ fun SubtitleStylePage(
|
|||
modifier: Modifier = Modifier,
|
||||
viewModel: PreferencesViewModel = hiltViewModel(),
|
||||
) {
|
||||
val density = LocalDensity.current
|
||||
var preferences by remember { mutableStateOf(initialPreferences) }
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.preferenceDataStore.data.collect {
|
||||
|
|
@ -95,6 +99,7 @@ fun SubtitleStylePage(
|
|||
Cue.Builder().setText(text).build(),
|
||||
),
|
||||
)
|
||||
Media3SubtitleOverride(prefs.calculateEdgeSize(density)).apply(it)
|
||||
},
|
||||
modifier =
|
||||
Modifier
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue