aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2013-11-15 16:30:59 -0800
committerdaneren2005 <daneren2005@gmail.com>2013-11-15 16:30:59 -0800
commit857ca6b21dbdd7b2633303a0bae08dedb1dd0446 (patch)
tree8665fa467bcf81f28a2a80087abffb78f51040dc /src
parent6d6dc9efa87f85bbd6ce72d362d3de1ae41161d9 (diff)
downloaddsub-857ca6b21dbdd7b2633303a0bae08dedb1dd0446.tar.gz
dsub-857ca6b21dbdd7b2633303a0bae08dedb1dd0446.tar.bz2
dsub-857ca6b21dbdd7b2633303a0bae08dedb1dd0446.zip
Added ability to do sort by year in EntryComparator
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/domain/MusicDirectory.java31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/github/daneren2005/dsub/domain/MusicDirectory.java b/src/github/daneren2005/dsub/domain/MusicDirectory.java
index 0b9be5fb..724beed2 100644
--- a/src/github/daneren2005/dsub/domain/MusicDirectory.java
+++ b/src/github/daneren2005/dsub/domain/MusicDirectory.java
@@ -96,7 +96,10 @@ public class MusicDirectory implements Serializable {
}
public void sortChildren() {
- EntryComparator.sort(children);
+ EntryComparator.sort(children, false);
+ }
+ public void sortChildren(boolean sortByYear) {
+ EntryComparator.sort(children, sortByYear);
}
public static class Entry implements Serializable {
@@ -364,13 +367,33 @@ public class MusicDirectory implements Serializable {
}
public static class EntryComparator implements Comparator<Entry> {
+ private boolean sortByYear = false;
+
+ EntryComparator(boolean byYear) {
+ sortByYear = 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()) {
- return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
+ if(sortByYear) {
+ 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());
+ }
+ } else {
+ return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
+ }
}
Integer lhsDisc = lhs.getDiscNumber();
@@ -397,9 +420,9 @@ public class MusicDirectory implements Serializable {
return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
}
- public static void sort(List<Entry> entries) {
+ public static void sort(List<Entry> entries, boolean sortByYear) {
try {
- Collections.sort(entries, new EntryComparator());
+ Collections.sort(entries, new EntryComparator(sortByYear));
} catch (Exception e) {
Log.w(TAG, "Failed to sort MusicDirectory");
}