Add option to add new episodes to queue (#6855)

This commit is contained in:
Matej Drobnič 2024-02-25 16:11:30 +01:00 committed by GitHub
parent a7068cc24a
commit 7332c04631
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 12 deletions

View File

@ -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;

View File

@ -197,6 +197,7 @@ public final class DBTasks {
public static synchronized Feed updateFeed(Context context, Feed newFeed, boolean removeUnlistedItems) {
Feed resultFeed;
List<FeedItem> unlistedItems = new ArrayList<>();
List<FeedItem> 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) {

View File

@ -55,23 +55,27 @@
<string-array name="globalNewEpisodesActionItems">
<item>@string/feed_new_episodes_action_add_to_inbox</item>
<item>@string/feed_new_episodes_action_add_to_queue</item>
<item>@string/feed_new_episodes_action_nothing</item>
</string-array>
<string-array name="globalNewEpisodesActionValues">
<item>1</item>
<item>3</item>
<item>2</item>
</string-array>
<string-array name="feedNewEpisodesActionItems">
<item>@string/global_default</item>
<item>@string/feed_new_episodes_action_add_to_inbox</item>
<item>@string/feed_new_episodes_action_add_to_queue</item>
<item>@string/feed_new_episodes_action_nothing</item>
</string-array>
<string-array name="feedNewEpisodesActionValues">
<item>0</item>
<item>1</item>
<item>3</item>
<item>2</item>
</string-array>

View File

@ -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;

View File

@ -138,6 +138,7 @@
<string name="feed_auto_download_always">Always</string>
<string name="feed_auto_download_never">Never</string>
<string name="feed_new_episodes_action_add_to_inbox">Add to inbox</string>
<string name="feed_new_episodes_action_add_to_queue">Add to queue</string>
<string name="feed_new_episodes_action_nothing">Nothing</string>
<string name="episode_cleanup_never">Never</string>
<string name="episode_cleanup_except_favorite_removal">When not favorited</string>