[Android] Fill browsers with Medialibrary items if available

Geoffrey Métais git at videolan.org
Tue Mar 7 18:29:29 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar  7 18:28:08 2017 +0100| [08a95c69e357266581663d0eed2ffc756130b4df] | committer: Geoffrey Métais

Fill browsers with Medialibrary items if available

Close #234 #235

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

 .../videolan/vlc/gui/browser/BaseBrowserFragment.java    | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 514a281..d86ffd7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -28,6 +28,7 @@ import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Message;
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -252,7 +253,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
     @Override
     public void onMediaAdded(int index, Media media) {
         boolean wasEmtpy = mAdapter.isEmpty();
-        mAdapter.addItem(new MediaWrapper(media), false);
+        mAdapter.addItem(getMediaWrapper(media), false);
         if (!wasEmtpy)
             return;
         updateEmptyView();
@@ -552,7 +553,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
             if (type == Media.Type.Directory)
                 directories.add(new MediaWrapper(media));
             else if (type == Media.Type.File)
-                files.add(new MediaWrapper(media));
+                files.add(getMediaWrapper(media));
         }
 
         @Override
@@ -619,6 +620,17 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
         }
     };
 
+    @NonNull
+    private MediaWrapper getMediaWrapper(Media media) {
+        MediaWrapper mw = null;
+        Uri uri = media.getUri();
+        if (media.getType() == Media.Type.File && "file".equals(uri.getScheme()))
+            mw = mMediaLibrary.getMedia(uri);
+        if (mw == null)
+            mw = new MediaWrapper(media);
+        return mw;
+    }
+
     @Override
     public boolean enableSearchOption() {
         return !isRootDirectory();



More information about the Android mailing list