From f60375a110d78453a8d00ac8d0df7dd199a259ea Mon Sep 17 00:00:00 2001
From: RafaRamos <40279132+RafaelsRamos@users.noreply.github.com>
Date: Thu, 21 Dec 2023 18:33:38 +0100
Subject: [PATCH] feat: add "Rich caption rendering" setting (#5371)
---
.../java/com/github/libretube/constants/PreferenceKeys.kt | 1 +
.../main/java/com/github/libretube/helpers/PlayerHelper.kt | 6 ++++++
.../com/github/libretube/ui/views/CustomExoPlayerView.kt | 2 +-
app/src/main/res/values/strings.xml | 2 ++
app/src/main/res/xml/player_settings.xml | 7 +++++++
5 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt
index 7afa7804e..576664c3c 100644
--- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt
+++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt
@@ -71,6 +71,7 @@ object PreferenceKeys {
const val SEARCH_HISTORY_TOGGLE = "search_history_toggle"
const val SYSTEM_CAPTION_STYLE = "system_caption_style"
const val CAPTION_SETTINGS = "caption_settings"
+ const val RICH_CAPTION_RENDERING = "rich_caption_rendering"
const val SEEK_INCREMENT = "seek_increment"
const val DEFAULT_RESOLUTION = "default_res"
const val DEFAULT_RESOLUTION_MOBILE = "default_res_mobile"
diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt
index 49215f71d..d717a6fdc 100644
--- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt
+++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt
@@ -165,6 +165,12 @@ object PlayerHelper {
true
)
+ val useRichCaptionRendering: Boolean
+ get() = PreferenceHelper.getBoolean(
+ PreferenceKeys.RICH_CAPTION_RENDERING,
+ false
+ )
+
private val bufferingGoal: Int
get() = PreferenceHelper.getString(
PreferenceKeys.BUFFERING_GOAL,
diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt
index 4511e0f74..24f3bf591 100644
--- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt
+++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt
@@ -605,8 +605,8 @@ open class CustomExoPlayerView(
val captionStyle = PlayerHelper.getCaptionStyle(context)
subtitleView?.apply {
setApplyEmbeddedFontSizes(false)
- setViewType(SubtitleView.VIEW_TYPE_WEB)
setFixedTextSize(Cue.TEXT_SIZE_TYPE_ABSOLUTE, PlayerHelper.captionsTextSize)
+ if (PlayerHelper.useRichCaptionRendering) setViewType(SubtitleView.VIEW_TYPE_WEB)
if (!PlayerHelper.useSystemCaptionStyle) return
setApplyEmbeddedStyles(captionStyle == CaptionStyleCompat.DEFAULT)
setStyle(captionStyle)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b7fd1fd5a..9e4e603d6 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -223,6 +223,8 @@
Remembered playback positions
Reset
System caption style
+ Rich caption rendering
+ Render web captions for a more rich and customized experience.
Captions
None
General
diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml
index 30ebd0026..b65ddceb2 100644
--- a/app/src/main/res/xml/player_settings.xml
+++ b/app/src/main/res/xml/player_settings.xml
@@ -123,6 +123,13 @@
app:key="caption_settings"
app:title="@string/caption_settings" />
+
+