[Android] Allow resetting the sleep timer on any interaction

Nicolas Pomepuy git at videolan.org
Tue Jun 11 14:50:38 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri May 24 12:09:37 2024 +0200| [7e0a72942134a155a09b22cdc72295ae01912561] | committer: Nicolas Pomepuy

Allow resetting the sleep timer on any interaction

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

 application/resources/src/main/res/values/strings.xml |  1 +
 .../vlc-android/res/layout/dialog_time_picker.xml     | 19 ++++++++++++++-----
 .../src/org/videolan/vlc/PlaybackService.kt           |  2 ++
 .../org/videolan/vlc/gui/dialogs/SleepTimerDialog.kt  |  2 ++
 .../vlc/gui/video/VideoPlayerOverlayDelegate.kt       | 11 +++++++++++
 5 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index afc7fcf2d2..ad9db83f9e 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -190,6 +190,7 @@
     <string name="jump_to_time">Jump to Time</string>
     <string name="subtitle_select">Select subtitle file</string>
     <string name="wait_before_sleep">Wait for current media item to finish first</string>
+    <string name="reset_on_interaction">Reset on any interaction</string>
 
     <string name="server_add_title">Add a new server to favorites</string>
     <string name="server_domain_hint">Server address (domain name or IP)</string>
diff --git a/application/vlc-android/res/layout/dialog_time_picker.xml b/application/vlc-android/res/layout/dialog_time_picker.xml
index 05fd96bae8..a5e5322b38 100644
--- a/application/vlc-android/res/layout/dialog_time_picker.xml
+++ b/application/vlc-android/res/layout/dialog_time_picker.xml
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
-<layout>
+<layout xmlns:tools="http://schemas.android.com/tools"
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:app="http://schemas.android.com/apk/res-auto">
 
-    <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
-            xmlns:app="http://schemas.android.com/apk/res-auto"
-            xmlns:tools="http://schemas.android.com/tools"
+    <androidx.core.widget.NestedScrollView
             android:layout_width="match_parent"
             android:layout_height="match_parent">
 
@@ -270,6 +270,15 @@
                     app:layout_constraintStart_toStartOf="parent"
                     app:layout_constraintTop_toBottomOf="@id/linearLayout5" />
 
+            <CheckBox
+                    android:id="@+id/tim_pic_reset_checkbox"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginStart="16dp"
+                    android:text="@string/reset_on_interaction"
+                    app:layout_constraintStart_toStartOf="parent"
+                    app:layout_constraintTop_toBottomOf="@id/tim_pic_wait_checkbox" />
+
             <Button
                     android:id="@+id/tim_pic_delete_current"
                     android:layout_width="0dp"
@@ -297,7 +306,7 @@
                     android:text="@string/ok"
                     android:textStyle="bold"
                     app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toBottomOf="@+id/tim_pic_wait_checkbox" />
+                    app:layout_constraintTop_toBottomOf="@+id/tim_pic_reset_checkbox" />
 
         </androidx.constraintlayout.widget.ConstraintLayout>
     </androidx.core.widget.NestedScrollView>
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index bb79c3a41f..da08e7641d 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -220,6 +220,8 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner, CoroutineSc
     private lateinit var browserCallback: MediaBrowserCallback
     var sleepTimerJob: Job? = null
     var waitForMediaEnd = false
+    var resetOnInteraction = false
+    var sleepTimerInterval = 0L
     private var mediaEndReached = false
 
     // Playback management
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SleepTimerDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SleepTimerDialog.kt
index a2c7614e9a..cf69929a09 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SleepTimerDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SleepTimerDialog.kt
@@ -59,11 +59,13 @@ class SleepTimerDialog : PickTimeFragment() {
 
     override fun executeAction() {
         playlistModel.service?.waitForMediaEnd = binding.timPicWaitCheckbox.isChecked
+        playlistModel.service?.resetOnInteraction = binding.timPicResetCheckbox.isChecked
         settings.putSingle(SLEEP_TIMER_WAIT, binding.timPicWaitCheckbox.isChecked)
 
         val hours = if (hours != "") java.lang.Long.parseLong(hours) * HOURS_IN_MICROS else 0L
         val minutes = if (minutes != "") java.lang.Long.parseLong(minutes) * MINUTES_IN_MICROS else 0L
         val interval = (hours + minutes) / MILLIS_IN_MICROS //Interval in ms
+        playlistModel.service?.sleepTimerInterval = interval
 
         val sleepTime = Calendar.getInstance()
         sleepTime.timeInMillis = sleepTime.timeInMillis + interval
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 0c3ca55ff7..5d05141a4e 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
@@ -354,6 +354,9 @@ class VideoPlayerOverlayDelegate (private val player: VideoPlayerActivity) {
         player.handler.removeMessages(VideoPlayerActivity.FADE_OUT_VOLUME_INFO)
         player.handler.sendEmptyMessageDelayed(VideoPlayerActivity.FADE_OUT_VOLUME_INFO, 1000L)
         dimStatusBar(true)
+        player.service?.let { service ->
+            resetSleepTimer(service)
+        }
     }
 
     /**
@@ -448,9 +451,17 @@ class VideoPlayerOverlayDelegate (private val player: VideoPlayerActivity) {
                 if (overlayTimeout != VideoPlayerActivity.OVERLAY_INFINITE)
                     player.handler.sendMessageDelayed(player.handler.obtainMessage(VideoPlayerActivity.FADE_OUT), overlayTimeout.toLong())
             }
+
+            resetSleepTimer(service)
         }
     }
 
+    private fun resetSleepTimer(service: PlaybackService) {
+        val sleepTime = Calendar.getInstance()
+        sleepTime.timeInMillis = System.currentTimeMillis() + service.sleepTimerInterval
+        PlaybackService.playerSleepTime.value = sleepTime
+    }
+
     fun updateOverlayPausePlay(skipAnim: Boolean = false) {
         if (!::hudBinding.isInitialized) return
         player.service?.let { service ->



More information about the Android mailing list