diff options
Diffstat (limited to 'src/github')
-rw-r--r-- | src/github/daneren2005/dsub/domain/PodcastChannel.java | 33 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java | 2 |
2 files changed, 32 insertions, 3 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;
}
diff --git a/src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java b/src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java index 570ec423..bfdef7f2 100644 --- a/src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java +++ b/src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java @@ -62,6 +62,6 @@ public class PodcastChannelParser extends AbstractParser { } while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- return PodcastChannel.PodcastComparator.sort(channels);
+ return PodcastChannel.PodcastComparator.sort(channels, context);
}
}
|