[Android] HistoryAdapter: use MediaDatbase() meta if possible

Edward Wang git at videolan.org
Sun Sep 1 16:30:42 CEST 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sun Sep  1 16:07:13 2013 +0200| [374b23c0fcc06a100562201d11651a1cad6bbd56] | committer: Edward Wang

HistoryAdapter: use MediaDatbase() meta if possible

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=374b23c0fcc06a100562201d11651a1cad6bbd56
---

 .../src/org/videolan/vlc/gui/HistoryAdapter.java    |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java
index 3dba1ed..c4e06e4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java
@@ -26,6 +26,7 @@ import java.util.List;
 import org.videolan.libvlc.EventHandler;
 import org.videolan.libvlc.LibVLC;
 import org.videolan.vlc.Media;
+import org.videolan.vlc.MediaDatabase;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.WeakHandler;
@@ -54,14 +55,22 @@ public class HistoryAdapter extends BaseAdapter {
         if (libVLC != null)
             libVLC.getMediaListItems(items);
 
-       for(int i = 0; i < items.size(); i++) {
-           mHistory.add(new Media(items.get(i), libVLC.getPrimaryMediaList(), i));
-       }
+       addToHistory(items, libVLC);
 
         EventHandler em = libVLC.getPrimaryMediaList().getEventHandler();
         em.addHandler(new HistoryEventHandler(this));
     }
 
+    private void addToHistory(ArrayList<String> items, LibVLC libVLC) {
+        MediaDatabase db = MediaDatabase.getInstance(VLCApplication.getAppContext());
+        for(int i = 0; i < items.size(); i++) {
+            if(db.mediaItemExists(items.get(i)))
+                mHistory.add(db.getMedia(VLCApplication.getAppContext(), items.get(i)));
+            else
+                mHistory.add(new Media(items.get(i), libVLC.getPrimaryMediaList(), i));
+        }
+    }
+
     @Override
     public int getCount() {
         return mHistory.size();
@@ -131,9 +140,7 @@ public class HistoryAdapter extends BaseAdapter {
         if (libVLC != null) {
             libVLC.getMediaListItems(items);
             mHistory.clear();
-            for(int i = 0; i < items.size(); i++) {
-                mHistory.add(new Media(items.get(i), libVLC.getPrimaryMediaList(), i));
-            };
+            addToHistory(items, libVLC);
             this.notifyDataSetChanged();
         }
     }



More information about the Android mailing list