From 7332c04631ee689c309363f17f14c4a6ed469c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Drobni=C4=8D?= Date: Sun, 25 Feb 2024 16:11:30 +0100 Subject: [PATCH] Add option to add new episodes to queue (#6855) --- .../fragment/FeedSettingsFragment.java | 3 ++ .../antennapod/core/storage/DBTasks.java | 36 ++++++++++++------- core/src/main/res/values/arrays.xml | 4 +++ .../model/feed/FeedPreferences.java | 1 + ui/i18n/src/main/res/values/strings.xml | 1 + 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java index 7e9c3d093..c42134165 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java @@ -421,6 +421,9 @@ public class FeedSettingsFragment extends Fragment { case ADD_TO_INBOX: newEpisodesAction.setSummary(R.string.feed_new_episodes_action_add_to_inbox); break; + case ADD_TO_QUEUE: + newEpisodesAction.setSummary(R.string.feed_new_episodes_action_add_to_queue); + break; case NOTHING: newEpisodesAction.setSummary(R.string.feed_new_episodes_action_nothing); break; diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java index d6a4fa1cb..840ce65f6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java @@ -197,6 +197,7 @@ public final class DBTasks { public static synchronized Feed updateFeed(Context context, Feed newFeed, boolean removeUnlistedItems) { Feed resultFeed; List unlistedItems = new ArrayList<>(); + List itemsToAddToQueue = new ArrayList<>(); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); @@ -290,18 +291,26 @@ public final class DBTasks { savedFeed.getItems().add(idx, item); } - FeedPreferences.NewEpisodesAction action = savedFeed.getPreferences().getNewEpisodesAction(); - if (action == FeedPreferences.NewEpisodesAction.GLOBAL) { - action = UserPreferences.getNewEpisodesAction(); - } - if (action == FeedPreferences.NewEpisodesAction.ADD_TO_INBOX - && (item.getPubDate() == null - || priorMostRecentDate == null - || priorMostRecentDate.before(item.getPubDate()) - || priorMostRecentDate.equals(item.getPubDate()))) { - Log.d(TAG, "Marking item published on " + item.getPubDate() - + " new, prior most recent date = " + priorMostRecentDate); - item.setNew(); + if (item.getPubDate() == null + || priorMostRecentDate == null + || priorMostRecentDate.before(item.getPubDate()) + || priorMostRecentDate.equals(item.getPubDate())) { + Log.d(TAG, "Performing new episode action for item published on " + item.getPubDate() + + ", prior most recent date = " + priorMostRecentDate); + FeedPreferences.NewEpisodesAction action = savedFeed.getPreferences().getNewEpisodesAction(); + if (action == FeedPreferences.NewEpisodesAction.GLOBAL) { + action = UserPreferences.getNewEpisodesAction(); + } + switch (action) { + case ADD_TO_INBOX: + item.setNew(); + break; + case ADD_TO_QUEUE: + itemsToAddToQueue.add(item); + break; + default: + break; + } } } } @@ -341,6 +350,9 @@ public final class DBTasks { e.printStackTrace(); } + // We need to add to queue after items are saved to database + DBWriter.addQueueItem(context, itemsToAddToQueue.toArray(new FeedItem[0])); + adapter.close(); if (savedFeed != null) { diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 2961339cd..a4f5d7f38 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -55,23 +55,27 @@ @string/feed_new_episodes_action_add_to_inbox + @string/feed_new_episodes_action_add_to_queue @string/feed_new_episodes_action_nothing 1 + 3 2 @string/global_default @string/feed_new_episodes_action_add_to_inbox + @string/feed_new_episodes_action_add_to_queue @string/feed_new_episodes_action_nothing 0 1 + 3 2 diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedPreferences.java b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedPreferences.java index 8e3dd48f6..39b6e2bdd 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedPreferences.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedPreferences.java @@ -40,6 +40,7 @@ public class FeedPreferences implements Serializable { public enum NewEpisodesAction { GLOBAL(0), ADD_TO_INBOX(1), + ADD_TO_QUEUE(3), NOTHING(2); public final int code; diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml index 2ec045a3d..03044a79d 100644 --- a/ui/i18n/src/main/res/values/strings.xml +++ b/ui/i18n/src/main/res/values/strings.xml @@ -138,6 +138,7 @@ Always Never Add to inbox + Add to queue Nothing Never When not favorited