[Android] Allow editing the sleep timer

Nicolas Pomepuy git at videolan.org
Mon Sep 9 15:14:15 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Sep  4 11:20:11 2024 +0200| [fbfa055958fbd152d71e07d9dfb26615102c5617] | committer: Duncan McNamara

Allow editing the sleep timer

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

 .../src/org/videolan/vlc/gui/dialogs/SleepTimerDialog.kt |  2 ++
 .../org/videolan/vlc/webserver/RemoteAccessServer.kt     | 11 ++++++++---
 .../org/videolan/vlc/webserver/TranslationMapping.kt     |  5 +++++
 .../vlc/webserver/websockets/RemoteAccessWebSockets.kt   | 16 ++++++++++++++--
 4 files changed, 29 insertions(+), 5 deletions(-)

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 445820745f..b39b18384c 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
@@ -70,6 +70,8 @@ class SleepTimerDialog : PickTimeFragment() {
                 updateValue("$hours$minutes")
             }
         }
+        binding.timPicWaitCheckbox.isChecked = playlistModel.service?.waitForMediaEnd ?: false
+        binding.timPicResetCheckbox.isChecked = playlistModel.service?.resetOnInteraction ?: false
     }
 
     override fun executeAction() {
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt
index 8ab2ac40db..b6c773e86b 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt
@@ -588,9 +588,11 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
                 val chapters = withContext(Dispatchers.IO) { service.getChapters(-1) ?: arrayOf() }
                 val speed = String.format(Locale.US, "%.2f", service.speed).toFloat()
                 val sleepTimer = playerSleepTime.value?.time?.time ?: 0L
+                val waitForMediaEnd = service.waitForMediaEnd
+                val resetOnInteraction = service.resetOnInteraction
                 val nowPlaying = NowPlaying(media.title ?: "", media.artist
                         ?: "", service.isPlaying, service.getTime(), service.length, media.id, media.artworkURL
-                        ?: "", media.uri.toString(), getVolume(), speed, sleepTimer, service.isShuffling, service.repeatType, bookmarks = bookmarks.map { WSBookmark(it.id, it.title, it.time) }, chapters = chapters.map { WSChapter(it.name, it.duration) })
+                        ?: "", media.uri.toString(), getVolume(), speed, sleepTimer, waitForMediaEnd, resetOnInteraction, service.isShuffling, service.repeatType, bookmarks = bookmarks.map { WSBookmark(it.id, it.title, it.time) }, chapters = chapters.map { WSChapter(it.name, it.duration) })
                 return nowPlaying
 
             }
@@ -742,8 +744,11 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
     }
 
     abstract class WSMessage(val type: String)
-    data class NowPlaying(val title: String, val artist: String, val playing: Boolean, val progress: Long, val duration: Long, val id: Long, val artworkURL: String, val uri: String, val volume: Int, val speed: Float, val sleepTimer: Long, val shuffle: Boolean, val repeat: Int, val shouldShow: Boolean = PlaylistManager.playingState.value
-            ?: false, val bookmarks:List<WSBookmark> = listOf(), val chapters:List<WSChapter> = listOf()) : WSMessage("now-playing")
+    data class NowPlaying(val title: String, val artist: String, val playing: Boolean, val progress: Long,
+                          val duration: Long, val id: Long, val artworkURL: String, val uri: String, val volume: Int, val speed: Float,
+                          val sleepTimer: Long, val waitForMediaEnd:Boolean, val resetOnInteraction:Boolean, val shuffle: Boolean, val repeat: Int,
+                          val shouldShow: Boolean = PlaylistManager.playingState.value ?: false,
+                          val bookmarks:List<WSBookmark> = listOf(), val chapters:List<WSChapter> = listOf()) : WSMessage("now-playing")
 
     data class WSBookmark(val id:Long, val title: String, val time: Long)
     data class WSChapter(val title: String, val time: Long)
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/TranslationMapping.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/TranslationMapping.kt
index 54c8e5dc18..b93586f8a3 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/TranslationMapping.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/TranslationMapping.kt
@@ -133,5 +133,10 @@ object TranslationMapping {
         OK(R.string.ok),
         CANCEL(R.string.cancel),
         NOT_SET(R.string.notset),
+        SLEEP_IN(R.string.sleep_in),
+        WAIT_CURRENT_MEDIA(R.string.wait_before_sleep),
+        RESET_ON_INTERACTION(R.string.reset_on_interaction),
+        HOURS(R.string.talkback_hours),
+        MINUTES(R.string.talkback_minutes),
     }
 }
\ No newline at end of file
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt
index a20b635f3c..1043632e4c 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt
@@ -187,12 +187,24 @@ object RemoteAccessWebSockets {
                         "sleep-timer" -> {
                             incomingMessage.longValue?.let { sleepTimerEnd ->
                                 val sleepTime = Calendar.getInstance()
-                                sleepTime.timeInMillis = sleepTime.timeInMillis + sleepTimerEnd
+                                sleepTime.timeInMillis += sleepTimerEnd
                                 sleepTime.set(Calendar.SECOND, 0)
-                                service?.setSleepTimer(sleepTime)
+                                AppScope.launch(Dispatchers.Main) {
+                                    service?.setSleepTimer(sleepTime)
+                                }
                                 if (playbackControlAllowedOrSend(settings)) service?.sleepTimerInterval = sleepTimerEnd
                             }
                         }
+                        "sleep-timer-wait" -> {
+                            incomingMessage.stringValue?.let { waitForMediaEnd ->
+                                service?.waitForMediaEnd = waitForMediaEnd == "true"
+                            }
+                        }
+                        "sleep-timer-reset" -> {
+                            incomingMessage.stringValue?.let { resetOnInteraction ->
+                                service?.resetOnInteraction = resetOnInteraction == "true"
+                            }
+                        }
                         "add-bookmark" -> {
                             incomingMessage.longValue?.let { time ->
                                 service?.currentMediaWrapper?.let {



More information about the Android mailing list