[Android] Share the history with the remote access

Nicolas Pomepuy git at videolan.org
Wed Jun 19 08:17:53 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jun 18 13:23:13 2024 +0200| [48454e4648286d73e16ee1f48f4344125087721d] | committer: Nicolas Pomepuy

Share the history with the remote access

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

 .../src/main/java/org/videolan/tools/Settings.kt   |  1 +
 .../res/xml/preferences_remote_access.xml          |  5 +++++
 .../videolan/vlc/webserver/RemoteAccessRouting.kt  | 23 ++++++++++++++++++++++
 .../videolan/vlc/webserver/TranslationMapping.kt   |  2 ++
 4 files changed, 31 insertions(+)

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 e93e5fae05..034d2b7962 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -132,6 +132,7 @@ const val KEY_ENABLE_REMOTE_ACCESS = "enable_remote_access"
 const val KEY_REMOTE_ACCESS_ML_CONTENT = "remote_access_medialibrary_content"
 const val REMOTE_ACCESS_FILE_BROWSER_CONTENT = "remote_access_file_browser_content"
 const val REMOTE_ACCESS_NETWORK_BROWSER_CONTENT = "remote_access_network_browser_content"
+const val REMOTE_ACCESS_HISTORY_CONTENT = "remote_access_history_content"
 const val REMOTE_ACCESS_PLAYBACK_CONTROL = "remote_access_playback_control"
 const val REMOTE_ACCESS_LOGS = "remote_access_logs"
 const val KEYSTORE_PASSWORD = "keystore_encrypted_password"
diff --git a/application/vlc-android/res/xml/preferences_remote_access.xml b/application/vlc-android/res/xml/preferences_remote_access.xml
index f020578c94..dc26dd7569 100644
--- a/application/vlc-android/res/xml/preferences_remote_access.xml
+++ b/application/vlc-android/res/xml/preferences_remote_access.xml
@@ -39,6 +39,11 @@
                 android:dependency="enable_remote_access"
                 android:key="remote_access_network_browser_content"
                 android:title="@string/remote_access_network_browser_content" />
+        <CheckBoxPreference
+                android:defaultValue="false"
+                android:dependency="enable_remote_access"
+                android:key="remote_access_history_content"
+                android:title="@string/history" />
         <CheckBoxPreference
                 android:defaultValue="true"
                 android:dependency="enable_remote_access"
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
index c8c4fa974f..51a6bd472e 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
@@ -62,6 +62,7 @@ import kotlinx.coroutines.withContext
 import org.json.JSONArray
 import org.json.JSONObject
 import org.videolan.medialibrary.MLServiceLocator
+import org.videolan.medialibrary.Tools
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.Album
 import org.videolan.medialibrary.interfaces.media.Artist
@@ -87,6 +88,7 @@ import org.videolan.tools.CloseableUtils
 import org.videolan.tools.HttpImageLoader
 import org.videolan.tools.KEY_ARTISTS_SHOW_ALL
 import org.videolan.tools.REMOTE_ACCESS_FILE_BROWSER_CONTENT
+import org.videolan.tools.REMOTE_ACCESS_HISTORY_CONTENT
 import org.videolan.tools.REMOTE_ACCESS_LOGS
 import org.videolan.tools.REMOTE_ACCESS_NETWORK_BROWSER_CONTENT
 import org.videolan.tools.Settings
@@ -669,6 +671,27 @@ fun Route.setupRouting(appContext: Context, scope: CoroutineScope) {
             val gson = Gson()
             call.respondText(gson.toJson(list))
         }
+        get("/history") {
+            verifyLogin(settings)
+            if (!settings.getBoolean(REMOTE_ACCESS_HISTORY_CONTENT, false)) {
+                call.respond(HttpStatusCode.Forbidden)
+                return at get
+            }
+            val list = try {
+                withContext(Dispatchers.Default) {
+                    appContext.getFromMl {
+                        history(
+                            Medialibrary.HISTORY_TYPE_LOCAL).toMutableList().map { it.toPlayQueueItem(if (it.type == MediaWrapper.TYPE_VIDEO) Tools.millisToText(it.length) else "") }
+                    }
+                }
+            } catch (e: Exception) {
+                Log.e(this::class.java.simpleName, e.message, e)
+                call.respond(HttpStatusCode.InternalServerError)
+                return at get
+            }
+            val gson = Gson()
+            call.respondText(gson.toJson(list))
+        }
         // List of all the network shares
         get("/network-list") {
             verifyLogin(settings)
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 5e8285e06e..f5d5a05ace 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
@@ -94,5 +94,7 @@ object TranslationMapping {
         PLAY_ALL(R.string.play_all),
         DARK_THEME(R.string.dark_theme),
         LIGHT_THEME(R.string.light_theme),
+        MORE(R.string.more),
+        HISTORY(R.string.history),
     }
 }
\ No newline at end of file



More information about the Android mailing list