[Android] Remote access: add / remove favorites

Nicolas Pomepuy git at videolan.org
Thu Jun 20 12:34:44 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun 20 09:08:02 2024 +0200| [cae02363ef69f5a1fbcaa8902d67294ff5dbcebe] | committer: Nicolas Pomepuy

Remote access: add / remove favorites

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

 .../videolan/vlc/webserver/RemoteAccessRouting.kt  | 56 ++++++++++++++++++++++
 .../videolan/vlc/webserver/TranslationMapping.kt   |  2 +
 2 files changed, 58 insertions(+)

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 41aefd7bf0..e8b83c36a9 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
@@ -1002,6 +1002,62 @@ fun Route.setupRouting(appContext: Context, scope: CoroutineScope) {
             }
             call.respond(HttpStatusCode.NotFound)
         }
+        //Change the favorite state of a media
+        get("/favorite") {
+            val type = call.request.queryParameters["type"] ?: "media"
+            val favorite = call.request.queryParameters["favorite"] ?: "true" == "true"
+            call.request.queryParameters["id"]?.let { id ->
+                when (type) {
+                    "album" -> {
+                        val album = appContext.getFromMl { getAlbum(id.toLong()) }
+                        album.setFavorite(favorite)
+                        call.respondText("")
+                        return at get
+                    }
+                    "artist" -> {
+                        val artist = appContext.getFromMl { getArtist(id.toLong()) }
+                        artist.setFavorite(favorite)
+                        call.respondText("")
+                        return at get
+                    }
+                    "genre" -> {
+                        val genre = appContext.getFromMl { getGenre(id.toLong()) }
+                        genre.setFavorite(favorite)
+                        call.respondText("")
+                        return at get
+                    }
+                    "playlist" -> {
+                        val playlist = appContext.getFromMl { getPlaylist(id.toLong(), false, false) }
+                        playlist.setFavorite(favorite)
+                        call.respondText("")
+                        return at get
+                    }
+                    "video-group" -> {
+                        val videoGroup = appContext.getFromMl { getVideoGroup(id.toLong()) }
+                        videoGroup.setFavorite(favorite)
+                        call.respondText("")
+                        return at get
+                    }
+                    "video-folder" -> {
+                        val videoFolder = appContext.getFromMl { getFolder(Folder.TYPE_FOLDER_VIDEO, id.toLong()) }
+                        videoFolder.setFavorite(favorite)
+                        call.respondText("")
+                        return at get
+                    }
+                    else -> {
+                        //simple media. It's a direct download
+                        appContext.getFromMl { getMedia(id.toLong()) }?.let { media ->
+                            media.setFavorite(favorite)
+                            call.respondText("")
+                            return at get
+
+                        }
+                        call.respond(HttpStatusCode.NotFound)
+                    }
+                }
+            }
+            call.respond(HttpStatusCode.NotFound)
+        }
         // Get a media artwork
         get("/artwork") {
             var type = call.request.queryParameters["type"]
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 f5d5a05ace..167de49b3e 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
@@ -96,5 +96,7 @@ object TranslationMapping {
         LIGHT_THEME(R.string.light_theme),
         MORE(R.string.more),
         HISTORY(R.string.history),
+        ADD_FAVORITE(R.string.favorites_add),
+        REMOVE_FAVORITE(R.string.favorites_remove),
     }
 }
\ No newline at end of file



More information about the Android mailing list