diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-06-03 06:45:20 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-06-03 06:45:20 -0700 |
commit | 67bcb7bea9d8df747db55a692bb5c65f4a124916 (patch) | |
tree | 01773a25e72c5f979c19fc40d3bab56871644f72 /subsonic-android | |
parent | 4ded97251b07b1be8be0aaeeba1084a5bfba08e0 (diff) | |
download | dsub-67bcb7bea9d8df747db55a692bb5c65f4a124916.tar.gz dsub-67bcb7bea9d8df747db55a692bb5c65f4a124916.tar.bz2 dsub-67bcb7bea9d8df747db55a692bb5c65f4a124916.zip |
Fix for some edge cases in sorting, surround with try/catch to never bother user if it fails
Diffstat (limited to 'subsonic-android')
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java | 24 |
1 files 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<Entry> { 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<Entry> 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 |