aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005/dsub/domain/PodcastChannel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/github/daneren2005/dsub/domain/PodcastChannel.java')
-rw-r--r--src/github/daneren2005/dsub/domain/PodcastChannel.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/github/daneren2005/dsub/domain/PodcastChannel.java b/src/github/daneren2005/dsub/domain/PodcastChannel.java
index 8549b06d..912b0e29 100644
--- a/src/github/daneren2005/dsub/domain/PodcastChannel.java
+++ b/src/github/daneren2005/dsub/domain/PodcastChannel.java
@@ -18,7 +18,16 @@
*/
package github.daneren2005.dsub.domain;
+import android.content.Context;
+import android.content.SharedPreferences;
+
import java.io.Serializable;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.Util;
/**
*
@@ -79,12 +88,32 @@ public class PodcastChannel implements Serializable {
}
public static class PodcastComparator implements Comparator<PodcastChannel> {
+ private static String[] ignoredArticles;
+
@Override
public int compare(PodcastChannel podcast1, PodcastChannel podcast2) {
- return podcast1.getName().compareToIgnoreCase(podcast2.getName());
+ String lhs = podcast1.getName().toLowerCase();
+ String rhs = podcast2.getName().toLowerCase();
+
+ for(String article: ignoredArticles) {
+ int index = lhs.indexOf(article.toLowerCase() + " ");
+ if(index == 0) {
+ lhs = lhs.substring(article.length() + 1);
+ }
+ index = rhs.indexOf(article.toLowerCase() + " ");
+ if(index == 0) {
+ rhs = rhs.substring(article.length() + 1);
+ }
+ }
+
+ return lhs.compareToIgnoreCase(rhs);
}
- public static List<PodcastChannel> sort(List<PodcastChannel> podcasts) {
+ public static List<PodcastChannel> sort(List<PodcastChannel> podcasts, Context context) {
+ SharedPreferences prefs = Util.getPreferences(context);
+ String ignoredArticlesString = prefs.getString(Constants.CACHE_KEY_IGNORE, "The El La Los Las Le Les");
+ ignoredArticles = ignoredArticlesString.split(" ");
+
Collections.sort(podcasts, new PodcastComparator());
return podcasts;
}