summaryrefslogtreecommitdiff
path: root/model/src/main
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2022-04-25 22:45:47 +0200
committerByteHamster <info@bytehamster.com>2022-04-26 17:57:42 +0200
commit069a2ca329a342ad0559a48719f49264d2610f00 (patch)
tree59cc8327dec62ddfd105d1ad2fdb59dcba12736e /model/src/main
parent20363ee41c814b14b16999505fa850a0943346dd (diff)
downloadAntennaPod-069a2ca329a342ad0559a48719f49264d2610f00.zip
Decouple preferences
Diffstat (limited to 'model/src/main')
-rw-r--r--model/src/main/java/de/danoeh/antennapod/model/download/ProxyConfig.java24
-rw-r--r--model/src/main/java/de/danoeh/antennapod/model/feed/SubscriptionsFilter.java121
2 files changed, 145 insertions, 0 deletions
diff --git a/model/src/main/java/de/danoeh/antennapod/model/download/ProxyConfig.java b/model/src/main/java/de/danoeh/antennapod/model/download/ProxyConfig.java
new file mode 100644
index 000000000..4e194b341
--- /dev/null
+++ b/model/src/main/java/de/danoeh/antennapod/model/download/ProxyConfig.java
@@ -0,0 +1,24 @@
+package de.danoeh.antennapod.model.download;
+
+import androidx.annotation.Nullable;
+
+import java.net.Proxy;
+
+public class ProxyConfig {
+
+ public final Proxy.Type type;
+ @Nullable public final String host;
+ public final int port;
+ @Nullable public final String username;
+ @Nullable public final String password;
+
+ public static final int DEFAULT_PORT = 8080;
+
+ public ProxyConfig(Proxy.Type type, String host, int port, String username, String password) {
+ this.type = type;
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ }
+} \ No newline at end of file
diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/SubscriptionsFilter.java b/model/src/main/java/de/danoeh/antennapod/model/feed/SubscriptionsFilter.java
new file mode 100644
index 000000000..434d474a7
--- /dev/null
+++ b/model/src/main/java/de/danoeh/antennapod/model/feed/SubscriptionsFilter.java
@@ -0,0 +1,121 @@
+package de.danoeh.antennapod.model.feed;
+
+import android.text.TextUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class SubscriptionsFilter {
+ private static final String divider = ",";
+
+ private final String[] properties;
+
+ private boolean showIfCounterGreaterZero = false;
+
+ private boolean showAutoDownloadEnabled = false;
+ private boolean showAutoDownloadDisabled = false;
+
+ private boolean showUpdatedEnabled = false;
+ private boolean showUpdatedDisabled = false;
+
+ private boolean showEpisodeNotificationEnabled = false;
+ private boolean showEpisodeNotificationDisabled = false;
+
+ public SubscriptionsFilter(String properties) {
+ this(TextUtils.split(properties, divider));
+ }
+
+
+ public SubscriptionsFilter(String[] properties) {
+ this.properties = properties;
+ for (String property : properties) {
+ // see R.arrays.feed_filter_values
+ switch (property) {
+ case "counter_greater_zero":
+ showIfCounterGreaterZero = true;
+ break;
+ case "enabled_auto_download":
+ showAutoDownloadEnabled = true;
+ break;
+ case "disabled_auto_download":
+ showAutoDownloadDisabled = true;
+ break;
+ case "enabled_updates":
+ showUpdatedEnabled = true;
+ break;
+ case "disabled_updates":
+ showUpdatedDisabled = true;
+ break;
+ case "episode_notification_enabled":
+ showEpisodeNotificationEnabled = true;
+ break;
+ case "episode_notification_disabled":
+ showEpisodeNotificationDisabled = true;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ public boolean isEnabled() {
+ return properties.length > 0;
+ }
+
+ /**
+ * Run a list of feed items through the filter.
+ */
+ public List<Feed> filter(List<Feed> items, Map<Long, Integer> feedCounters) {
+ if (properties.length == 0) {
+ return items;
+ }
+
+ List<Feed> result = new ArrayList<>();
+
+ for (Feed item : items) {
+ FeedPreferences itemPreferences = item.getPreferences();
+
+ // If the item does not meet a requirement, skip it.
+ if (showAutoDownloadEnabled && !itemPreferences.getAutoDownload()) {
+ continue;
+ } else if (showAutoDownloadDisabled && itemPreferences.getAutoDownload()) {
+ continue;
+ }
+
+ if (showUpdatedEnabled && !itemPreferences.getKeepUpdated()) {
+ continue;
+ } else if (showUpdatedDisabled && itemPreferences.getKeepUpdated()) {
+ continue;
+ }
+
+ if (showEpisodeNotificationEnabled && !itemPreferences.getShowEpisodeNotification()) {
+ continue;
+ } else if (showEpisodeNotificationDisabled && itemPreferences.getShowEpisodeNotification()) {
+ continue;
+ }
+
+ // If the item reaches here, it meets all criteria (except counter > 0)
+ result.add(item);
+ }
+
+ if (showIfCounterGreaterZero) {
+ for (int i = result.size() - 1; i >= 0; i--) {
+ if (!feedCounters.containsKey(result.get(i).getId())
+ || feedCounters.get(result.get(i).getId()) <= 0) {
+ result.remove(i);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public String[] getValues() {
+ return properties.clone();
+ }
+
+ public String serialize() {
+ return TextUtils.join(divider, getValues());
+ }
+}