Skip to content

Commit

Permalink
feat: subtitles position setting
Browse files Browse the repository at this point in the history
closes #49
  • Loading branch information
abdallahmehiz committed Sep 8, 2024
1 parent cd6f469 commit 3bf81bb
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SubtitlesPreferences(preferenceStore: PreferenceStore) {
val backgroundColor = preferenceStore.getInt("sub_color_bg", Color.Transparent.toArgb())

val justification = preferenceStore.getEnum("sub_justify", SubtitleJustification.Auto)
val subPos = preferenceStore.getInt("sub_pos", 100)

val overrideAssSubs = preferenceStore.getBoolean("sub_override_ass")

Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/MPVView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ class MPVView(context: Context, attributes: AttributeSet) : BaseMPVView(context,
)

MPVLib.setOptionString("sub-font", subtitlesPreferences.font.get())
subtitlesPreferences.overrideAssSubs.get().let {
MPVLib.setOptionString("sub-ass-override", if (it) "force" else "no")
MPVLib.setOptionString("sub-ass-justify", if (it) "yes" else "no")
if (subtitlesPreferences.overrideAssSubs.get()) {
MPVLib.setOptionString("sub-ass-override", "force")
MPVLib.setOptionString("sub-ass-justify", "yes")
}
MPVLib.setOptionString("sub-font-size", subtitlesPreferences.fontSize.get().toString())
MPVLib.setOptionString("sub-bold", if (subtitlesPreferences.bold.get()) "yes" else "no")
Expand All @@ -242,5 +242,6 @@ class MPVView(context: Context, attributes: AttributeSet) : BaseMPVView(context,
MPVLib.setOptionString("sub-border-size", subtitlesPreferences.borderSize.get().toString())
MPVLib.setOptionString("sub-border-style", subtitlesPreferences.borderStyle.get().value)
MPVLib.setOptionString("sub-shadow-offset", subtitlesPreferences.shadowOffset.get().toString())
MPVLib.setOptionString("sub-pos", subtitlesPreferences.subPos.get().toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ fun SubtitleSettingsColorsCard(
currentColor = getCurrentMPVColor(currentColorType)
},
) {
Row(horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall)) {
Row(
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall),
verticalAlignment = Alignment.CenterVertically
) {
Icon(Icons.Default.FormatColorReset, null)
Text(stringResource(R.string.generic_reset))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package live.mehiz.mpvkt.ui.player.controls.components.panels
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AlignVerticalCenter
import androidx.compose.material.icons.filled.EditOff
import androidx.compose.material.icons.filled.Tune
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -19,7 +24,9 @@ import androidx.compose.ui.res.stringResource
import `is`.xyz.mpv.MPVLib
import live.mehiz.mpvkt.R
import live.mehiz.mpvkt.preferences.SubtitlesPreferences
import live.mehiz.mpvkt.preferences.preference.deleteAndGet
import live.mehiz.mpvkt.presentation.components.ExpandableCard
import live.mehiz.mpvkt.presentation.components.SliderItem
import live.mehiz.mpvkt.ui.theme.spacing
import me.zhanghai.compose.preference.ProvidePreferenceLocals
import me.zhanghai.compose.preference.SwitchPreference
Expand All @@ -44,17 +51,59 @@ fun SubtitlesMiscellaneousCard(modifier: Modifier = Modifier) {
ProvidePreferenceLocals {
Column {
var overrideAssSubs by remember {
mutableStateOf(MPVLib.getPropertyString("sub-ass-override") == "force")
mutableStateOf(MPVLib.getPropertyString("sub-ass-override").also { println(it) } == "force")
}
SwitchPreference(
overrideAssSubs,
onValueChange = {
overrideAssSubs = it
preferences.overrideAssSubs.set(it)
MPVLib.setPropertyString("sub-ass-override", if (it) "force" else "no")
MPVLib.setPropertyString("sub-ass-override", if (it) "force" else "scale")
},
{ Text(stringResource(R.string.player_sheets_sub_override_ass)) },
)
var subPos by remember {
mutableStateOf(MPVLib.getPropertyInt("sub-pos"))
}
SliderItem(
label = stringResource(R.string.player_sheets_sub_position),
value = subPos,
valueText = subPos.toString(),
onChange = {
subPos = it
preferences.subPos.set(it)
MPVLib.setPropertyInt("sub-pos", it)
},
max = 150,
icon = {
Icon(
Icons.Default.AlignVerticalCenter,
null,
)
}
)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(end = MaterialTheme.spacing.medium, bottom = MaterialTheme.spacing.medium),
horizontalArrangement = Arrangement.End
) {
TextButton(
onClick = {
preferences.subPos.deleteAndGet().let {
subPos = it
MPVLib.setPropertyInt("sub-pos", it)
}
preferences.overrideAssSubs.deleteAndGet().let { overrideAssSubs = it }
MPVLib.setPropertyString("sub-ass-override", "scale") // mpv's default is 'scale'
},
) {
Row {
Icon(Icons.Default.EditOff, null)
Text(stringResource(R.string.generic_reset))
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ fun SubtitleSettingsTypographyCard(
borderSize = MPVLib.getPropertyInt("sub-border-size")
shadowOffset = MPVLib.getPropertyInt("sub-shadow-offset")
}) {
Row(horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall)) {
Row(
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall),
verticalAlignment = Alignment.CenterVertically
) {
Icon(Icons.Default.FormatClear, null)
Text(stringResource(R.string.generic_reset))
}
Expand Down

0 comments on commit 3bf81bb

Please sign in to comment.