[Android] Sort media by type in TV Network Browser

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


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

Sort media by type in TV Network Browser

Group by first letter, sort by name but folders first

(cherry picked from commit b6044fc213a197e5bf77f72e615929e93df38050)
Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

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

 .../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 1c2dc3d..148a91f 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
@@ -160,7 +160,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