[Android] Video player: change hud timeout range from 1 to infinity

Nicolas Pomepuy git at videolan.org
Mon Jun 13 06:07:17 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun  9 07:48:03 2022 +0200| [8bdbda43d38e8869d04136c047740d1396620f56] | committer: Nicolas Pomepuy

Video player: change hud timeout range from 1 to infinity

Fixes #2539

> https://code.videolan.org/videolan/vlc-android/commit/8bdbda43d38e8869d04136c047740d1396620f56
---

 .../tools/src/main/java/org/videolan/tools/Settings.kt    | 12 +++++++++++-
 .../vlc-android/res/xml/preferences_video_controls.xml    |  4 ++--
 .../vlc/gui/preferences/PreferencesVideoControls.kt       |  4 ++--
 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt |  4 ++--
 .../videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt  |  4 ++--
 .../src/org/videolan/vlc/util/VersionMigration.kt         | 15 ++++++++++++++-
 6 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index 663315706..42617456c 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -35,7 +35,7 @@ object Settings : SingletonHolder<SharedPreferences, Context>({ init(it.applicat
         showVideoThumbs = prefs.getBoolean(SHOW_VIDEO_THUMBNAILS, true)
         tvUI = prefs.getBoolean(PREF_TV_UI, false)
         listTitleEllipsize = prefs.getString(LIST_TITLE_ELLIPSIZE, "0")?.toInt() ?: 0
-        videoHudDelay = prefs.getInt(VIDEO_HUD_TIMEOUT, 4)
+        videoHudDelay = prefs.getInt(VIDEO_HUD_TIMEOUT, 4).coerceInOrDefault(1, 15, -1)
         device = DeviceInfo(context)
         includeMissing = prefs.getBoolean(KEY_INCLUDE_MISSING, true)
         showHeaders = prefs.getBoolean(KEY_SHOW_HEADERS, true)
@@ -192,3 +192,13 @@ fun SharedPreferences.putSingle(key: String, value: Any) {
         else -> throw IllegalArgumentException("value class is invalid!")
     }
 }
+
+/**
+ * Force an [Int] to be in a reange else set it to a default value
+ *
+ * @param min the minimum value to accept
+ * @param max the maximum value to accept
+ * @param defautValue the default value to return if it's not in the range
+ * @return an [Int] in the range
+ */
+fun Int.coerceInOrDefault(min: Int, max: Int, defautValue: Int) = if (this < min || this > max) defautValue else this
\ No newline at end of file
diff --git a/application/vlc-android/res/xml/preferences_video_controls.xml b/application/vlc-android/res/xml/preferences_video_controls.xml
index 6323be568..44c4511fd 100644
--- a/application/vlc-android/res/xml/preferences_video_controls.xml
+++ b/application/vlc-android/res/xml/preferences_video_controls.xml
@@ -85,8 +85,8 @@
                 android:key="video_hud_timeout_in_s"
                 app:updatesContinuously="true"
                 android:summary="%s"
-                android:max="15"
-                app:min="0"
+                android:max="16"
+                app:min="1"
                 app:seekBarIncrement="1"
                 android:title="@string/video_hud_timeout"
                 app:singleLineTitle="false" />
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt
index f87ddcc31..e7eeeacf7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt
@@ -53,7 +53,7 @@ class PreferencesVideoControls : BasePreferenceFragment(), SharedPreferences.OnS
 
     private fun updateHudTimeoutSummary() {
         when (Settings.videoHudDelay) {
-            0 -> findPreference<Preference>(VIDEO_HUD_TIMEOUT)?.summary = getString(R.string.timeout_infinite)
+            -1 -> findPreference<Preference>(VIDEO_HUD_TIMEOUT)?.summary = getString(R.string.timeout_infinite)
             else -> findPreference<Preference>(VIDEO_HUD_TIMEOUT)?.summary =  getString(R.string.video_hud_timeout_summary, Settings.videoHudDelay.toString())
         }
     }
@@ -73,7 +73,7 @@ class PreferencesVideoControls : BasePreferenceFragment(), SharedPreferences.OnS
         (activity as? VideoPlayerActivity)?.onChangedControlSetting(key)
         when (key) {
             VIDEO_HUD_TIMEOUT -> {
-                Settings.videoHudDelay = sharedPreferences.getInt(VIDEO_HUD_TIMEOUT, 4)
+                Settings.videoHudDelay = sharedPreferences.getInt(VIDEO_HUD_TIMEOUT, 4).coerceInOrDefault(1, 15, -1)
                 updateHudTimeoutSummary()
             }
             KEY_VIDEO_JUMP_DELAY -> {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 0dc0f3a1a..853689827 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -1442,7 +1442,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
         stopLoading()
         overlayDelegate.updateOverlayPausePlay()
         updateNavStatus()
-        if (!mw.hasFlag(MediaWrapper.MEDIA_PAUSED) && Settings.videoHudDelay != 0)
+        if (!mw.hasFlag(MediaWrapper.MEDIA_PAUSED) && Settings.videoHudDelay != -1)
             handler.sendEmptyMessageDelayed(FADE_OUT, Settings.videoHudDelay.toLong() * 1000)
         else {
             mw.removeFlags(MediaWrapper.MEDIA_PAUSED)
@@ -1736,7 +1736,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
             overlayDelegate.showOverlayTimeout(OVERLAY_INFINITE)
             pause()
         } else {
-            if (Settings.videoHudDelay != 0) handler.sendEmptyMessageDelayed(FADE_OUT, 300L)
+            if (Settings.videoHudDelay != -1) handler.sendEmptyMessageDelayed(FADE_OUT, 300L)
             play()
         }
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt
index ca7273069..4985ec86a 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt
@@ -394,11 +394,11 @@ class VideoPlayerOverlayDelegate (private val player: VideoPlayerActivity) {
             if (!::hudBinding.isInitialized) return
             overlayTimeout = when {
                 player.isTalkbackIsEnabled() -> VideoPlayerActivity.OVERLAY_INFINITE
-                Settings.videoHudDelay == 0 -> VideoPlayerActivity.OVERLAY_INFINITE
+                Settings.videoHudDelay == -1 -> VideoPlayerActivity.OVERLAY_INFINITE
                 isBookmarkShown() -> VideoPlayerActivity.OVERLAY_INFINITE
                 timeout != 0 -> timeout
                 service.isPlaying -> when (Settings.videoHudDelay) {
-                    0 -> VideoPlayerActivity.OVERLAY_INFINITE
+                    -1 -> VideoPlayerActivity.OVERLAY_INFINITE
                     else -> Settings.videoHudDelay * 1000
                 }
                 else -> VideoPlayerActivity.OVERLAY_INFINITE
diff --git a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
index c76259b7c..3f84f6580 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
@@ -39,7 +39,7 @@ import org.videolan.vlc.gui.onboarding.ONBOARDING_DONE_KEY
 import java.io.File
 import java.io.IOException
 
-private const val CURRENT_VERSION = 5
+private const val CURRENT_VERSION = 6
 
 object VersionMigration {
 
@@ -61,6 +61,9 @@ object VersionMigration {
         if (lastVersion < 5) {
             migrateToVersion5(settings)
         }
+        if (lastVersion < 6) {
+            migrateToVersion6(settings)
+        }
         settings.putSingle(KEY_CURRENT_SETTINGS_VERSION, CURRENT_VERSION)
     }
 
@@ -145,4 +148,14 @@ object VersionMigration {
         Log.i(this::class.java.simpleName, "Migrating to Version 5: force the TV ui setting if device is TV")
         if (Settings.device.isTv && settings.getBoolean("tv_ui", false) != settings.getBoolean("tv_ui", true)) settings.putSingle("tv_ui", true)
     }
+
+    /**
+     * Migrate the Video hud timeout to the new range
+     */
+    private fun migrateToVersion6(settings: SharedPreferences) {
+        Log.i(this::class.java.simpleName, "Migrating to Version 6: Migrate the Video hud timeout to the new range")
+        val hudTimeOut = settings.getInt(VIDEO_HUD_TIMEOUT, 4)
+        if (hudTimeOut == 0) settings.edit { putInt(VIDEO_HUD_TIMEOUT, 16) }
+        Settings.videoHudDelay = settings.getInt(VIDEO_HUD_TIMEOUT, 4).coerceInOrDefault(1,15,-1)
+    }
 }
\ No newline at end of file



More information about the Android mailing list