[Android] VideoListAdapter: refactor

Thomas Guillem git at videolan.org
Tue Oct 6 14:15:37 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Oct  6 14:00:12 2015 +0200| [6eea161d6113455c85d198f7e8a091efe67aa2af] | committer: Thomas Guillem

VideoListAdapter: refactor

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

 .../videolan/vlc/gui/video/VideoListAdapter.java   |   55 +++++++++-----------
 1 file changed, 25 insertions(+), 30 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 385cff8..85e7b73 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -188,10 +188,7 @@ public class VideoListAdapter extends ArrayAdapter<MediaWrapper>
         holder.binding.setVariable(BR.scaleType, ImageView.ScaleType.CENTER);
         holder.binding.setVariable(BR.cover, DEFAULT_COVER);
 
-        if (media instanceof MediaGroup)
-            fillGroupView(holder, media);
-        else
-            fillVideoView(holder, media);
+        fillView(holder, media);
 
         holder.binding.setVariable(BR.media, media);
         holder.binding.setVariable(BR.handler, mClickHandler);
@@ -207,40 +204,38 @@ public class VideoListAdapter extends ArrayAdapter<MediaWrapper>
         }
     }
 
-    private void fillGroupView(ViewHolder holder, MediaWrapper media) {
-        holder.binding.setVariable(BR.group, true);
-        MediaGroup mediaGroup = (MediaGroup) media;
-        int size = mediaGroup.size();
-        String text = getContext().getResources().getQuantityString(R.plurals.videos_quantity, size, size);
-        holder.binding.setVariable(BR.resolution, text);
-        holder.binding.setVariable(BR.time, "");
-        holder.binding.setVariable(BR.max, 0);
-        holder.binding.setVariable(BR.progress, 0);
-    }
-
-    private void fillVideoView(ViewHolder holder, MediaWrapper media) {
+    private void fillView(ViewHolder holder, MediaWrapper media) {
+        boolean group;
         String text = "";
         String resolution = "";
         int max = 0;
         int progress = 0;
 
-        /* Time / Duration */
-        if (media.getLength() > 0) {
-            long lastTime = media.getTime();
-            if (lastTime > 0) {
-                text = String.format("%s / %s",
-                        Strings.millisToText(lastTime),
-                        Strings.millisToText(media.getLength()));
-                max = (int) (media.getLength() / 1000);
-                progress = (int) (lastTime / 1000);
-            } else {
-                text = Strings.millisToText(media.getLength());
+        if (media.getType() == MediaWrapper.TYPE_GROUP) {
+            group = true;
+            MediaGroup mediaGroup = (MediaGroup) media;
+            int size = mediaGroup.size();
+            resolution = getContext().getResources().getQuantityString(R.plurals.videos_quantity, size, size);
+        } else {
+            group = false;
+            /* Time / Duration */
+            if (media.getLength() > 0) {
+                long lastTime = media.getTime();
+                if (lastTime > 0) {
+                    text = String.format("%s / %s",
+                            Strings.millisToText(lastTime),
+                            Strings.millisToText(media.getLength()));
+                    max = (int) (media.getLength() / 1000);
+                    progress = (int) (lastTime / 1000);
+                } else {
+                    text = Strings.millisToText(media.getLength());
+                }
             }
+            if (media.getWidth() > 0 && media.getHeight() > 0)
+                resolution = String.format("%dx%d", media.getWidth(), media.getHeight());
         }
-        if (media.getWidth() > 0 && media.getHeight() > 0)
-            resolution = String.format("%dx%d", media.getWidth(), media.getHeight());
 
-        holder.binding.setVariable(BR.group, false);
+        holder.binding.setVariable(BR.group, group);
         holder.binding.setVariable(BR.resolution, resolution);
         holder.binding.setVariable(BR.time, text);
         holder.binding.setVariable(BR.max, max);



More information about the Android mailing list