[Android] Media types filtering

Geoffrey Métais git at videolan.org
Mon Feb 9 11:30:47 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan 20 17:20:02 2015 +0100| [48c46205d866ceaa58b5cb79d52c1646c3dd4013] | committer: Geoffrey Métais

Media types filtering

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

 .../videolan/vlc/gui/network/NetworkAdapter.java   |   25 ++++++++++++++++++--
 vlc-android/src/org/videolan/vlc/util/Util.java    |    8 +++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/network/NetworkAdapter.java b/vlc-android/src/org/videolan/vlc/gui/network/NetworkAdapter.java
index 5d24413..28fac8f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/NetworkAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/network/NetworkAdapter.java
@@ -21,6 +21,7 @@
  */
 package org.videolan.vlc.gui.network;
 
+import android.net.Uri;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -32,6 +33,7 @@ import org.videolan.libvlc.Media;
 import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
 import org.videolan.vlc.gui.audio.MediaComparators;
+import org.videolan.vlc.util.Util;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -59,11 +61,14 @@ public class NetworkAdapter extends  RecyclerView.Adapter<NetworkAdapter.ViewHol
         final MediaWrapper media = getItem(position);
         holder.title.setText(media.getTitle());
         holder.text.setVisibility(View.GONE);
-        holder.icon.setImageResource(R.drawable.ic_menu_folder);
+        holder.icon.setImageResource(getIconResId(media));
         holder.itemView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                fragment.browse(media);
+                if (media.getType() == MediaWrapper.TYPE_DIR)
+                    fragment.browse(media);
+                else
+                    Util.openMedia(v.getContext(), media);
             }
         });
     }
@@ -104,6 +109,7 @@ public class NetworkAdapter extends  RecyclerView.Adapter<NetworkAdapter.ViewHol
         return mMediaList.get(position);
     }
 
+
     public void sortList(){
         ArrayList<MediaWrapper> files = new ArrayList<MediaWrapper>(), dirs = new ArrayList<MediaWrapper>();
         for (MediaWrapper media : mMediaList){
@@ -119,4 +125,19 @@ public class NetworkAdapter extends  RecyclerView.Adapter<NetworkAdapter.ViewHol
         mMediaList.addAll(files);
         notifyDataSetChanged();
     }
+
+    private int getIconResId(MediaWrapper media) {
+        switch (media.getType()){
+            case MediaWrapper.TYPE_AUDIO:
+                return R.drawable.ic_menu_audio;
+            case MediaWrapper.TYPE_DIR:
+                return R.drawable.ic_menu_folder;
+            case MediaWrapper.TYPE_VIDEO:
+                return R.drawable.ic_menu_video;
+            case MediaWrapper.TYPE_SUBTITLE:
+                return R.drawable.ic_subtitle_circle_normal;
+            default:
+                return R.drawable.ic_cone_o;
+        }
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 06f72e9..6844614 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -181,6 +181,14 @@ public class Util {
     }
 
 
+    public static void openMedia(Context context, final MediaWrapper media){
+        String mrl = Uri.decode(media.getLocation());
+        if (media.getType() == MediaWrapper.TYPE_VIDEO)
+            VideoPlayerActivity.start(context, mrl, media.getTitle());
+        else if (media.getType() == MediaWrapper.TYPE_AUDIO)
+            openStream(context, mrl);
+    }
+
     public static void openStream(Context context, final String uri){
         VideoPlayerActivity.start(context, uri);
     }



More information about the Android mailing list