[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
This commit is contained in:
Jace 2022-04-12 20:23:30 +08:00 committed by GitHub
parent 970a68f47b
commit d6d4bfaa0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 4 deletions

View file

@ -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")

View file

@ -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)

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/white">
<path
android:fillColor="@android:color/white"
android:pathData="M5,17v2h14v-2L5,17zM9.5,12.8h5l0.9,2.2h2.1L12.75,4h-1.5L6.5,15h2.1l0.9,-2.2zM12,5.98L13.87,11h-3.74L12,5.98z"/>
</vector>

View file

@ -59,6 +59,21 @@
<item>3</item>
</array>
<array name="limit_title_pref_names">
<item>@string/none</item>
<item>16 characters</item>
<item>32 characters</item>
<item>64 characters</item>
<item>128 characters</item>
</array>
<array name="limit_title_pref_values">
<item>0</item>
<item>16</item>
<item>32</item>
<item>64</item>
<item>128</item>
</array>
<array name="video_buffer_length_names">
<item>@string/automatic</item>
<item>1min</item>

View file

@ -13,6 +13,7 @@
<string name="subtitle_settings_key" translatable="false">subtitle_settings_key</string>
<string name="subtitle_settings_chromecast_key" translatable="false">subtitle_settings_chromecast_key</string>
<string name="quality_pref_key" translatable="false">quality_pref_key</string>
<string name="prefer_limit_title_key" translatable="false">prefer_limit_title_key</string>
<string name="video_buffer_size_key" translatable="false">video_buffer_size_key</string>
<string name="video_buffer_length_key" translatable="false">video_buffer_length_key</string>
<string name="video_buffer_clear_key" translatable="false">video_buffer_clear_key</string>
@ -348,6 +349,7 @@
<string name="dont_show_again">Don\'t show again</string>
<string name="update">Update</string>
<string name="watch_quality_pref">Preferred watch quality</string>
<string name="limit_title">Limit title characters on player</string>
<string name="video_buffer_size_settings">Video buffer size</string>
<string name="video_buffer_length_settings">Video buffer length</string>
<string name="video_buffer_disk_settings">Video cache on disk</string>

View file

@ -20,6 +20,10 @@
android:key="@string/quality_pref_key"
android:title="@string/watch_quality_pref"
android:icon="@drawable/ic_baseline_hd_24" />
<Preference
android:key="@string/prefer_limit_title_key"
android:title="@string/limit_title"
android:icon="@drawable/ic_baseline_text_format_24" />
<SwitchPreference
android:icon="@drawable/ic_baseline_picture_in_picture_alt_24"