[Android] VideoInBackground: add force restore setting

Duncan McNamara git at videolan.org
Fri Mar 10 09:26:54 UTC 2023


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Mon Feb 13 15:34:49 2023 +0100| [d0e4841d43ff9cba6c29537a5df654dea4167b99] | committer: Nicolas Pomepuy

VideoInBackground: add force restore setting

Add setting to force restore video from background when reopening the
app, so that you don't have to go through the long click on the cover.

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

 application/resources/src/main/res/values/strings.xml  |  2 ++
 .../tools/src/main/java/org/videolan/tools/Settings.kt |  1 +
 application/vlc-android/res/xml/preferences_video.xml  |  7 +++++++
 .../src/org/videolan/vlc/gui/audio/AudioPlayer.kt      | 18 +++++++++++-------
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index ae3c625406..32a4f5b8e6 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -765,6 +765,8 @@
     <string name="misc">Miscellaneous</string>
     <string name="popup_force_legacy_title">Use custom Picture-in-Picture popup</string>
     <string name="popup_force_legacy_summary">Use custom Picture-in-Picture resizable popup</string>
+    <string name="restore_background_video_title">Restore video from background</string>
+    <string name="restore_background_video_summary">Restore video from background when reopening vlc-android</string>
     <string name="device_default">Device default</string>
     <string name="track_number">%d tracks</string>
     <string name="jump_to">Jump to</string>
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 890cb5b8f2..c929f6afd0 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -137,6 +137,7 @@ const val SAVE_BRIGHTNESS = "save_brightness"
 const val BRIGHTNESS_VALUE = "brightness_value"
 const val POPUP_KEEPSCREEN = "popup_keepscreen"
 const val POPUP_FORCE_LEGACY = "popup_force_legacy"
+const val RESTORE_BACKGROUND_VIDEO = "restore_background_video"
 const val LOCK_USE_SENSOR = "lock_use_sensor"
 const val DISPLAY_UNDER_NOTCH = "display_under_notch"
 const val ALLOW_FOLD_AUTO_LAYOUT = "allow_fold_auto_layout"
diff --git a/application/vlc-android/res/xml/preferences_video.xml b/application/vlc-android/res/xml/preferences_video.xml
index fb6e30a10d..8a05b2f635 100644
--- a/application/vlc-android/res/xml/preferences_video.xml
+++ b/application/vlc-android/res/xml/preferences_video.xml
@@ -42,6 +42,13 @@
             android:summary="@string/popup_force_legacy_summary"
             android:title="@string/popup_force_legacy_title"/>
 
+    <CheckBoxPreference
+            app:singleLineTitle="false"
+            android:defaultValue="false"
+            android:key="restore_background_video"
+            android:summary="@string/restore_background_video_summary"
+            android:title="@string/restore_background_video_title"/>
+
     <CheckBoxPreference
         app:singleLineTitle="false"
         android:defaultValue="false"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 0e93d2395c..9745c310c6 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -127,13 +127,6 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
         playlistAdapter = PlaylistAdapter(this)
         settings = Settings.getInstance(requireContext())
         playlistModel = PlaylistModel.get(this)
-        val restoreVideoTipCount = settings.getInt(PREF_RESTORE_VIDEO_TIPS_SHOWN, 0)
-        playlistModel.service?.let {
-            if (!it.isVideoPlaying && it.videoTracksCount > 0 && restoreVideoTipCount < 4) {
-                UiTools.snacker(requireActivity(), R.string.return_to_video)
-                settings.putSingle(PREF_RESTORE_VIDEO_TIPS_SHOWN, restoreVideoTipCount + 1)
-            }
-        }
         playlistModel.progress.observe(this at AudioPlayer) { it?.let { updateProgress(it) } }
         playlistModel.speed.observe(this at AudioPlayer) { showChips() }
         playlistAdapter.setModel(playlistModel)
@@ -289,6 +282,17 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
     override fun onResume() {
         onStateChanged(playerState)
         showRemainingTime = Settings.getInstance(requireContext()).getBoolean(SHOW_REMAINING_TIME, false)
+        val restoreVideoTipCount = settings.getInt(PREF_RESTORE_VIDEO_TIPS_SHOWN, 0)
+        val forceRestoreVideo = settings.getBoolean(RESTORE_BACKGROUND_VIDEO, false)
+        playlistModel.service?.let {
+            if (!it.isVideoPlaying && it.videoTracksCount > 0)
+                if ( !forceRestoreVideo && restoreVideoTipCount < 4) {
+                    UiTools.snacker(requireActivity(), R.string.return_to_video)
+                    settings.putSingle(PREF_RESTORE_VIDEO_TIPS_SHOWN, restoreVideoTipCount + 1)
+                } else if (forceRestoreVideo) {
+                    onResumeToVideoClick()
+                }
+        }
         super.onResume()
     }
 



More information about the Android mailing list