aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-12-09 21:38:00 -0800
committerScott Jackson <daneren2005@gmail.com>2013-12-09 21:38:00 -0800
commitad66a9397d5d1541fd47b4122daf955538d93c63 (patch)
tree63d25402a532d1acd2f607de869c2d42e28c5af1 /src
parentba093211085e586380d89c9213a4a59c8de9aa81 (diff)
downloaddsub-ad66a9397d5d1541fd47b4122daf955538d93c63.tar.gz
dsub-ad66a9397d5d1541fd47b4122daf955538d93c63.tar.bz2
dsub-ad66a9397d5d1541fd47b4122daf955538d93c63.zip
#213 Use ignored articles in podcast sort
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/domain/PodcastChannel.java33
-rw-r--r--src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java2
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);
}
}