Skip to content

Commit

Permalink
feat: added subtitles background opacity option
Browse files Browse the repository at this point in the history
  • Loading branch information
OwOchle committed Jan 26, 2025
1 parent 5d551f3 commit 34715ca
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
*/
var subtitlesBackgroundColor = longPreference("subtitles_background_color", 0x00FFFFFF)

/**
* Subtitles background opacity
*/
var subtitlesBackgroundOpacity = floatPreference("subtitles_background_opacity", 1f)

/**
* Subtitles foreground color
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.jellyfin.androidtv.data.compat.StreamInfo;
import org.jellyfin.androidtv.preference.UserPreferences;
import org.jellyfin.androidtv.preference.constant.ZoomMode;
import org.jellyfin.androidtv.util.ColorUtilsKt;
import org.jellyfin.sdk.api.client.ApiClient;
import org.jellyfin.sdk.model.api.MediaStream;
import org.jellyfin.sdk.model.api.MediaStreamType;
Expand Down Expand Up @@ -97,7 +98,10 @@ public VideoManager(@NonNull Activity activity, @NonNull View view, @NonNull Pla
int strokeColor = userPreferences.get(UserPreferences.Companion.getSubtitleTextStrokeColor()).intValue();
CaptionStyleCompat subtitleStyle = new CaptionStyleCompat(
userPreferences.get(UserPreferences.Companion.getSubtitlesTextColor()).intValue(),
userPreferences.get(UserPreferences.Companion.getSubtitlesBackgroundColor()).intValue(),
ColorUtilsKt.withOpacity(
userPreferences.get(UserPreferences.Companion.getSubtitlesBackgroundColor()),
userPreferences.get(UserPreferences.Companion.getSubtitlesBackgroundOpacity())
).intValue(),
Color.TRANSPARENT,
Color.alpha(strokeColor) == 0 ? CaptionStyleCompat.EDGE_TYPE_NONE : CaptionStyleCompat.EDGE_TYPE_OUTLINE,
strokeColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ class PlaybackPreferencesScreen : OptionsFragment() {
bind(userPreferences, UserPreferences.subtitlesBackgroundColor)
}

@Suppress("MagicNumber")
seekbar {
setTitle(R.string.pref_subtitles_background_opacity)
min = 20
max = 100
increment = 10
valueFormatter = object : DurationSeekBarPreference.ValueFormatter() {
override fun display(value: Int): String = "$value%"
}

bind {
get { (userPreferences[UserPreferences.subtitlesBackgroundOpacity] * 100f).roundToInt() }
set { value -> userPreferences[UserPreferences.subtitlesBackgroundOpacity] = value / 100f }
default { (UserPreferences.subtitlesBackgroundOpacity.defaultValue * 100f).roundToInt() }
}

depends {
userPreferences[UserPreferences.subtitlesBackgroundColor] != 0x00FFFFFFL
}
}

colorList {
setTitle(R.string.lbl_subtitle_text_stroke_color)
entries = mapOf(
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/org/jellyfin/androidtv/util/ColorUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jellyfin.androidtv.util

import android.util.Log
import okhttp3.internal.toHexString
import timber.log.Timber
import kotlin.math.roundToLong

/**
* Adds an opacity to a Long color.
* Conversion to java.lang.Long is required for usage in VideoManager.java
* @param opacity Opacity as a float in range 0..1
* @return `this` color with opacity
*/
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
fun Long.withOpacity(opacity: Float): java.lang.Long {
if (opacity > 1f) {
throw IllegalArgumentException("Opacity must be lower or equal to 1")
}

val op = ((opacity * 255).roundToLong() shl 24) or 0xFFFFFF

Timber.d((this and op).toHexString())

return (this and op) as java.lang.Long
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
<string name="segment_type_unknown">Unknown segments</string>
<string name="skip_forward_length">Skip forward length</string>
<string name="preference_enable_trickplay">Enable trickplay in video player</string>
<string name="pref_subtitles_background_opacity">Subtitle background opacity</string>
<plurals name="seconds">
<item quantity="one">%1$s second</item>
<item quantity="other">%1$s seconds</item>
Expand Down

0 comments on commit 34715ca

Please sign in to comment.