From 67bcb7bea9d8df747db55a692bb5c65f4a124916 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 3 Jun 2013 06:45:20 -0700 Subject: Fix for some edge cases in sorting, surround with try/catch to never bother user if it fails --- .../daneren2005/dsub/domain/MusicDirectory.java | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java b/subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java index 153c590e..10e9ef22 100644 --- a/subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java +++ b/subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java @@ -18,6 +18,7 @@ */ package github.daneren2005.dsub.domain; +import android.util.Log; import java.util.ArrayList; import java.util.List; import java.io.Serializable; @@ -28,6 +29,7 @@ import java.util.Comparator; * @author Sindre Mehus */ public class MusicDirectory { + private static final String TAG = MusicDirectory.class.getSimpleName(); private String name; private String id; @@ -319,6 +321,12 @@ public class MusicDirectory { public static class EntryComparator implements Comparator { public int compare(Entry lhs, Entry rhs) { + if(lhs.isDirectory() && !rhs.isDirectory()) { + return -1; + } else if(!lhs.isDirectory() && rhs.isDirectory()) { + return 1; + } + Integer lhsDisc = lhs.getDiscNumber(); Integer rhsDisc = rhs.getDiscNumber(); @@ -329,9 +337,9 @@ public class MusicDirectory { return 1; } } else if(lhsDisc != null) { - return 1; - } else if(rhsDisc != null) { return -1; + } else if(rhsDisc != null) { + return 1; } Integer lhsTrack = lhs.getTrack(); @@ -342,17 +350,21 @@ public class MusicDirectory { } else if(lhsTrack > rhsTrack) { return 1; } - } else if(lhsDisc != null) { - return 1; - } else if(rhsDisc != null) { + } else if(lhsTrack != null) { return -1; + } else if(rhsTrack != null) { + return 1; } return lhs.getTitle().compareToIgnoreCase(rhs.getTitle()); } public static void sort(List entries) { - Collections.sort(entries, new EntryComparator()); + try { + Collections.sort(entries, new EntryComparator()); + } catch (Exception e) { + Log.w(TAG, "Failed to sort MusicDirectory"); + } } } } \ No newline at end of file -- cgit v1.2.3