aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-05-28 19:16:50 -0700
committerScott Jackson <daneren2005@gmail.com>2013-05-28 19:16:50 -0700
commitb5e059531040c7edfc89028942d2daf3bbb2d5d7 (patch)
treecb5e62e99cb107bfc4138d37cf7c3f408a16fc63 /subsonic-android/src/github
parent3cf0694d2c83a1574f2e365cd89418bc8baaaa02 (diff)
downloaddsub-b5e059531040c7edfc89028942d2daf3bbb2d5d7.tar.gz
dsub-b5e059531040c7edfc89028942d2daf3bbb2d5d7.tar.bz2
dsub-b5e059531040c7edfc89028942d2daf3bbb2d5d7.zip
Support for sorting by disc number
Diffstat (limited to 'subsonic-android/src/github')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/domain/MusicDirectory.java47
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java1
2 files changed, 47 insertions, 1 deletions
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<Entry> children = new ArrayList<Entry>();
+ private List<Entry> children = new ArrayList<Entry>();
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<Entry> {
+ 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<Entry> 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.");