[Android] Refactor playlist display

Geoffrey Métais git at videolan.org
Wed Apr 27 10:34:07 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Apr 27 09:45:29 2016 +0200| [4b925f5b2a6a9ffc565ddd0e2bb4201c1fc9173b] | committer: Geoffrey Métais

Refactor playlist display

> https://code.videolan.org/videolan/vlc-android/commit/4b925f5b2a6a9ffc565ddd0e2bb4201c1fc9173b
---

 vlc-android/res/layout/audio_player.xml            |  3 ++-
 vlc-android/res/layout/playlist_item.xml           | 24 ++++++++--------------
 vlc-android/res/values-sw600dp/styles.xml          |  8 ++++++++
 vlc-android/res/values/styles.xml                  |  6 ++++++
 .../videolan/vlc/gui/audio/PlaylistAdapter.java    |  4 ++--
 .../src/org/videolan/vlc/media/MediaUtils.java     | 19 ++++++++++-------
 6 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/vlc-android/res/layout/audio_player.xml b/vlc-android/res/layout/audio_player.xml
index 8ee0549..39be14d 100644
--- a/vlc-android/res/layout/audio_player.xml
+++ b/vlc-android/res/layout/audio_player.xml
@@ -139,9 +139,10 @@
 
         <android.support.v7.widget.RecyclerView
             android:id="@+id/songs_list"
-            android:layout_width="match_parent"
+            style="@style/PlaylistStyle"
             android:layout_height="match_parent"
             android:clipToPadding="false"
+            android:layout_gravity="center_horizontal"
             android:background="?attr/background_default"
             android:paddingBottom="@dimen/listview_bottom_padding" />
 
diff --git a/vlc-android/res/layout/playlist_item.xml b/vlc-android/res/layout/playlist_item.xml
index 41982ab..935aac6 100644
--- a/vlc-android/res/layout/playlist_item.xml
+++ b/vlc-android/res/layout/playlist_item.xml
@@ -14,7 +14,6 @@
         <variable
             name="subTitle"
             type="String"/>
-            type="int"/>
         <variable
             name="titleColor"
             type="int"/>
@@ -24,9 +23,7 @@
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="40dp"
-        android:layout_marginTop="3dip"
-        android:layout_marginBottom="3dip"
-        android:layout_marginLeft="5dip"
+        android:layout_margin="5dip"
         android:clickable="true"
         android:onClick="@{holder.onClick}" >
         <TextView
@@ -36,14 +33,15 @@
             android:layout_marginLeft="5dip"
             android:layout_marginRight="5dip"
             android:layout_alignParentLeft="true"
+            android:layout_alignParentStart="true"
             android:layout_alignParentTop="true"
-            android:layout_toLeftOf="@+id/length"
+            android:layout_toLeftOf="@+id/item_more"
+            android:layout_toStartOf="@+id/item_more"
             android:layout_above="@+id/audio_item_subtitle"
             android:maxLines="@{TextUtils.isEmpty(subTitle) ? 2 : 1}"
             android:ellipsize="middle"
             android:text="@{media.title}"
             android:textColor="@{titleColor}"
-            android:fontFamily="sans-serif-light"
             android:gravity="center_vertical"
             android:textSize="16sp" />
         <TextView
@@ -54,23 +52,16 @@
             android:layout_marginLeft="5dip"
             android:layout_marginRight="5dip"
             android:layout_alignParentLeft="true"
+            android:layout_alignParentStart="true"
             android:layout_alignParentBottom="true"
-            android:layout_toLeftOf="@+id/length"
+            android:layout_toLeftOf="@+id/item_more"
+            android:layout_toStartOf="@+id/item_more"
             android:singleLine="true"
             android:ellipsize="middle"
             android:textColor="?attr/list_subtitle"
             android:fontFamily="sans-serif-light"
             android:textSize="12sp"
             android:visibility="@{TextUtils.isEmpty(subTitle) ? View.GONE : View.VISIBLE}"/>
-        <TextView
-            android:id="@+id/length"
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            android:layout_toLeftOf="@+id/item_more"
-            android:layout_marginRight="5dip"
-            android:gravity="center_vertical"
-            android:text="@{Strings.millisToString(media.length)}"
-            android:visibility="@{media.length > 0 ? View.VISIBLE : View.GONE}"/>
 
         <ImageView
             android:id="@+id/item_more"
@@ -80,6 +71,7 @@
             android:paddingRight="10dp"
             android:paddingLeft="10dp"
             android:layout_alignParentRight="true"
+            android:layout_alignParentEnd="true"
             android:layout_alignBottom="@id/audio_item_subtitle"
             android:layout_alignTop="@id/audio_item_title"
             android:scaleType="center"
diff --git a/vlc-android/res/values-sw600dp/styles.xml b/vlc-android/res/values-sw600dp/styles.xml
new file mode 100644
index 0000000..e101bd4
--- /dev/null
+++ b/vlc-android/res/values-sw600dp/styles.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <!-- Playlist-->
+
+    <style name="PlaylistStyle">
+        <item name="android:layout_width">800dp</item>
+    </style>
+</resources>
\ No newline at end of file
diff --git a/vlc-android/res/values/styles.xml b/vlc-android/res/values/styles.xml
index a03561a..0e1bb16 100644
--- a/vlc-android/res/values/styles.xml
+++ b/vlc-android/res/values/styles.xml
@@ -256,4 +256,10 @@
     <style name="TipsFontStyle.Small" parent="TipsFontStyle">
       <item name="android:textSize">10sp</item>
     </style>
+
+    <!-- Playlist-->
+
+    <style name="PlaylistStyle">
+      <item name="android:layout_width">match_parent</item>
+    </style>
 </resources>
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
index cf3c02a..84cbc93 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
@@ -80,10 +80,10 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
 
     @Override
     public void onBindViewHolder(ViewHolder holder, int position) {
-        Context ctx = holder.itemView.getContext();
+        final Context ctx = holder.itemView.getContext();
         final MediaWrapper media = getItem(position);
         holder.binding.setMedia(media);
-        holder.binding.setSubTitle(MediaUtils.getMediaSubtitle(ctx, media));
+        holder.binding.setSubTitle(MediaUtils.getMediaSubtitle(media));
         holder.binding.setTitleColor(mCurrentIndex == position
                 ? UiTools.getColorFromAttribute(ctx, R.attr.list_title_last)
                 : UiTools.getColorFromAttribute(ctx, R.attr.list_title));
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
index ca88321..43e19c7 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
@@ -9,6 +9,7 @@ import android.database.Cursor;
 import android.net.Uri;
 import android.provider.MediaStore;
 import android.support.v4.content.LocalBroadcastManager;
+import android.text.TextUtils;
 
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.PlaybackService;
@@ -154,13 +155,17 @@ public class MediaUtils {
         return genre != null ? genre : getMediaString(ctx, R.string.unknown_genre);
     }
 
-    public static String getMediaSubtitle(Context ctx, MediaWrapper media) {
-        if (media.getType() == MediaWrapper.TYPE_AUDIO)
-            return media.getNowPlaying() != null
-                    ? media.getNowPlaying()
-                    : getMediaArtist(ctx, media) + " - " + getMediaAlbum(ctx, media);
-        else
-            return "";
+    public static String getMediaSubtitle(MediaWrapper media) {
+        String subtitle = media.getNowPlaying() != null
+                ? media.getNowPlaying()
+                : media.getArtist();
+        if (media.getLength() > 0L) {
+            if (TextUtils.isEmpty(subtitle))
+                subtitle = Strings.millisToString(media.getLength());
+            else
+                subtitle = subtitle + "  -  " +  Strings.millisToString(media.getLength());
+        }
+        return subtitle;
     }
 
     public static String getMediaTitle(MediaWrapper mediaWrapper){



More information about the Android mailing list