Converted playback speed in media preferences to a float instead of String

This commit is contained in:
Jonas Kalderstam 2019-09-14 00:09:24 +02:00
parent 684213c291
commit 60eb41048f
6 changed files with 17 additions and 33 deletions

View File

@ -19,6 +19,7 @@ import de.danoeh.antennapod.dialog.EpisodeFilterDialog;
import de.danoeh.antennapod.viewmodel.FeedSettingsViewModel;
import static de.danoeh.antennapod.activity.FeedSettingsActivity.EXTRA_FEED_ID;
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
public class FeedSettingsFragment extends PreferenceFragmentCompat {
private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter";
@ -55,7 +56,7 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
String[] speeds = UserPreferences.getPlaybackSpeedArray();
String[] values = new String[speeds.length + 1];
values[0] = "global";
values[0] = Float.toString(SPEED_USE_GLOBAL);
String[] entries = new String[speeds.length + 1];
entries[0] = getString(R.string.feed_auto_download_global);
@ -67,7 +68,7 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
feedPlaybackSpeedPreference.setEntries(entries);
feedPlaybackSpeedPreference.setOnPreferenceChangeListener((preference, newValue) -> {
feedPreferences.setFeedPlaybackSpeed((String) newValue);
feedPreferences.setFeedPlaybackSpeed(Float.parseFloat((String) newValue));
feed.savePreferences();
updatePlaybackSpeedPreference();
return false;
@ -126,8 +127,8 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
private void updatePlaybackSpeedPreference() {
ListPreference feedPlaybackSpeedPreference = (ListPreference) findPreference(PREF_FEED_PLAYBACK_SPEED);
String speedValue = feedPreferences.getFeedPlaybackSpeed();
feedPlaybackSpeedPreference.setValue(speedValue);
float speedValue = feedPreferences.getFeedPlaybackSpeed();
feedPlaybackSpeedPreference.setValue(Float.toString(speedValue));
}
private void updateAutoDeleteSummary() {

View File

@ -603,7 +603,7 @@ public class QueueFragment extends Fragment {
float playbackSpeed = SPEED_USE_GLOBAL;
Feed feed = item.getFeed();
if (feed != null) {
playbackSpeed = feed.getPreferences().getCurrentPlaybackSpeed();
playbackSpeed = feed.getPreferences().getFeedPlaybackSpeed();
}
if (playbackSpeed == SPEED_USE_GLOBAL) {
playbackSpeed = UserPreferences.getPlaybackSpeed(item.getMedia());

View File

@ -652,7 +652,7 @@ public class FeedMedia extends FeedFile implements Playable {
if (item != null) {
Feed feed = item.getFeed();
if (feed != null) {
playbackSpeed = feed.getPreferences().getCurrentPlaybackSpeed();
playbackSpeed = feed.getPreferences().getFeedPlaybackSpeed();
}
}
}

View File

@ -30,13 +30,13 @@ public class FeedPreferences {
private AutoDeleteAction auto_delete_action;
private String username;
private String password;
private String feedPlaybackSpeed;
private float feedPlaybackSpeed;
public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction auto_delete_action, String username, String password) {
this(feedID, autoDownload, true, auto_delete_action, username, password, new FeedFilter(), "global");
this(feedID, autoDownload, true, auto_delete_action, username, password, new FeedFilter(), SPEED_USE_GLOBAL);
}
private FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction auto_delete_action, String username, String password, @NonNull FeedFilter filter, String feedPlaybackSpeed) {
private FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction auto_delete_action, String username, String password, @NonNull FeedFilter filter, float feedPlaybackSpeed) {
this.feedID = feedID;
this.autoDownload = autoDownload;
this.keepUpdated = keepUpdated;
@ -67,7 +67,7 @@ public class FeedPreferences {
String password = cursor.getString(indexPassword);
String includeFilter = cursor.getString(indexIncludeFilter);
String excludeFilter = cursor.getString(indexExcludeFilter);
String feedPlaybackSpeed = cursor.getString(indexFeedPlaybackSpeed);
float feedPlaybackSpeed = cursor.getFloat(indexFeedPlaybackSpeed);
return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, username, password, new FeedFilter(includeFilter, excludeFilter), feedPlaybackSpeed);
}
@ -182,30 +182,11 @@ public class FeedPreferences {
this.password = password;
}
public float getCurrentPlaybackSpeed() {
float speed = 0.0f;
if (!"global".equals(feedPlaybackSpeed)) {
try {
speed = Float.parseFloat(getFeedPlaybackSpeed());
} catch (NumberFormatException e) {
setFeedPlaybackSpeed("global");
}
}
// Either global or error happened
if (speed == 0.0f) {
speed = SPEED_USE_GLOBAL;
}
return speed;
}
public String getFeedPlaybackSpeed() {
public float getFeedPlaybackSpeed() {
return feedPlaybackSpeed;
}
public void setFeedPlaybackSpeed(String playbackSpeed) {
public void setFeedPlaybackSpeed(float playbackSpeed) {
feedPlaybackSpeed = playbackSpeed;
}
}

View File

@ -9,6 +9,7 @@ import android.util.Log;
import de.danoeh.antennapod.core.feed.FeedItem;
import static de.danoeh.antennapod.core.feed.FeedMedia.LAST_PLAYBACK_SPEED_UNSET;
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
class DBUpgrader {
/**
@ -292,7 +293,7 @@ class DBUpgrader {
}
if (oldVersion < 1070400) {
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ " ADD COLUMN " + PodDBAdapter.KEY_FEED_PLAYBACK_SPEED + " TEXT");
+ " ADD COLUMN " + PodDBAdapter.KEY_FEED_PLAYBACK_SPEED + " REAL DEFAULT " + SPEED_USE_GLOBAL);
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_MEDIA
+ " ADD COLUMN " + PodDBAdapter.KEY_MEDIA_LAST_PLAYBACK_SPEED + " REAL DEFAULT " + LAST_PLAYBACK_SPEED_UNSET);
}

View File

@ -38,6 +38,7 @@ import de.danoeh.antennapod.core.util.LongIntMap;
import org.greenrobot.eventbus.EventBus;
import static de.danoeh.antennapod.core.feed.FeedMedia.LAST_PLAYBACK_SPEED_UNSET;
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
// TODO Remove media column from feeditem table
@ -148,7 +149,7 @@ public class PodDBAdapter {
+ KEY_HIDE + " TEXT,"
+ KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0,"
+ KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0,"
+ KEY_FEED_PLAYBACK_SPEED + " TEXT)";
+ KEY_FEED_PLAYBACK_SPEED + " REAL DEFAULT " + SPEED_USE_GLOBAL + ")";
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE