diff options
author | Erik Johnson <palehose@gmail.com> | 2023-02-22 14:34:43 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 21:34:43 +0100 |
commit | 9fed944392ee31f00ef91a01a2c34dddc876a86a (patch) | |
tree | 198a5618feacc5fbc847fae378bdaa6bbaec032c /app/src | |
parent | 5c79bc7c4541fbc0788d03adf3c56b483f96dcdb (diff) | |
download | AntennaPod-9fed944392ee31f00ef91a01a2c34dddc876a86a.zip |
Add "New Episodes Action" preference (#6095)
Diffstat (limited to 'app/src')
6 files changed, 60 insertions, 27 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java index aa2f1cf98..e8436a3a2 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java @@ -129,7 +129,8 @@ public class PlaybackServiceMediaPlayerTest { private Playable writeTestPlayable(String downloadUrl, String fileUrl) { Feed f = new Feed(0, null, "f", "l", "d", null, null, null, null, "i", null, null, "l", false); - FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NO, VolumeAdaptionSetting.OFF, null, null); + FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NEVER, + VolumeAdaptionSetting.OFF, FeedPreferences.NewEpisodesAction.NOTHING, null, null); f.setPreferences(prefs); f.setItems(new ArrayList<>()); FeedItem i = new FeedItem(0, "t", "i", "l", new Date(), FeedItem.UNPLAYED, f); 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 47c2e4dcd..b4195ba01 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java @@ -105,6 +105,7 @@ public class FeedSettingsFragment extends Fragment { private static final CharSequence PREF_AUTHENTICATION = "authentication"; private static final CharSequence PREF_AUTO_DELETE = "autoDelete"; private static final CharSequence PREF_CATEGORY_AUTO_DOWNLOAD = "autoDownloadCategory"; + private static final CharSequence PREF_NEW_EPISODES_ACTION = "feedNewEpisodesAction"; private static final String PREF_FEED_PLAYBACK_SPEED = "feedPlaybackSpeed"; private static final String PREF_AUTO_SKIP = "feedAutoSkip"; private static final String PREF_TAGS = "tags"; @@ -156,6 +157,7 @@ public class FeedSettingsFragment extends Fragment { setupKeepUpdatedPreference(); setupAutoDeletePreference(); setupVolumeReductionPreferences(); + setupNewEpisodesAction(); setupAuthentificationPreference(); setupEpisodeFilterPreference(); setupPlaybackSpeedPreference(); @@ -166,6 +168,7 @@ public class FeedSettingsFragment extends Fragment { updateAutoDeleteSummary(); updateVolumeReductionValue(); updateAutoDownloadEnabled(); + updateNewEpisodesAction(); if (feed.isLocalFeed()) { findPreference(PREF_AUTHENTICATION).setVisible(false); @@ -283,11 +286,12 @@ public class FeedSettingsFragment extends Fragment { feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.GLOBAL); break; case "always": - feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.YES); + feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.ALWAYS); break; case "never": - feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.NO); + feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.NEVER); break; + default: } DBWriter.setFeedPreferences(feedPreferences); updateAutoDeleteSummary(); @@ -300,14 +304,14 @@ public class FeedSettingsFragment extends Fragment { switch (feedPreferences.getAutoDeleteAction()) { case GLOBAL: - autoDeletePreference.setSummary(R.string.feed_auto_download_global); + autoDeletePreference.setSummary(R.string.global_default); autoDeletePreference.setValue("global"); break; - case YES: + case ALWAYS: autoDeletePreference.setSummary(R.string.feed_auto_download_always); autoDeletePreference.setValue("always"); break; - case NO: + case NEVER: autoDeletePreference.setSummary(R.string.feed_auto_download_never); autoDeletePreference.setValue("never"); break; @@ -327,6 +331,7 @@ public class FeedSettingsFragment extends Fragment { case "heavy": feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.HEAVY_REDUCTION); break; + default: } DBWriter.setFeedPreferences(feedPreferences); updateVolumeReductionValue(); @@ -352,6 +357,34 @@ public class FeedSettingsFragment extends Fragment { } } + private void setupNewEpisodesAction() { + findPreference(PREF_NEW_EPISODES_ACTION).setOnPreferenceChangeListener((preference, newValue) -> { + int code = Integer.parseInt((String) newValue); + feedPreferences.setNewEpisodesAction(FeedPreferences.NewEpisodesAction.fromCode(code)); + DBWriter.setFeedPreferences(feedPreferences); + updateNewEpisodesAction(); + return false; + }); + } + + private void updateNewEpisodesAction() { + ListPreference newEpisodesAction = findPreference(PREF_NEW_EPISODES_ACTION); + newEpisodesAction.setValue("" + feedPreferences.getNewEpisodesAction().code); + + switch (feedPreferences.getNewEpisodesAction()) { + case GLOBAL: + newEpisodesAction.setSummary(R.string.global_default); + break; + case ADD_TO_INBOX: + newEpisodesAction.setSummary(R.string.feed_new_episodes_action_add_to_inbox); + break; + case NOTHING: + newEpisodesAction.setSummary(R.string.feed_new_episodes_action_nothing); + break; + default: + } + } + private void setupKeepUpdatedPreference() { SwitchPreferenceCompat pref = findPreference("keepUpdated"); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java b/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java index 203a64c32..bbe78f4a2 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java @@ -89,28 +89,12 @@ public class FeedMultiSelectActionHandler { private void autoDeleteEpisodesPrefHandler() { PreferenceListDialog preferenceListDialog = new PreferenceListDialog(activity, - "Auto delete episodes"); + activity.getString(R.string.auto_delete_label)); String[] items = activity.getResources().getStringArray(R.array.spnAutoDeleteItems); - String[] values = activity.getResources().getStringArray(R.array.spnAutoDeleteValues); preferenceListDialog.openDialog(items); preferenceListDialog.setOnPreferenceChangedListener(which -> { - FeedPreferences.AutoDeleteAction autoDeleteAction = null; - switch (values[which]) { - case "global": - autoDeleteAction = FeedPreferences.AutoDeleteAction.GLOBAL; - break; - case "always": - autoDeleteAction = FeedPreferences.AutoDeleteAction.YES; - break; - case "never": - autoDeleteAction = FeedPreferences.AutoDeleteAction.NO; - break; - default: - } - FeedPreferences.AutoDeleteAction finalAutoDeleteAction = autoDeleteAction; - saveFeedPreferences(feedPreferences -> { - feedPreferences.setAutoDeleteAction(finalAutoDeleteAction); - }); + FeedPreferences.AutoDeleteAction autoDeleteAction = FeedPreferences.AutoDeleteAction.fromCode(which); + saveFeedPreferences(feedPreferences -> feedPreferences.setAutoDeleteAction(autoDeleteAction)); }); } diff --git a/app/src/main/res/layout/playback_speed_feed_setting_dialog.xml b/app/src/main/res/layout/playback_speed_feed_setting_dialog.xml index 572096911..48d69e4a9 100644 --- a/app/src/main/res/layout/playback_speed_feed_setting_dialog.xml +++ b/app/src/main/res/layout/playback_speed_feed_setting_dialog.xml @@ -10,7 +10,7 @@ android:id="@+id/useGlobalCheckbox" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/feed_auto_download_global" + android:text="@string/global_default" android:layout_marginBottom="8dp" /> <LinearLayout diff --git a/app/src/main/res/xml/feed_settings.xml b/app/src/main/res/xml/feed_settings.xml index a2ea42f01..619ab6296 100644 --- a/app/src/main/res/xml/feed_settings.xml +++ b/app/src/main/res/xml/feed_settings.xml @@ -45,7 +45,7 @@ android:entryValues="@array/spnAutoDeleteValues" android:icon="@drawable/ic_delete" android:key="autoDelete" - android:summary="@string/feed_auto_download_global" + android:summary="@string/global_default" android:title="@string/auto_delete_label" /> <de.danoeh.antennapod.preferences.MaterialListPreference @@ -57,6 +57,14 @@ android:summary="@string/feed_volume_reduction_summary" android:title="@string/feed_volume_reduction" /> + <de.danoeh.antennapod.preferences.MaterialListPreference + android:entries="@array/feedNewEpisodesActionItems" + android:entryValues="@array/feedNewEpisodesActionValues" + android:icon="@drawable/ic_feed" + android:key="feedNewEpisodesAction" + android:summary="@string/global_default" + android:title="@string/pref_new_episodes_action_title" /> + <PreferenceCategory android:key="autoDownloadCategory" android:title="@string/auto_download_settings_label"> diff --git a/app/src/main/res/xml/preferences_network.xml b/app/src/main/res/xml/preferences_network.xml index 428c891ad..83929bb70 100644 --- a/app/src/main/res/xml/preferences_network.xml +++ b/app/src/main/res/xml/preferences_network.xml @@ -13,6 +13,13 @@ android:key="prefAutoDownloadSettings" android:title="@string/pref_automatic_download_title" search:ignore="true" /> + <de.danoeh.antennapod.preferences.MaterialListPreference + android:entryValues="@array/globalNewEpisodesActionValues" + android:entries="@array/globalNewEpisodesActionItems" + android:key="prefNewEpisodesAction" + android:title="@string/pref_new_episodes_action_title" + android:summary="@string/pref_new_episodes_action_sum" + android:defaultValue="1"/> </PreferenceCategory> <PreferenceCategory android:title="@string/download_pref_details"> |