aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-10 15:56:44 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-10 15:56:44 -0700
commit45c668b341c92130c1060492676285ec26487575 (patch)
treefa0026245946c0afa18af8a15fa575a94144d0fd
parent5da225e72d03941961df49e1959d7bbeded4b2a4 (diff)
downloaddsub-45c668b341c92130c1060492676285ec26487575.tar.gz
dsub-45c668b341c92130c1060492676285ec26487575.tar.bz2
dsub-45c668b341c92130c1060492676285ec26487575.zip
Add a byYear option to do sort without byYear
-rw-r--r--src/github/daneren2005/dsub/domain/MusicDirectory.java33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/github/daneren2005/dsub/domain/MusicDirectory.java b/src/github/daneren2005/dsub/domain/MusicDirectory.java
index c284ba00..363a1540 100644
--- a/src/github/daneren2005/dsub/domain/MusicDirectory.java
+++ b/src/github/daneren2005/dsub/domain/MusicDirectory.java
@@ -422,23 +422,31 @@ public class MusicDirectory implements Serializable {
}
public static class EntryComparator implements Comparator<Entry> {
+ private boolean byYear;
+
+ public EntryComparator(boolean byYear) {
+ this.byYear = byYear;
+ }
+
public int compare(Entry lhs, Entry rhs) {
if(lhs.isDirectory() && !rhs.isDirectory()) {
return -1;
} else if(!lhs.isDirectory() && rhs.isDirectory()) {
return 1;
} else if(lhs.isDirectory() && rhs.isDirectory()) {
- Integer lhsYear = lhs.getYear();
- Integer rhsYear = rhs.getYear();
- if(lhsYear != null && rhsYear != null) {
- return lhsYear.compareTo(rhsYear);
- } else if(lhsYear != null) {
- return -1;
- } else if(rhsYear != null) {
- return 1;
- } else {
- return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
+ if(byYear) {
+ Integer lhsYear = lhs.getYear();
+ Integer rhsYear = rhs.getYear();
+ if(lhsYear != null && rhsYear != null) {
+ return lhsYear.compareTo(rhsYear);
+ } else if(lhsYear != null) {
+ return -1;
+ } else if(rhsYear != null) {
+ return 1;
+ }
}
+
+ return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
}
Integer lhsDisc = lhs.getDiscNumber();
@@ -466,8 +474,11 @@ public class MusicDirectory implements Serializable {
}
public static void sort(List<Entry> entries) {
+ sort(entries, true);
+ }
+ public static void sort(List<Entry> entries, boolean byYear) {
try {
- Collections.sort(entries, new EntryComparator());
+ Collections.sort(entries, new EntryComparator(byYear));
} catch (Exception e) {
Log.w(TAG, "Failed to sort MusicDirectory");
}