-
-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subtitles background opacity #4423
Open
OwOchle
wants to merge
3
commits into
jellyfin:master
Choose a base branch
from
OwOchle:feat/subtitle-opacity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.jellyfin.androidtv.ui.preference.screen | ||
|
||
import okhttp3.internal.toHexString | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't use an internal function from a sub-dependency There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry, I thought it was the kotlin stdlib function |
||
import org.jellyfin.androidtv.R | ||
import org.jellyfin.androidtv.preference.UserPreferences | ||
import org.jellyfin.androidtv.preference.UserSettingPreferences | ||
|
@@ -16,9 +17,12 @@ import org.jellyfin.androidtv.ui.preference.dsl.enum | |
import org.jellyfin.androidtv.ui.preference.dsl.link | ||
import org.jellyfin.androidtv.ui.preference.dsl.optionsScreen | ||
import org.jellyfin.androidtv.ui.preference.dsl.seekbar | ||
import org.jellyfin.androidtv.util.getOpacity | ||
import org.jellyfin.androidtv.util.withOpacity | ||
import org.jellyfin.preference.store.PreferenceStore | ||
import org.jellyfin.sdk.model.api.MediaSegmentType | ||
import org.koin.android.ext.android.inject | ||
import timber.log.Timber | ||
import kotlin.math.roundToInt | ||
|
||
class PlaybackPreferencesScreen : OptionsFragment() { | ||
|
@@ -124,7 +128,54 @@ class PlaybackPreferencesScreen : OptionsFragment() { | |
0xFFD60080L to context.getString(R.string.color_pink), | ||
0xFF009FDAL to context.getString(R.string.color_cyan), | ||
) | ||
bind(userPreferences, UserPreferences.subtitlesBackgroundColor) | ||
|
||
bind { | ||
get { userPreferences[UserPreferences.subtitlesBackgroundColor].let { | ||
if (it == 0x00FFFFFFL) { | ||
it | ||
} else { | ||
it.withOpacity(1f) | ||
} | ||
} | ||
} | ||
set { value -> | ||
userPreferences[UserPreferences.subtitlesBackgroundColor] = if (value == 0x00FFFFFFL) { | ||
value | ||
} else { | ||
value.withOpacity(userPreferences[UserPreferences.subtitlesBackgroundColor].let { if (it == 0x00FFFFFFL) 0xFF000000L else it }) | ||
} | ||
} | ||
default { UserPreferences.subtitlesBackgroundColor.defaultValue } | ||
} | ||
} | ||
|
||
@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.subtitlesBackgroundColor].let { | ||
if (it == 0x00FFFFFFL) { | ||
1.0f | ||
} else { | ||
it.getOpacity() | ||
} | ||
} * 100f).roundToInt() } | ||
set { value -> | ||
userPreferences[UserPreferences.subtitlesBackgroundColor] = userPreferences[UserPreferences.subtitlesBackgroundColor].withOpacity(value / 100f) | ||
} | ||
default { 100 } | ||
} | ||
|
||
depends { | ||
userPreferences[UserPreferences.subtitlesBackgroundColor] != 0x00FFFFFFL | ||
} | ||
} | ||
|
||
colorList { | ||
|
31 changes: 31 additions & 0 deletions
31
app/src/main/java/org/jellyfin/androidtv/util/ColorUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jellyfin.androidtv.util | ||
|
||
import android.util.Log | ||
import okhttp3.internal.toHexString | ||
import timber.log.Timber | ||
import kotlin.math.min | ||
import kotlin.math.roundToLong | ||
|
||
/** | ||
* Adds an opacity to a Long color. | ||
* @param opacity Opacity as a float in range 0..1 | ||
* @return `this` color with opacity | ||
*/ | ||
fun Long.withOpacity(opacity: Float): Long { | ||
if (opacity > 1f) { | ||
throw IllegalArgumentException("Opacity must be lower or equal to 1") | ||
} | ||
|
||
val op = ((opacity * 255f).roundToLong() shl 24) | ||
|
||
return ((this and 0x00FFFFFF) or op) | ||
} | ||
|
||
/** | ||
* Extract opacity from a color and applies it to color `this`. | ||
* @param color Color providing the opacity | ||
* @return `this` with the opacity of `color` | ||
*/ | ||
fun Long.withOpacity(color: Long): Long = this.withOpacity(min(color.getOpacity(), 0.2f)) | ||
|
||
fun Long.getOpacity(): Float = (this shr 24) / 255f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like an unused import?