From 45c668b341c92130c1060492676285ec26487575 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 10 Jul 2014 15:56:44 -0700 Subject: Add a byYear option to do sort without byYear --- .../daneren2005/dsub/domain/MusicDirectory.java | 33 ++++++++++++++-------- 1 file 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 { + 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 entries) { + sort(entries, true); + } + public static void sort(List 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"); } -- cgit v1.2.3