Skip to content

Commit

Permalink
Add subtitles font size and background switch
Browse files Browse the repository at this point in the history
Added five font sizes to choose from (XLarge, Large, Normal, Small, XSmall)
Added an option to disable the subtitles black background and the shadow color was changed to black from transparent, that adds slight shadow to the text which is much needed for when the black background is disabled, but not really visible when enabled.
  • Loading branch information
siankatabg committed Dec 21, 2021
1 parent b21a222 commit d7569da
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
* Enable series thumbnails in home screen rows
*/
var seriesThumbnailsEnabled = Preference.boolean("pref_enable_series_thumbnails", true)

/**
* Enable subtitles background
*/
var subtitlesBackgroundEnabled = Preference.boolean("pref_enable_subtitles_background", true)

/**
* Set default subtitles font size
*/
var defaultSubtitlesSize = Preference.enum("pref_subtitles_size", SubtitlesSize.SUBS_SIZE_NORMAL)
}

init {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jellyfin.androidtv.preference.constant

import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions

enum class SubtitlesSize {
/**
* Sets the subtitles size to huge.
*/
@EnumDisplayOptions(R.string.subs_size_xlarge)
SUBS_SIZE_XLARGE,

/**
* Sets the subtitles size to big.
*/
@EnumDisplayOptions(R.string.subs_size_large)
SUBS_SIZE_LARGE,

/**
* Sets the subtitles size to normal.
*/
@EnumDisplayOptions(R.string.subs_size_normal)
SUBS_SIZE_NORMAL,

/**
* Sets the subtitles size to small.
*/
@EnumDisplayOptions(R.string.subs_size_small)
SUBS_SIZE_SMALL,

/**
* Sets the subtitles size to xsmall.
*/
@EnumDisplayOptions(R.string.subs_size_xsmall)
SUBS_SIZE_XSMALL
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.jellyfin.androidtv.R;
import org.jellyfin.androidtv.TvApp;
import org.jellyfin.androidtv.constant.CustomMessage;
import org.jellyfin.androidtv.preference.UserPreferences;
import org.jellyfin.androidtv.preference.constant.SubtitlesSize;
import org.jellyfin.androidtv.data.model.DataRefreshService;
import org.jellyfin.androidtv.databinding.OverlayTvGuideBinding;
import org.jellyfin.androidtv.databinding.VlcPlayerInterfaceBinding;
Expand Down Expand Up @@ -255,9 +257,29 @@ public void onActivityCreated(Bundle savedInstanceState) {

//manual subtitles
// This configuration is required for the PaddedLineBackgroundSpan to work
binding.subtitlesText.setShadowLayer(SUBTITLE_PADDING, 0, 0, Color.TRANSPARENT);
binding.subtitlesText.setShadowLayer(SUBTITLE_PADDING, 0, 0, Color.BLACK);
binding.subtitlesText.setPadding(SUBTITLE_PADDING, 0, SUBTITLE_PADDING, 0);

// Subtitles font size configuration
SubtitlesSize subtitlesSize = KoinJavaComponent.<UserPreferences>get(UserPreferences.class).get(UserPreferences.Companion.getDefaultSubtitlesSize());
switch (subtitlesSize) {
case SUBS_SIZE_XLARGE:
binding.subtitlesText.setTextSize(36);
break;
case SUBS_SIZE_LARGE:
binding.subtitlesText.setTextSize(32);
break;
case SUBS_SIZE_NORMAL:
binding.subtitlesText.setTextSize(28);
break;
case SUBS_SIZE_SMALL:
binding.subtitlesText.setTextSize(24);
break;
case SUBS_SIZE_XSMALL:
binding.subtitlesText.setTextSize(20);
break;
}

//pre-load animations
fadeOut = AnimationUtils.loadAnimation(requireContext(), R.anim.abc_fade_out);
fadeOut.setAnimationListener(hideAnimationListener);
Expand Down Expand Up @@ -1461,6 +1483,10 @@ private void renderSubtitles(@Nullable final String text) {
clearSubtitles();
return;
}

// Subtitles background switch
boolean subtitlesBackgroundEnabled = KoinJavaComponent.<UserPreferences>get(UserPreferences.class).get(UserPreferences.Companion.getSubtitlesBackgroundEnabled());

requireActivity().runOnUiThread(() -> {
// Encode whitespace as html entities
final String htmlText = text
Expand All @@ -1469,7 +1495,7 @@ private void renderSubtitles(@Nullable final String text) {

final SpannableString span = new SpannableString(TextUtilsKt.toHtmlSpanned(htmlText));
span.setSpan(new ForegroundColorSpan(Color.WHITE), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new PaddedLineBackgroundSpan(ContextCompat.getColor(requireContext(), R.color.black_opaque), SUBTITLE_PADDING), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new PaddedLineBackgroundSpan(ContextCompat.getColor(requireContext(), subtitlesBackgroundEnabled ? R.color.black_opaque : R.color.transparent), SUBTITLE_PADDING), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

binding.subtitlesText.setText(span);
binding.subtitlesText.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jellyfin.androidtv.preference.UserPreferences
import org.jellyfin.androidtv.preference.constant.AudioBehavior
import org.jellyfin.androidtv.preference.constant.NextUpBehavior
import org.jellyfin.androidtv.preference.constant.PreferredVideoPlayer
import org.jellyfin.androidtv.preference.constant.SubtitlesSize
import org.jellyfin.androidtv.ui.preference.custom.DurationSeekBarPreference
import org.jellyfin.androidtv.ui.preference.dsl.*
import org.jellyfin.androidtv.util.DeviceUtils
Expand Down Expand Up @@ -148,4 +149,15 @@ fun OptionsScreen.playbackCategory(
}
depends { userPreferences[UserPreferences.videoPlayer] == PreferredVideoPlayer.EXTERNAL }
}

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

enum<SubtitlesSize> {
setTitle(R.string.pref_subtitles_size)
bind(userPreferences, UserPreferences.defaultSubtitlesSize)
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,12 @@
<string name="home_section_i">Home section %1$d</string>
<string name="searchable_hint">Search Jellyfin</string>
<string name="searchable_settings_description">Media</string>
<string name="pref_subtitles_background_title">Subtitles background</string>
<string name="pref_subtitles_background_summary">Show a black background behind the subtitles</string>
<string name="subs_size_xlarge">XLarge</string>
<string name="subs_size_large">Lanrge</string>
<string name="subs_size_normal">Normal</string>
<string name="subs_size_small">Small</string>
<string name="subs_size_xsmall">XSmall</string>
<string name="pref_subtitles_size">Subtitles font size</string>
</resources>

0 comments on commit d7569da

Please sign in to comment.