Skip to content

Commit

Permalink
Add new subtitle customization preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Aug 5, 2024
1 parent be06693 commit e8a8179
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.jellyfin.androidtv.preference.constant.RefreshRateSwitchingBehavior
import org.jellyfin.androidtv.preference.constant.WatchedIndicatorBehavior
import org.jellyfin.preference.booleanPreference
import org.jellyfin.preference.enumPreference
import org.jellyfin.preference.floatPreference
import org.jellyfin.preference.intPreference
import org.jellyfin.preference.longPreference
import org.jellyfin.preference.store.SharedPreferenceStore
Expand Down Expand Up @@ -156,29 +157,24 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
var seriesThumbnailsEnabled = booleanPreference("pref_enable_series_thumbnails", true)

/**
* Enable subtitles background
*/
var subtitlesBackgroundEnabled = booleanPreference("subtitles_background_enabled", true)

/**
* Subtitles font size
* Subtitles foreground color
*/
var subtitlesSize = intPreference("subtitles_size", 28)
var subtitlesBackgroundColor = longPreference("subtitles_background_color", 0x00FFFFFF)

/**
* Subtitles stroke size
* Subtitles foreground color
*/
var subtitleStrokeSize = intPreference("subtitles_stroke_size", 0)
var subtitlesTextColor = longPreference("subtitles_text_color", 0xFFFFFFFF)

/**
* Subtitles position
* Subtitles stroke color
*/
var subtitlePosition = intPreference("subtitles_position", 40)
var subtitleTextStrokeColor = longPreference("subtitles_text_stroke_color", 0xFF000000)

/**
* Subtitles foreground color
* Subtitles font size
*/
var subtitlesTextColor = longPreference("subtitles_text_color", 0xFFFFFFFF)
var subtitlesTextSize = floatPreference("subtitles_text_size", 1f)

/**
* Show screensaver in app
Expand Down Expand Up @@ -216,6 +212,17 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
// Enable playback rewrite for music
putBoolean("playback_new_audio", true)
}

// v0.17.z to v0.18.0
migration(toVersion = 8) {
// Set subtitle background color to black if it was enabled in a previous version
val subtitlesBackgroundEnabled = it.getBoolean("subtitles_background_enabled", true)
putLong("subtitles_background_color", if (subtitlesBackgroundEnabled) 0XFF000000L else 0X00FFFFFFL)

// Set subtitle text stroke color to black if it was enabled in a previous version
val subtitleStrokeSize = it.getInt("subtitles_stroke_size", 0)
putLong("subtitles_text_stroke_color", if (subtitleStrokeSize > 0) 0XFF000000L else 0X00FFFFFFL)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.media.audiofx.DynamicsProcessing;
import android.media.audiofx.DynamicsProcessing.Limiter;
import android.media.audiofx.Equalizer;
Expand Down Expand Up @@ -35,6 +36,7 @@
import androidx.media3.extractor.DefaultExtractorsFactory;
import androidx.media3.extractor.ts.TsExtractor;
import androidx.media3.ui.AspectRatioFrameLayout;
import androidx.media3.ui.CaptionStyleCompat;
import androidx.media3.ui.PlayerView;

import org.jellyfin.androidtv.R;
Expand Down Expand Up @@ -74,7 +76,8 @@ public class VideoManager {
public VideoManager(@NonNull Activity activity, @NonNull View view, @NonNull PlaybackOverlayFragmentHelper helper) {
mActivity = activity;
_helper = helper;
nightModeEnabled = KoinJavaComponent.<UserPreferences>get(UserPreferences.class).get(UserPreferences.Companion.getAudioNightMode());
UserPreferences userPreferences = KoinJavaComponent.<UserPreferences>get(UserPreferences.class);
nightModeEnabled = userPreferences.get(UserPreferences.Companion.getAudioNightMode());

mExoPlayer = configureExoplayerBuilder(activity).build();

Expand All @@ -83,6 +86,17 @@ public VideoManager(@NonNull Activity activity, @NonNull View view, @NonNull Pla

mExoPlayerView = view.findViewById(R.id.exoPlayerView);
mExoPlayerView.setPlayer(mExoPlayer);
int strokeColor = userPreferences.get(UserPreferences.Companion.getSubtitleTextStrokeColor()).intValue();
CaptionStyleCompat subtitleStyle = new CaptionStyleCompat(
userPreferences.get(UserPreferences.Companion.getSubtitlesTextColor()).intValue(),
userPreferences.get(UserPreferences.Companion.getSubtitlesBackgroundColor()).intValue(),
Color.TRANSPARENT,
Color.alpha(strokeColor) == 0 ? CaptionStyleCompat.EDGE_TYPE_NONE : CaptionStyleCompat.EDGE_TYPE_OUTLINE,
strokeColor,
null
);
mExoPlayerView.getSubtitleView().setFractionalTextSize(0.0533f * userPreferences.get(UserPreferences.Companion.getSubtitlesTextSize()));
mExoPlayerView.getSubtitleView().setStyle(subtitleStyle);
mExoPlayer.addListener(new Player.Listener() {
@Override
public void onPlayerError(@NonNull PlaybackException error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.jellyfin.androidtv.ui.preference.dsl.checkbox
import org.jellyfin.androidtv.ui.preference.dsl.colorList
import org.jellyfin.androidtv.ui.preference.dsl.enum
import org.jellyfin.androidtv.ui.preference.dsl.link
import org.jellyfin.androidtv.ui.preference.dsl.list
import org.jellyfin.androidtv.ui.preference.dsl.optionsScreen
import org.jellyfin.androidtv.ui.preference.dsl.seekbar
import org.koin.android.ext.android.inject
Expand Down Expand Up @@ -69,53 +70,73 @@ class PlaybackPreferencesScreen : OptionsFragment() {
category {
setTitle(R.string.pref_subtitles)

checkbox {
setTitle(R.string.pref_subtitles_background_title)
setContent(R.string.pref_subtitles_background_summary)
bind(userPreferences, UserPreferences.subtitlesBackgroundEnabled)
}

@Suppress("MagicNumber")
colorList {
setTitle(R.string.lbl_subtitle_fg)
setTitle(R.string.lbl_subtitle_text_color)
entries = mapOf(
0xFFFFFFFF to context.getString(R.string.color_white),
0XFF000000 to context.getString(R.string.color_black),
0xFF7F7F7F to context.getString(R.string.color_darkgrey),
0xFFC80000 to context.getString(R.string.color_red),
0xFF00C800 to context.getString(R.string.color_green),
0xFF0000C8 to context.getString(R.string.color_blue),
0xFFEEDC00 to context.getString(R.string.color_yellow),
0xFFD60080 to context.getString(R.string.color_pink),
0xFF009FDA to context.getString(R.string.color_cyan),
0xFFFFFFFFL to context.getString(R.string.color_white),
0XFF000000L to context.getString(R.string.color_black),
0xFF7F7F7FL to context.getString(R.string.color_darkgrey),
0xFFC80000L to context.getString(R.string.color_red),
0xFF00C800L to context.getString(R.string.color_green),
0xFF0000C8L to context.getString(R.string.color_blue),
0xFFEEDC00L to context.getString(R.string.color_yellow),
0xFFD60080L to context.getString(R.string.color_pink),
0xFF009FDAL to context.getString(R.string.color_cyan),
)
bind(userPreferences, UserPreferences.subtitlesTextColor)
}

@Suppress("MagicNumber")
seekbar {
setTitle(R.string.lbl_subtitle_stroke)
min = 0
max = 24
increment = 2
bind(userPreferences, UserPreferences.subtitleStrokeSize)
colorList {
setTitle(R.string.lbl_subtitle_background_color)
entries = mapOf(
0x00FFFFFFL to context.getString(R.string.lbl_none),
0xFFFFFFFFL to context.getString(R.string.color_white),
0XFF000000L to context.getString(R.string.color_black),
0xFF7F7F7FL to context.getString(R.string.color_darkgrey),
0xFFC80000L to context.getString(R.string.color_red),
0xFF00C800L to context.getString(R.string.color_green),
0xFF0000C8L to context.getString(R.string.color_blue),
0xFFEEDC00L to context.getString(R.string.color_yellow),
0xFFD60080L to context.getString(R.string.color_pink),
0xFF009FDAL to context.getString(R.string.color_cyan),
)
bind(userPreferences, UserPreferences.subtitlesBackgroundColor)
}

@Suppress("MagicNumber")
seekbar {
setTitle(R.string.lbl_subtitle_position)
min = 0
max = 300
increment = 10
bind(userPreferences, UserPreferences.subtitlePosition)
colorList {
setTitle(R.string.lbl_subtitle_text_stroke_color)
entries = mapOf(
0x00FFFFFFL to context.getString(R.string.lbl_none),
0xFFFFFFFFL to context.getString(R.string.color_white),
0XFF000000L to context.getString(R.string.color_black),
0xFF7F7F7FL to context.getString(R.string.color_darkgrey),
0xFFC80000L to context.getString(R.string.color_red),
0xFF00C800L to context.getString(R.string.color_green),
0xFF0000C8L to context.getString(R.string.color_blue),
0xFFEEDC00L to context.getString(R.string.color_yellow),
0xFFD60080L to context.getString(R.string.color_pink),
0xFF009FDAL to context.getString(R.string.color_cyan),
)
bind(userPreferences, UserPreferences.subtitleTextStrokeColor)
}

@Suppress("MagicNumber")
seekbar {
list {
setTitle(R.string.pref_subtitles_size)
min = 10
max = 38
bind(userPreferences, UserPreferences.subtitlesSize)
entries = mapOf(
0.25f to context.getString(R.string.pref_subtitles_size_very_small),
0.5f to context.getString(R.string.pref_subtitles_size_small),
1.0f to context.getString(R.string.pref_subtitles_size_normal),
1.5f to context.getString(R.string.pref_subtitles_size_large),
2.0f to context.getString(R.string.pref_subtitles_size_very_large),
).mapKeys { it.key.toString() }

bind {
get { userPreferences[UserPreferences.subtitlesTextSize].toString() }
set { value -> userPreferences[UserPreferences.subtitlesTextSize] = value.toFloat() }
default { UserPreferences.subtitlesTextSize.defaultValue.toString() }
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,14 @@
<string name="lbl_guide_option_played">Last played</string>
<string name="lbl_guide_option_number">Channel number</string>
<string name="lbl_resume_preroll">Resume pre-roll</string>
<string name="lbl_subtitle_fg">Subtitle text color</string>
<string name="lbl_subtitle_stroke">Subtitle stroke size</string>
<string name="lbl_subtitle_position">Subtitle offset from bottom</string>
<string name="lbl_subtitle_text_color">Subtitle text color</string>
<string name="lbl_subtitle_background_color">Subtitle background color</string>
<string name="lbl_subtitle_text_stroke_color">Subtitle stroke color</string>
<string name="pref_subtitles_size_very_small">Very small</string>
<string name="pref_subtitles_size_small">Small</string>
<string name="pref_subtitles_size_normal">Normal</string>
<string name="pref_subtitles_size_large">Large</string>
<string name="pref_subtitles_size_very_large">Very large</string>
<string name="lbl_resume_from">Resume from %1$s</string>
<string name="lbl_more_like_this">More like this</string>
<string name="lbl_previous_episode">Previous episode</string>
Expand Down

0 comments on commit e8a8179

Please sign in to comment.