Skip to content

Commit

Permalink
Use Switches instead of check box for subtitle subtitle_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Jul 27, 2023
1 parent 54921d1 commit 63d4a5f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import eu.kanade.tachiyomi.ui.player.settings.PlayerSettingsScreenModel
import `is`.xyz.mpv.MPVLib
import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.getAndSet
import tachiyomi.presentation.core.components.CheckboxItem
import tachiyomi.presentation.core.components.material.ReadItemAlpha
import tachiyomi.presentation.core.components.material.padding
import kotlin.math.floor
Expand All @@ -78,9 +77,9 @@ fun SubtitleSettingsDialog(
TabbedDialog(
onDismissRequest = onDismissRequest,
tabTitles = listOf(
"Delay",
"Style",
"Size & Position",
stringResource(id = R.string.player_subtitle_settings_delay_tab),
stringResource(id = R.string.player_subtitle_settings_style_tab),
stringResource(id = R.string.player_subtitle_settings_size_and_position_tab),
),
) { contentPadding, page ->
Column(
Expand All @@ -102,39 +101,62 @@ fun SubtitleSettingsDialog(
private fun DelayPage(
screenModel: PlayerSettingsScreenModel,
) {
Column {
Column(
modifier = Modifier.padding(horizontal = 24.dp),
) {
val subDelay by remember { mutableStateOf(screenModel.preferences.rememberSubtitlesDelay()) }
val audioDelay by remember { mutableStateOf(screenModel.preferences.rememberAudioDelay()) }

Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = { screenModel.togglePreference { subDelay } }),
) {
Text(text = stringResource(id = R.string.player_subtitle_remember_delay))
Switch(
checked = subDelay.collectAsState().value,
onCheckedChange = { screenModel.togglePreference { subDelay } },
)
}
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = stringResource(id = R.string.player_subtitle_delay), Modifier.width(80.dp))
TrackDelay(
onDelayChanged = {
MPVLib.setPropertyDouble("sub-delay", it)
MPVLib.setPropertyDouble(Tracks.SUBTITLES.mpvProperty, it)
if (screenModel.preferences.rememberSubtitlesDelay().get()) {
screenModel.preferences.subtitlesDelay().set(it.toFloat())
}
},
Tracks.SUBTITLES,
)
}
val subDelay by remember { mutableStateOf(screenModel.preferences.rememberSubtitlesDelay()) }
CheckboxItem(label = "Remember Sub Delay", checked = subDelay.collectAsState().value) {
screenModel.togglePreference { subDelay }
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = { screenModel.togglePreference { audioDelay } }),
) {
Text(text = stringResource(id = R.string.player_audio_remember_delay))
Switch(
checked = audioDelay.collectAsState().value,
onCheckedChange = { screenModel.togglePreference { audioDelay } },
)
}
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = stringResource(id = R.string.player_audio_delay), Modifier.width(80.dp))
TrackDelay(
onDelayChanged = {
MPVLib.setPropertyDouble("audio-delay", it)
MPVLib.setPropertyDouble(Tracks.AUDIO.mpvProperty, it)
if (screenModel.preferences.rememberAudioDelay().get()) {
screenModel.preferences.audioDelay().set(it.toFloat())
}
},
Tracks.AUDIO,
)
}
val audioDelay by remember { mutableStateOf(screenModel.preferences.rememberAudioDelay()) }
CheckboxItem(label = "Remember Audio Delay", checked = audioDelay.collectAsState().value) {
screenModel.togglePreference { audioDelay }
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion i18n/src/main/res/values/strings-aniyomi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,15 @@
<string name="extension_settings">Extension settings</string>
<string name="action_save_screenshot">Save screenshot</string>
<!-- Subtitle settings -->
<string name="player_subtitle_settings_delay_tab">Delay</string>
<string name="player_subtitle_settings_style_tab">Style</string>
<string name="player_subtitle_settings_size_and_position_tab">Size &amp; Position</string>
<string name="player_subtitle_settings">Subtitle settings</string>
<string name="player_override_subtitle_style">Override subtitle style</string>
<string name="player_subtitle_delay">Subtitle Delay</string>
<string name="player_audio_delay">Audio Delay</string>
<string name="player_subtitle_remember_delay">Remember subtitle delay</string>
<string name="player_audio_delay">Audio delay</string>
<string name="player_audio_remember_delay">Remember audio delay</string>
<string name="player_track_delay_text_field">Delay(s)</string>
<string name="player_subtitle_text_color">Text</string>
<string name="player_subtitle_border_color">Border</string>
Expand Down

0 comments on commit 63d4a5f

Please sign in to comment.