[Android] 'Last added' section for Android Auto

Geoffrey Métais git at videolan.org
Wed Mar 22 17:39:09 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 22 17:38:20 2017 +0100| [704754d4714253bc0bc605b32e133c6e93635456] | committer: Geoffrey Métais

'Last added' section for Android Auto

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

 vlc-android/res/values/strings.xml                     |  1 +
 .../src/org/videolan/vlc/media/BrowserProvider.java    | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 3bca1a8..cea6a3f 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -699,6 +699,7 @@
     <string name="tv_settings_hint">Long press OK button to check/uncheck directories</string>
     <string name="ml_external_storage_title">New external storage detected</string>
     <string name="ml_external_storage_msg">Do you want VLC to add device %1$s to your medialibrary?</string>
+    <string name="last_added_media">last added</string>
 
     <string-array name="chroma_formats" translatable="false">
         <item>RGB 32-bit</item>
diff --git a/vlc-android/src/org/videolan/vlc/media/BrowserProvider.java b/vlc-android/src/org/videolan/vlc/media/BrowserProvider.java
index 66bf464..1c683e1 100644
--- a/vlc-android/src/org/videolan/vlc/media/BrowserProvider.java
+++ b/vlc-android/src/org/videolan/vlc/media/BrowserProvider.java
@@ -57,19 +57,28 @@ public class BrowserProvider {
     private static final String ID_GENRES = "ID_GENRES";
     private static final String ID_PLAYLISTS = "ID_PLAYLISTS";
     private static final String ID_HISTORY = "ID_HISTORY";
+    private static final String ID_LAST_ADDED = "ID_RECENT";
     public static final String ALBUM_PREFIX = "album";
     private static final String ARTIST_PREFIX = "artist";
     private static final String GENRE_PREFIX = "genre";
     public static final String PLAYLIST_PREFIX = "playlist";
+    public static final int MAX_HISTORY_SIZE = 50;
 
     public static List<MediaBrowserCompat.MediaItem> browse(String parentId) {
         ArrayList<MediaBrowserCompat.MediaItem> results = new ArrayList<>();
         MediaLibraryItem[] list = null;
+        boolean limitSize = false;
         Resources res = VLCApplication.getAppResources();
         switch (parentId) {
             case ID_ROOT:
-                //Playlists
+                //Last added
                 MediaDescriptionCompat.Builder item = new MediaDescriptionCompat.Builder()
+                        .setMediaId(ID_LAST_ADDED)
+                        .setTitle(res.getString(R.string.last_added_media))
+                        .setIconUri(Uri.parse(BASE_DRAWABLE_URI+"ic_auto_history_normal"));
+                results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
+                //History
+                item = new MediaDescriptionCompat.Builder()
                         .setMediaId(ID_HISTORY)
                         .setTitle(res.getString(R.string.history))
                         .setIconUri(Uri.parse(BASE_DRAWABLE_URI+"ic_auto_history_normal"));
@@ -100,7 +109,12 @@ public class BrowserProvider {
                         .setIconUri(Uri.parse(BASE_DRAWABLE_URI+"ic_auto_genre_normal"));
                 results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                 return results;
+            case ID_LAST_ADDED:
+                limitSize = true;
+                list = VLCApplication.getMLInstance().getRecentAudio();
+                break;
             case ID_HISTORY:
+                limitSize = true;
                 list = VLCApplication.getMLInstance().lastMediaPlayed();
                 break;
             case ID_ARTISTS:
@@ -151,6 +165,8 @@ public class BrowserProvider {
                         libraryItem.getItemType() == MediaLibraryItem.TYPE_ALBUM ||
                         libraryItem.getItemType() == MediaLibraryItem.TYPE_PLAYLIST;
                 results.add(new MediaBrowserCompat.MediaItem(item.build(), playable ? MediaBrowserCompat.MediaItem.FLAG_PLAYABLE : MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
+                if (limitSize && results.size() == MAX_HISTORY_SIZE)
+                    break;
             }
         }
         return results;



More information about the Android mailing list