#2652 the UI of a new setting enqueue location
- replaced existing enqueue at front
- the option after current episode will replace Keep In-Progress in Queue that was in the PR (30f104f4
).
This commit is contained in:
parent
406f1cceb8
commit
52521ecddb
|
@ -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
|
||||
|
|
|
@ -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 checkKeepInProgressAtFrontItemVisibility(boolean enabled) {
|
||||
findPreference(UserPreferences.PREF_QUEUE_KEEP_IN_PROGESS_AT_FRONT).setEnabled(enabled);
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@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() {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue