diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 1fa7f8f28..534b9df50 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -59,7 +59,27 @@ 1.85 1.90 1.95 - 2.0 + 2.00 + 2.10 + 2.20 + 2.30 + 2.40 + 2.50 + 2.60 + 2.70 + 2.80 + 2.90 + 3.00 + 3.10 + 3.20 + 3.30 + 3.40 + 3.50 + 3.60 + 3.70 + 3.80 + 3.90 + 4.00 diff --git a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java index a84e5b8f2..a5104426c 100644 --- a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -428,8 +428,7 @@ public class AudioplayerActivity extends MediaplayerActivity { break; } } - UserPreferences.setPlaybackSpeed(AudioplayerActivity.this, - newSpeed); + UserPreferences.setPlaybackSpeed(newSpeed); controller.setPlaybackSpeed(Float.parseFloat(newSpeed)); } } diff --git a/src/de/danoeh/antennapod/dialog/VariableSpeedDialog.java b/src/de/danoeh/antennapod/dialog/VariableSpeedDialog.java index 308235f95..bcff905d9 100644 --- a/src/de/danoeh/antennapod/dialog/VariableSpeedDialog.java +++ b/src/de/danoeh/antennapod/dialog/VariableSpeedDialog.java @@ -85,8 +85,7 @@ public class VariableSpeedDialog { } } - UserPreferences.setPlaybackSpeedArray(context, - newSpeedValues); + UserPreferences.setPlaybackSpeedArray(newSpeedValues); } }); diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index b2c1927b4..8ee03527a 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -2,6 +2,8 @@ package de.danoeh.antennapod.preferences; import java.io.File; import java.io.IOException; +import java.util.LinkedList; +import java.util.List; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; @@ -89,6 +91,7 @@ public class UserPreferences implements createNoMediaFile(); PreferenceManager.getDefaultSharedPreferences(context) .registerOnSharedPreferenceChangeListener(instance); + } private void loadPreferences() { @@ -145,17 +148,25 @@ public class UserPreferences implements } private String[] readPlaybackSpeedArray(String valueFromPrefs) { - String[] playbackSpeeds = null; - // If this preference hasn't been set yet, return all options + String[] selectedSpeeds = null; + // If this preference hasn't been set yet, return the default options if (valueFromPrefs == null) { - playbackSpeeds = context.getResources().getStringArray( + String[] allSpeeds = context.getResources().getStringArray( R.array.playback_speed_values); + List speedList = new LinkedList(); + for (String speedStr : allSpeeds) { + float speed = Float.parseFloat(speedStr); + if (speed < 2.0001 && speed * 10 % 1 == 0) { + speedList.add(speedStr); + } + } + selectedSpeeds = speedList.toArray(new String[speedList.size()]); } else { try { JSONArray jsonArray = new JSONArray(valueFromPrefs); - playbackSpeeds = new String[jsonArray.length()]; + selectedSpeeds = new String[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { - playbackSpeeds[i] = jsonArray.getString(i); + selectedSpeeds[i] = jsonArray.getString(i); } } catch (JSONException e) { Log.e(TAG, @@ -163,7 +174,7 @@ public class UserPreferences implements e.printStackTrace(); } } - return playbackSpeeds; + return selectedSpeeds; } private static void instanceAvailable() { @@ -299,24 +310,19 @@ public class UserPreferences implements } } - public static void setPlaybackSpeed(Context context, String speed) { - SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(context.getApplicationContext()); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(PREF_PLAYBACK_SPEED, speed); - editor.apply(); + public static void setPlaybackSpeed(String speed) { + PreferenceManager.getDefaultSharedPreferences(instance.context).edit() + .putString(PREF_PLAYBACK_SPEED, speed).apply(); } - public static void setPlaybackSpeedArray(Context context, String[] speeds) { - SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(context.getApplicationContext()); - SharedPreferences.Editor editor = prefs.edit(); + public static void setPlaybackSpeedArray(String[] speeds) { JSONArray jsonArray = new JSONArray(); for (String speed : speeds) { jsonArray.put(speed); } - editor.putString(PREF_PLAYBACK_SPEED_ARRAY, jsonArray.toString()); - editor.apply(); + PreferenceManager.getDefaultSharedPreferences(instance.context).edit() + .putString(PREF_PLAYBACK_SPEED_ARRAY, jsonArray.toString()) + .apply(); } public static void setAutodownloadSelectedNetworks(Context context,