[Android] Sort media by type in TV Network Browser

Geoffrey Métais git at videolan.org
Tue Dec 22 10:53:19 CET 2015


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 22 10:52:02 2015 +0100| [b6044fc213a197e5bf77f72e615929e93df38050] | committer: Geoffrey Métais

Sort media by type in TV Network Browser

Group by first letter, sort by name but folders first

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

 .../videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java  |  2 +-
 .../src/org/videolan/vlc/gui/helpers/MediaComparators.java   | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java b/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java
index d0f29c7..0225f04 100644
--- a/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java
+++ b/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java
@@ -153,7 +153,7 @@ public class NetworkBrowserFragment extends BrowseFragment implements BrowserFra
             public void run() {
                 mMediaItemMap = new TreeMap<>(mMediaItemMap); //sort sections
                 for (ListItem item : mMediaItemMap.values()) {
-                    Collections.sort(item.mediaList, MediaComparators.byName);
+                    Collections.sort(item.mediaList, MediaComparators.byFileType);
                 }
                 mHandler.sendEmptyMessage(UPDATE_DISPLAY);
             }
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/MediaComparators.java b/vlc-android/src/org/videolan/vlc/gui/helpers/MediaComparators.java
index 528a55f..b7e9a0b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/MediaComparators.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/MediaComparators.java
@@ -35,6 +35,18 @@ public class MediaComparators {
         return String.CASE_INSENSITIVE_ORDER.compare(s1, s2);
     }
 
+    public static final Comparator<MediaWrapper> byFileType = new Comparator<MediaWrapper>() {
+        @Override
+        public int compare(MediaWrapper m1, MediaWrapper m2) {
+            int t1 = m1.getType(), t2= m2.getType();
+            if (t1 == MediaWrapper.TYPE_DIR && t2 != MediaWrapper.TYPE_DIR)
+                return -1;
+            if (t1 != MediaWrapper.TYPE_DIR && t2 == MediaWrapper.TYPE_DIR)
+                return 1;
+            return nullInsensitiveStringCompare(m1.getTitle(), m2.getTitle());
+        };
+    };
+
     public static final Comparator<MediaWrapper> byName = new Comparator<MediaWrapper>() {
         @Override
         public int compare(MediaWrapper m1, MediaWrapper m2) {



More information about the Android mailing list