summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java13
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackPreferencesFragment.java52
-rw-r--r--app/src/main/res/xml/preferences_playback.xml19
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java26
-rw-r--r--core/src/main/res/values/arrays.xml13
-rw-r--r--core/src/main/res/values/strings.xml9
6 files changed, 93 insertions, 39 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java
index 65bc7d745..6f541e5cf 100644
--- a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java
@@ -4,13 +4,13 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
-import androidx.test.filters.LargeTest;
+import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
+
import com.robotium.solo.Solo;
import com.robotium.solo.Timeout;
-import de.test.antennapod.EspressoTestUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -28,6 +28,7 @@ import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
import de.danoeh.antennapod.fragment.EpisodesFragment;
import de.danoeh.antennapod.fragment.QueueFragment;
import de.danoeh.antennapod.fragment.SubscriptionFragment;
+import de.test.antennapod.EspressoTestUtils;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.espresso.Espresso.onView;
@@ -126,13 +127,9 @@ public class PreferencesTest {
}
@Test
- public void testEnqueueAtFront() {
+ public void testEnqueueLocation() {
clickPreference(R.string.playback_pref);
- final boolean enqueueAtFront = UserPreferences.enqueueAtFront();
- clickPreference(R.string.pref_queueAddToFront_title);
- assertTrue(solo.waitForCondition(() -> enqueueAtFront != UserPreferences.enqueueAtFront(), Timeout.getLargeTimeout()));
- clickPreference(R.string.pref_queueAddToFront_title);
- assertTrue(solo.waitForCondition(() -> enqueueAtFront == UserPreferences.enqueueAtFront(), Timeout.getLargeTimeout()));
+ // TODO-2652: implement the test
}
@Test
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackPreferencesFragment.java
index 64ac1b8ed..5d9af14bd 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackPreferencesFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackPreferencesFragment.java
@@ -4,8 +4,15 @@ import android.app.Activity;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
+
+import androidx.annotation.NonNull;
+import androidx.collection.ArrayMap;
import androidx.preference.ListPreference;
+import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
+
+import java.util.Map;
+
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MediaplayerActivity;
import de.danoeh.antennapod.activity.PreferenceActivity;
@@ -64,19 +71,42 @@ public class PlaybackPreferencesFragment extends PreferenceFragmentCompat {
behaviour.setEntryValues(R.array.video_background_behavior_values_without_pip);
}
- findPreference(UserPreferences.PREF_QUEUE_ADD_TO_FRONT).setOnPreferenceChangeListener(
- (preference, newValue) -> {
- if (newValue instanceof Boolean) {
- boolean enableKeepInProgressAtFront = ((Boolean) newValue);
- checkKeepInProgressAtFrontItemVisibility(enableKeepInProgressAtFront);
- }
- return true;
- });
- checkKeepInProgressAtFrontItemVisibility(UserPreferences.enqueueAtFront());
+ buildEnqueueLocationPreference();
+ }
+
+ private void buildEnqueueLocationPreference() {
+ final Resources res = requireActivity().getResources();
+ final Map<String, String> options = new ArrayMap<>();
+ {
+ String[] keys = res.getStringArray(R.array.enqueue_location_values);
+ String[] values = res.getStringArray(R.array.enqueue_location_options);
+ for (int i = 0; i < keys.length; i++) {
+ options.put(keys[i], values[i]);
+ }
+ }
+
+ ListPreference pref = requirePreference(UserPreferences.PREF_ENQUEUE_LOCATION);
+ pref.setSummary(res.getString(R.string.pref_enqueue_location_sum, options.get(pref.getValue())));
+
+ pref.setOnPreferenceChangeListener((preference, newValue) -> {
+ if (!(newValue instanceof String)) {
+ return false;
+ }
+ String newValStr = (String)newValue;
+ pref.setSummary(res.getString(R.string.pref_enqueue_location_sum, options.get(newValStr)));
+ return true;
+ });
}
- private void checkKeepInProgressAtFrontItemVisibility(boolean enabled) {
- findPreference(UserPreferences.PREF_QUEUE_KEEP_IN_PROGESS_AT_FRONT).setEnabled(enabled);
+ @NonNull
+ private <T extends Preference> T requirePreference(@NonNull CharSequence key) {
+ // Possibly put it to a common method in abstract base class
+ T result = findPreference(key);
+ if (result == null) {
+ throw new IllegalArgumentException("Preference with key '" + key + "' is not found");
+
+ }
+ return result;
}
private void buildSmartMarkAsPlayedPreference() {
diff --git a/app/src/main/res/xml/preferences_playback.xml b/app/src/main/res/xml/preferences_playback.xml
index 44ecf32ec..254c907c5 100644
--- a/app/src/main/res/xml/preferences_playback.xml
+++ b/app/src/main/res/xml/preferences_playback.xml
@@ -90,18 +90,13 @@
android:key="prefEnqueueDownloaded"
android:summary="@string/pref_enqueue_downloaded_summary"
android:title="@string/pref_enqueue_downloaded_title" />
- <SwitchPreference
- android:defaultValue="false"
- android:enabled="true"
- android:key="prefQueueAddToFront"
- android:summary="@string/pref_queueAddToFront_sum"
- android:title="@string/pref_queueAddToFront_title"/>
- <SwitchPreference
- android:defaultValue="false"
- android:enabled="false"
- android:key="prefQueueKeepInProgressAtFront"
- android:summary="@string/pref_queueKeepInProgressAtFront_sum"
- android:title="@string/pref_queueKeepInProgressAtFront_title"/>
+ <ListPreference
+ android:defaultValue="BACK"
+ android:entries="@array/enqueue_location_options"
+ android:entryValues="@array/enqueue_location_values"
+ android:key="prefEnqueueLocation"
+ android:title="@string/pref_enqueue_location_title"
+ app:useStockLayout="true"/>
<SwitchPreference
android:defaultValue="true"
android:enabled="true"
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
index 16561779e..796848aaf 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
@@ -25,8 +25,8 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-import de.danoeh.antennapod.core.feed.MediaType;
import de.danoeh.antennapod.core.R;
+import de.danoeh.antennapod.core.feed.MediaType;
import de.danoeh.antennapod.core.service.download.ProxyConfig;
import de.danoeh.antennapod.core.storage.APCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
@@ -89,6 +89,7 @@ public class UserPreferences {
// Network
private static final String PREF_ENQUEUE_DOWNLOADED = "prefEnqueueDownloaded";
+ public static final String PREF_ENQUEUE_LOCATION = "prefEnqueueLocation";
public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall";
private static final String PREF_MOBILE_UPDATE = "prefMobileUpdateTypes";
public static final String PREF_EPISODE_CLEANUP = "prefEpisodeCleanup";
@@ -294,12 +295,29 @@ public class UserPreferences {
.apply();
}
- public static boolean enqueueAtFront() {
+ public enum EnqueueLocation {
+ BACK, FRONT, AFTER_CURRENTLY_PLAYING;
+ }
+
+ public static EnqueueLocation getEnqueueLocation() {
+ String valStr = prefs.getString(PREF_ENQUEUE_LOCATION, EnqueueLocation.BACK.name());
+ try {
+ return EnqueueLocation.valueOf(valStr);
+ } catch (Throwable t) {
+ // should never happen but just in case
+ Log.e(TAG, "getEnqueueLocation: invalid value '" + valStr + "' Use default.", t);
+ return EnqueueLocation.BACK;
+ }
+ }
+
+ // TODO-2652: migrate settings
+
+ public static boolean enqueueAtFront() { // TODO-2652: migrate to the new settings
return prefs.getBoolean(PREF_QUEUE_ADD_TO_FRONT, false);
}
@VisibleForTesting
- public static void setEnqueueAtFront(boolean enqueueAtFront) {
+ public static void setEnqueueAtFront(boolean enqueueAtFront) { // TODO-2652: migrate to the new settings
prefs.edit()
.putBoolean(PREF_QUEUE_ADD_TO_FRONT, enqueueAtFront)
.apply();
@@ -311,7 +329,7 @@ public class UserPreferences {
* in-progress, i.e., the user has played part of it, such item remains at the front of the
* queue; {@code false} otherwise.
*/
- public static boolean keepInProgressAtFront() {
+ public static boolean keepInProgressAtFront() { // TODO-2652: migrate to the new settings
return prefs.getBoolean(PREF_QUEUE_KEEP_IN_PROGESS_AT_FRONT, false);
}
diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml
index 2dd985d6a..3a6a45e6d 100644
--- a/core/src/main/res/values/arrays.xml
+++ b/core/src/main/res/values/arrays.xml
@@ -93,6 +93,19 @@
<item>@string/episode_cleanup_never</item>
</string-array>
+ <string-array name="enqueue_location_options">
+ <item>@string/enqueue_location_back</item>
+ <item>@string/enqueue_location_front</item>
+ <item>@string/enqueue_location_after_current</item>
+ </string-array>
+
+ <string-array name="enqueue_location_values">
+ <!-- MUST be the same as UserPreferences.EnqueueLocation enum -->
+ <item>BACK</item>
+ <item>FRONT</item>
+ <item>AFTER_CURRENTLY_PLAYING</item>
+ </string-array>
+
<string-array name="episode_cleanup_values">
<item>-1</item>
<item>0</item>
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index cf6bc620d..19fc3a81c 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -454,10 +454,11 @@
<string name="pref_showDownloadReport_title">Show Download Report</string>
<string name="pref_showDownloadReport_sum">If downloads fail, generate a report that shows the details of the failure.</string>
<string name="pref_expand_notify_unsupport_toast">Android versions before 4.1 do not support expanded notifications.</string>
- <string name="pref_queueAddToFront_sum">Add new episodes to the front of the queue.</string>
- <string name="pref_queueAddToFront_title">Enqueue at Front</string>
- <string name="pref_queueKeepInProgressAtFront_title">Keep In-progress Episode at Front</string>
- <string name="pref_queueKeepInProgressAtFront_sum">If the episode at front is in-progress, i.e., you have listened to part of it, keep it at the front of the queue.</string>
+ <string name="pref_enqueue_location_title">Enqueue Location</string>
+ <string name="pref_enqueue_location_sum">Add episodes to: %1$s.</string>
+ <string name="enqueue_location_back">back of the queue</string>
+ <string name="enqueue_location_front">front of the queue</string>
+ <string name="enqueue_location_after_current">after current episode</string>
<string name="pref_smart_mark_as_played_disabled">Disabled</string>
<string name="pref_image_cache_size_title">Image Cache Size</string>
<string name="pref_image_cache_size_sum">Size of the disk cache for images.</string>