From b5e059531040c7edfc89028942d2daf3bbb2d5d7 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 28 May 2013 19:16:50 -0700 Subject: Support for sorting by disc number --- .../daneren2005/dsub/domain/MusicDirectory.java | 47 +++++++++++++++++++++- .../dsub/service/parser/MusicDirectoryParser.java | 1 + 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'subsonic-android/src/github') diff --git a/subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java b/subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java index 185fc17f..14cb6694 100644 --- a/subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java +++ b/subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java @@ -21,6 +21,8 @@ package github.daneren2005.dsub.domain; import java.util.ArrayList; import java.util.List; import java.io.Serializable; +import java.util.Collections; +import java.util.Comparator; /** * @author Sindre Mehus @@ -28,7 +30,7 @@ import java.io.Serializable; public class MusicDirectory { private String name; - private final List children = new ArrayList(); + private List children = new ArrayList(); public String getName() { return name; @@ -59,6 +61,10 @@ public class MusicDirectory { } return result; } + + public void sortChildren() { + EntryComparator.sort(children); + } public static class Entry implements Serializable { private String id; @@ -283,4 +289,43 @@ public class MusicDirectory { return title; } } + + public static class EntryComparator implements Comparator { + public int compare(Entry lhs, Entry rhs) { + Integer lhsDisc = lhs.getDiscNumber(); + Integer rhsDisc = rhs.getDiscNumber(); + + if(lhsDisc != null && rhsDisc != null) { + if(lhsDisc < rhsDisc) { + return -1; + } else if(lhsDisc > rhsDisc) { + return 1; + } + } else if(lhsDisc != null) { + return 1; + } else if(rhsDisc != null) { + return -1; + } + + Integer lhsTrack = lhs.getTrack(); + Integer rhsTrack = rhs.getTrack(); + if(lhsTrack != null && rhsTrack != null) { + if(lhsTrack < rhsTrack) { + return -1; + } else if(lhsTrack > rhsTrack) { + return 1; + } + } else if(lhsDisc != null) { + return 1; + } else if(rhsDisc != null) { + return -1; + } + + return lhs.getTitle().compareToIgnoreCase(rhs.getTitle()); + } + + public static void sort(List entries) { + Collections.sort(entries, new EntryComparator()); + } + } } \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java b/subsonic-android/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java index 370df305..0bf6ded1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java @@ -62,6 +62,7 @@ public class MusicDirectoryParser extends MusicDirectoryEntryParser { validate(); updateProgress(progressListener, R.string.parser_reading_done); + dir.sortChildren(); long t1 = System.currentTimeMillis(); Log.d(TAG, "Got music directory in " + (t1 - t0) + "ms."); -- cgit v1.2.3