[Android] Return a flattened menu hierarchy in driving mode
Robert Stone
git at videolan.org
Mon Dec 13 07:20:18 UTC 2021
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sun Dec 5 22:34:38 2021 -0800| [6ee59ec26a07230898b28232245bba33fa0bb481] | committer: Nicolas Pomepuy
Return a flattened menu hierarchy in driving mode
> https://code.videolan.org/videolan/vlc-android/commit/6ee59ec26a07230898b28232245bba33fa0bb481
---
.../src/org/videolan/vlc/PlaybackService.kt | 6 +++-
.../org/videolan/vlc/media/MediaSessionBrowser.kt | 36 +++++++++++++---------
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index e751394e6..f2b7def4d 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1596,11 +1596,15 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
return when {
rootHints?.containsKey(BrowserRoot.EXTRA_SUGGESTED) == true -> BrowserRoot(MediaSessionBrowser.ID_SUGGESTED, null)
else -> {
+ val rootId = when(clientPackageName) {
+ "com.google.android.googlequicksearchbox" -> MediaSessionBrowser.ID_ROOT_NO_TABS
+ else -> MediaSessionBrowser.ID_ROOT
+ }
val extras = MediaSessionBrowser.getContentStyle(CONTENT_STYLE_LIST_ITEM_HINT_VALUE, CONTENT_STYLE_LIST_ITEM_HINT_VALUE).apply {
putBoolean(TABS_OPT_IN_HINT, true)
putBoolean(EXTRA_MEDIA_SEARCH_SUPPORTED, true)
}
- BrowserRoot(MediaSessionBrowser.ID_ROOT, extras)
+ BrowserRoot(rootId, extras)
}
}
}
diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
index 59af2a565..c2a098a48 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
@@ -78,7 +78,7 @@ import java.util.concurrent.Semaphore
* The reduction of space consumed by the mediaId enables an increased number of records per page.
*
* Root node
- * //org.videolan.vlc/{r}oot
+ * //org.videolan.vlc/{r}oot[?{f}latten=1]
* Root menu
* //org.videolan.vlc/{r}oot/home
* //org.videolan.vlc/{r}oot/playlist/<id>
@@ -152,6 +152,7 @@ class MediaSessionBrowser : ExtensionManagerActivity {
// Root item
// MediaIds are all strings. Maintain in uri parsable format.
const val ID_ROOT = "//${BuildConfig.APP_ID}/r"
+ const val ID_ROOT_NO_TABS = "$ID_ROOT?f=1"
const val ID_MEDIA = "$ID_ROOT/media"
const val ID_SEARCH = "$ID_ROOT/search"
const val ID_SUGGESTED = "$ID_ROOT/suggested"
@@ -225,6 +226,7 @@ class MediaSessionBrowser : ExtensionManagerActivity {
val parentIdUri = parentId.toUri()
val page = parentIdUri.getQueryParameter("p")
val pageOffset = page?.toInt()?.times(MAX_RESULT_SIZE) ?: 0
+ val flatten = parentIdUri.getBooleanQueryParameter("f", false)
when (parentIdUri.removeQuery().toString()) {
ID_ROOT -> {
//List of Extensions
@@ -257,13 +259,16 @@ class MediaSessionBrowser : ExtensionManagerActivity {
}
}
//Home
- val homeMediaDesc = MediaDescriptionCompat.Builder()
- .setMediaId(ID_HOME)
- .setTitle(res.getString(R.string.auto_home))
- .setIconUri("${BASE_DRAWABLE_URI}/${R.drawable.ic_auto_home}".toUri())
- .setExtras(getContentStyle(CONTENT_STYLE_GRID_ITEM_HINT_VALUE, CONTENT_STYLE_GRID_ITEM_HINT_VALUE))
- .build()
- results.add(MediaBrowserCompat.MediaItem(homeMediaDesc, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE))
+ if (flatten) browse(context, ID_HOME, isShuffling)?.let { results.addAll(it) }
+ else {
+ val homeMediaDesc = MediaDescriptionCompat.Builder()
+ .setMediaId(ID_HOME)
+ .setTitle(res.getString(R.string.auto_home))
+ .setIconUri("${BASE_DRAWABLE_URI}/${R.drawable.ic_auto_home}".toUri())
+ .setExtras(getContentStyle(CONTENT_STYLE_GRID_ITEM_HINT_VALUE, CONTENT_STYLE_GRID_ITEM_HINT_VALUE))
+ .build()
+ results.add(MediaBrowserCompat.MediaItem(homeMediaDesc, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE))
+ }
//Playlists
val playlistMediaDesc = MediaDescriptionCompat.Builder()
.setMediaId(ID_PLAYLIST)
@@ -273,12 +278,15 @@ class MediaSessionBrowser : ExtensionManagerActivity {
.build()
results.add(MediaBrowserCompat.MediaItem(playlistMediaDesc, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE))
//My library
- val libraryMediaDesc = MediaDescriptionCompat.Builder()
- .setMediaId(ID_LIBRARY)
- .setTitle(res.getString(R.string.auto_my_library))
- .setIconUri(MENU_AUDIO_ICON)
- .build()
- results.add(MediaBrowserCompat.MediaItem(libraryMediaDesc, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE))
+ if (flatten) browse(context, ID_LIBRARY, isShuffling)?.let { results.addAll(it) }
+ else {
+ val libraryMediaDesc = MediaDescriptionCompat.Builder()
+ .setMediaId(ID_LIBRARY)
+ .setTitle(res.getString(R.string.auto_my_library))
+ .setIconUri(MENU_AUDIO_ICON)
+ .build()
+ results.add(MediaBrowserCompat.MediaItem(libraryMediaDesc, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE))
+ }
//Streams
val streamsMediaDesc = MediaDescriptionCompat.Builder()
.setMediaId(ID_STREAM)
More information about the Android
mailing list