summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorrecalculated <recalculated@users.noreply.github.com>2016-01-23 20:16:53 -0600
committerrecalculated <recalculated@users.noreply.github.com>2016-01-23 20:25:08 -0600
commit9ef3c99899196538baa446db869c2ac23c15cb99 (patch)
treee01d5b88525bad828aae96208e4389f7cb3c6f99 /core/src
parent7e9e3bb9468c4829bac94fc5d3f8165d86d02bdb (diff)
downloadAntennaPod-9ef3c99899196538baa446db869c2ac23c15cb99.zip
Use positive/reverse filtering
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilter.java76
-rw-r--r--core/src/main/res/values/arrays.xml4
3 files changed, 48 insertions, 34 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
index 0de046fe5..4be788f33 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
@@ -544,7 +544,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
return itemfilter;
}
- public void setHiddenItemProperties(String[] properties) {
+ public void setItemFilter(String[] properties) {
if (properties != null) {
this.itemfilter = new FeedItemFilter(properties);
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilter.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilter.java
index 8636ac50a..33f5cf504 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilter.java
@@ -8,73 +8,87 @@ import java.util.List;
import de.danoeh.antennapod.core.storage.DBReader;
public class FeedItemFilter {
+ private final String[] mProperties;
- private final String[] properties;
-
- private boolean hideUnplayed = false;
- private boolean hidePaused = false;
- private boolean hidePlayed = false;
- private boolean hideQueued = false;
- private boolean hideNotQueued = false;
- private boolean hideDownloaded = false;
- private boolean hideNotDownloaded = false;
+ private boolean showPlayed = false;
+ private boolean showUnplayed = false;
+ private boolean showPaused = false;
+ private boolean showQueued = false;
+ private boolean showNotQueued = false;
+ private boolean showDownloaded = false;
+ private boolean showNotDownloaded = false;
public FeedItemFilter(String properties) {
this(TextUtils.split(properties, ","));
}
public FeedItemFilter(String[] properties) {
- this.properties = properties;
+ this.mProperties = properties;
for(String property : properties) {
// see R.arrays.feed_filter_values
switch(property) {
case "unplayed":
- hideUnplayed = true;
+ showUnplayed = true;
break;
case "paused":
- hidePaused = true;
+ showPaused = true;
break;
case "played":
- hidePlayed = true;
+ showPlayed = true;
break;
case "queued":
- hideQueued = true;
+ showQueued = true;
break;
case "not_queued":
- hideNotQueued = true;
+ showNotQueued = true;
break;
case "downloaded":
- hideDownloaded = true;
+ showDownloaded = true;
break;
case "not_downloaded":
- hideNotDownloaded = true;
+ showNotDownloaded = true;
break;
}
}
}
+ /**
+ * Run a list of feed items through the filter.
+ */
public List<FeedItem> filter(List<FeedItem> items) {
- if(properties.length == 0) {
- return items;
- }
- List<FeedItem> result = new ArrayList<FeedItem>();
+ if(mProperties.length == 0) return items;
+
+ List<FeedItem> result = new ArrayList<>();
+
+ // Check for filter combinations that will always return an empty list
+ // (e.g. requiring played and unplayed at the same time)
+ if (showPlayed && showUnplayed) return result;
+ if (showQueued && showNotQueued) return result;
+ if (showDownloaded && showNotDownloaded) return result;
+
for(FeedItem item : items) {
- if(hideUnplayed && false == item.isPlayed()) continue;
- if(hidePaused && item.getState() == FeedItem.State.IN_PROGRESS) continue;
- if(hidePlayed && item.isPlayed()) continue;
- boolean isQueued = DBReader.getQueueIDList().contains(item.getId());
- if(hideQueued && isQueued) continue;
- if(hideNotQueued && false == isQueued) continue;
- boolean isDownloaded = item.getMedia() != null && item.getMedia().isDownloaded();
- if(hideDownloaded && isDownloaded) continue;
- if(hideNotDownloaded && false == isDownloaded) continue;
+ // If the item does not meet a requirement, skip it.
+ if (showPlayed && !item.isPlayed()) continue;
+ if (showUnplayed && item.isPlayed()) continue;
+ if (showPaused && item.getState() != FeedItem.State.IN_PROGRESS) continue;
+
+ boolean queued = DBReader.getQueueIDList().contains(item.getId());
+ if (showQueued && !queued) continue;
+ if (showNotQueued && queued) continue;
+
+ boolean downloaded = item.getMedia() != null & item.getMedia().isDownloaded();
+ if (showDownloaded && !downloaded) continue;
+ if (showNotDownloaded && downloaded) continue;
+
+ // If the item reaches here, it meets all criteria
result.add(item);
}
+
return result;
}
public String[] getValues() {
- return properties.clone();
+ return mProperties.clone();
}
}
diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml
index 55da0ee04..0de515292 100644
--- a/core/src/main/res/values/arrays.xml
+++ b/core/src/main/res/values/arrays.xml
@@ -175,7 +175,7 @@
<item>3</item>
</string-array>
- <string-array name="episode_hide_options">
+ <string-array name="episode_filter_options">
<item>@string/hide_unplayed_episodes_label</item>
<item>@string/hide_paused_episodes_label</item>
<item>@string/hide_played_episodes_label</item>
@@ -185,7 +185,7 @@
<item>@string/hide_not_downloaded_episodes_label</item>
</string-array>
- <string-array name="episode_hide_values">
+ <string-array name="episode_filter_values">
<item>unplayed</item>
<item>paused</item>
<item>played</item>