diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-07-10 15:56:44 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-07-10 15:56:44 -0700 |
commit | 45c668b341c92130c1060492676285ec26487575 (patch) | |
tree | fa0026245946c0afa18af8a15fa575a94144d0fd | |
parent | 5da225e72d03941961df49e1959d7bbeded4b2a4 (diff) | |
download | dsub-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.java | 33 |
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"); } |