From d6d4bfaa0ea17a4f4755a05f0124879669cfd498 Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Tue, 12 Apr 2022 20:23:30 +0800 Subject: [PATCH] [Feature] Add setting to Truncate Video title on Player (#918) * [Feature] Add setting to Truncate Video title on Player * add missing icons * Revert "add missing icons" This reverts commit 51c8a85ed18b5664fde21262f5b8ee3ae3a894fb. * applied PR suggestions * edit color --- .../cloudstream3/ui/player/GeneratorPlayer.kt | 21 +++++++++++++++---- .../ui/settings/SettingsFragment.kt | 18 ++++++++++++++++ .../drawable/ic_baseline_text_format_24.xml | 10 +++++++++ app/src/main/res/values/array.xml | 15 +++++++++++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/settings.xml | 4 ++++ 6 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_text_format_24.xml diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index c82d3788..f340f234 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -545,10 +545,14 @@ class GeneratorPlayer : FullScreenPlayer() { tvType = meta.tvType } } - - player_episode_filler_holder?.isVisible = isFiller ?: false - - player_video_title?.text = if (headerName != null) { + //Get limit of characters on Video Title + var limitTitle = 0 + context?.let { + val settingsManager = PreferenceManager.getDefaultSharedPreferences(it) + limitTitle = settingsManager.getInt(getString(R.string.prefer_limit_title_key), 0) + } + //Generate video title + var playerVideoTitle = if (headerName != null) { (headerName + if (tvType.isEpisodeBased() && episode != null) if (season == null) @@ -559,6 +563,15 @@ class GeneratorPlayer : FullScreenPlayer() { } else { "" } + //Truncate video title if it exceeds limit + val differenceInLength = playerVideoTitle.length - limitTitle + val margin = 3 //If the difference is smaller than or equal to this value, ignore it + if (limitTitle > 0 && differenceInLength > margin) { + playerVideoTitle = playerVideoTitle.substring(0, limitTitle-1) + "..." + } + + player_episode_filler_holder?.isVisible = isFiller ?: false + player_video_title?.text = playerVideoTitle } @SuppressLint("SetTextI18n") diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index cb7f1138..90ca1acb 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -705,6 +705,24 @@ class SettingsFragment : PreferenceFragmentCompat() { return@setOnPreferenceClickListener true } + getPref(R.string.prefer_limit_title_key)?.setOnPreferenceClickListener { + val prefNames = resources.getStringArray(R.array.limit_title_pref_names) + val prefValues = resources.getIntArray(R.array.limit_title_pref_values) + val current = settingsManager.getInt(getString(R.string.prefer_limit_title_key), 0) + + activity?.showBottomDialog( + prefNames.toList(), + prefValues.indexOf(current), + getString(R.string.limit_title), + true, + {}) { + settingsManager.edit() + .putInt(getString(R.string.prefer_limit_title_key), prefValues[it]) + .apply() + } + return@setOnPreferenceClickListener true + } + getPref(R.string.dns_key)?.setOnPreferenceClickListener { val prefNames = resources.getStringArray(R.array.dns_pref) val prefValues = resources.getIntArray(R.array.dns_pref_values) diff --git a/app/src/main/res/drawable/ic_baseline_text_format_24.xml b/app/src/main/res/drawable/ic_baseline_text_format_24.xml new file mode 100644 index 00000000..ca03854f --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_text_format_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 8cd09501..e8795592 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -59,6 +59,21 @@ 3 + + @string/none + 16 characters + 32 characters + 64 characters + 128 characters + + + 0 + 16 + 32 + 64 + 128 + + @string/automatic 1min diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eb644776..8d355814 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,6 +13,7 @@ subtitle_settings_key subtitle_settings_chromecast_key quality_pref_key + prefer_limit_title_key video_buffer_size_key video_buffer_length_key video_buffer_clear_key @@ -348,6 +349,7 @@ Don\'t show again Update Preferred watch quality + Limit title characters on player Video buffer size Video buffer length Video cache on disk diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index c73765a6..e70d7ad9 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -20,6 +20,10 @@ android:key="@string/quality_pref_key" android:title="@string/watch_quality_pref" android:icon="@drawable/ic_baseline_hd_24" /> +