Update speed when changing feed defaults
This commit is contained in:
parent
63290ae762
commit
998a17a852
|
@ -2,22 +2,21 @@ package de.danoeh.antennapod.fragment;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.preference.SwitchPreference;
|
import android.util.Log;
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
import android.util.Log;
|
import androidx.preference.SwitchPreference;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.activity.MainActivity;
|
import de.danoeh.antennapod.activity.MainActivity;
|
||||||
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
||||||
|
import de.danoeh.antennapod.core.event.settings.SpeedPresetChangedEvent;
|
||||||
import de.danoeh.antennapod.core.event.settings.VolumeAdaptionChangedEvent;
|
import de.danoeh.antennapod.core.event.settings.VolumeAdaptionChangedEvent;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedFilter;
|
import de.danoeh.antennapod.core.feed.FeedFilter;
|
||||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||||
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
|
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.dialog.AuthenticationDialog;
|
import de.danoeh.antennapod.dialog.AuthenticationDialog;
|
||||||
|
@ -38,7 +37,8 @@ import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
|
||||||
public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
||||||
private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter";
|
private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter";
|
||||||
private static final String PREF_FEED_PLAYBACK_SPEED = "feedPlaybackSpeed";
|
private static final String PREF_FEED_PLAYBACK_SPEED = "feedPlaybackSpeed";
|
||||||
private static final DecimalFormat decimalFormat = new DecimalFormat("0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
private static final DecimalFormat SPEED_FORMAT =
|
||||||
|
new DecimalFormat("0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
||||||
private static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId";
|
private static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId";
|
||||||
private static final String TAG = "FeedSettingsFragment";
|
private static final String TAG = "FeedSettingsFragment";
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
||||||
String[] speeds = UserPreferences.getPlaybackSpeedArray();
|
String[] speeds = UserPreferences.getPlaybackSpeedArray();
|
||||||
|
|
||||||
String[] values = new String[speeds.length + 1];
|
String[] values = new String[speeds.length + 1];
|
||||||
values[0] = decimalFormat.format(SPEED_USE_GLOBAL);
|
values[0] = SPEED_FORMAT.format(SPEED_USE_GLOBAL);
|
||||||
|
|
||||||
String[] entries = new String[speeds.length + 1];
|
String[] entries = new String[speeds.length + 1];
|
||||||
entries[0] = getString(R.string.feed_auto_download_global);
|
entries[0] = getString(R.string.feed_auto_download_global);
|
||||||
|
@ -130,11 +130,12 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
feedPlaybackSpeedPreference.setEntryValues(values);
|
feedPlaybackSpeedPreference.setEntryValues(values);
|
||||||
feedPlaybackSpeedPreference.setEntries(entries);
|
feedPlaybackSpeedPreference.setEntries(entries);
|
||||||
|
|
||||||
feedPlaybackSpeedPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
feedPlaybackSpeedPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
feedPreferences.setFeedPlaybackSpeed(Float.parseFloat((String) newValue));
|
feedPreferences.setFeedPlaybackSpeed(Float.parseFloat((String) newValue));
|
||||||
feed.savePreferences();
|
feed.savePreferences();
|
||||||
updatePlaybackSpeedPreference();
|
updatePlaybackSpeedPreference();
|
||||||
|
EventBus.getDefault().post(
|
||||||
|
new SpeedPresetChangedEvent(feedPreferences.getFeedPlaybackSpeed(), feed.getId()));
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -192,7 +193,7 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
||||||
ListPreference feedPlaybackSpeedPreference = findPreference(PREF_FEED_PLAYBACK_SPEED);
|
ListPreference feedPlaybackSpeedPreference = findPreference(PREF_FEED_PLAYBACK_SPEED);
|
||||||
|
|
||||||
float speedValue = feedPreferences.getFeedPlaybackSpeed();
|
float speedValue = feedPreferences.getFeedPlaybackSpeed();
|
||||||
feedPlaybackSpeedPreference.setValue(decimalFormat.format(speedValue));
|
feedPlaybackSpeedPreference.setValue(SPEED_FORMAT.format(speedValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAutoDeleteSummary() {
|
private void updateAutoDeleteSummary() {
|
||||||
|
@ -230,17 +231,12 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
||||||
}
|
}
|
||||||
feed.savePreferences();
|
feed.savePreferences();
|
||||||
updateVolumeReductionValue();
|
updateVolumeReductionValue();
|
||||||
sendVolumeAdaptionChangedIntent();
|
EventBus.getDefault().post(
|
||||||
|
new VolumeAdaptionChangedEvent(feedPreferences.getVolumeAdaptionSetting(), feed.getId()));
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendVolumeAdaptionChangedIntent() {
|
|
||||||
EventBus.getDefault().post(
|
|
||||||
new VolumeAdaptionChangedEvent(feedPreferences.getVolumeAdaptionSetting(), feed.getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateVolumeReductionValue() {
|
private void updateVolumeReductionValue() {
|
||||||
ListPreference volumeReductionPreference = (ListPreference) findPreference("volumeReduction");
|
ListPreference volumeReductionPreference = (ListPreference) findPreference("volumeReduction");
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package de.danoeh.antennapod.core.event.settings;
|
||||||
|
|
||||||
|
public class SpeedPresetChangedEvent {
|
||||||
|
private final float speed;
|
||||||
|
private final long feedId;
|
||||||
|
|
||||||
|
public SpeedPresetChangedEvent(float speed, long feedId) {
|
||||||
|
this.speed = speed;
|
||||||
|
this.feedId = feedId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getSpeed() {
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFeedId() {
|
||||||
|
return feedId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,6 +50,7 @@ import de.danoeh.antennapod.core.R;
|
||||||
import de.danoeh.antennapod.core.event.MessageEvent;
|
import de.danoeh.antennapod.core.event.MessageEvent;
|
||||||
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||||
import de.danoeh.antennapod.core.event.ServiceEvent;
|
import de.danoeh.antennapod.core.event.ServiceEvent;
|
||||||
|
import de.danoeh.antennapod.core.event.settings.SpeedPresetChangedEvent;
|
||||||
import de.danoeh.antennapod.core.event.settings.VolumeAdaptionChangedEvent;
|
import de.danoeh.antennapod.core.event.settings.VolumeAdaptionChangedEvent;
|
||||||
import de.danoeh.antennapod.core.feed.Chapter;
|
import de.danoeh.antennapod.core.feed.Chapter;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
|
@ -79,6 +80,9 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
|
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls the MediaPlayer that plays a FeedMedia-file
|
* Controls the MediaPlayer that plays a FeedMedia-file
|
||||||
|
@ -1436,12 +1440,25 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void volumeAdaptionChanged(VolumeAdaptionChangedEvent event) {
|
public void volumeAdaptionChanged(VolumeAdaptionChangedEvent event) {
|
||||||
PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
|
PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
|
||||||
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, event.getFeedId(), event.getVolumeAdaptionSetting());
|
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, event.getFeedId(), event.getVolumeAdaptionSetting());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
public void speedPresetChanged(SpeedPresetChangedEvent event) {
|
||||||
|
if (getPlayable() instanceof FeedMedia) {
|
||||||
|
if (((FeedMedia) getPlayable()).getItem().getFeed().getId() == event.getFeedId()) {
|
||||||
|
if (event.getSpeed() == SPEED_USE_GLOBAL) {
|
||||||
|
setSpeed(UserPreferences.getPlaybackSpeed(getPlayable().getMediaType()));
|
||||||
|
} else {
|
||||||
|
setSpeed(event.getSpeed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static MediaType getCurrentMediaType() {
|
public static MediaType getCurrentMediaType() {
|
||||||
return currentMediaType;
|
return currentMediaType;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue