From 60f3d77eb2d41d49ad6fd999c39f5792f804a17e Mon Sep 17 00:00:00 2001 From: quails4Eva Date: Sun, 3 Mar 2024 19:17:22 +0000 Subject: [PATCH] Skip silence setting per feed (#6910) --- .../dialog/VariableSpeedDialog.java | 13 +++++-- .../fragment/FeedSettingsFragment.java | 27 ++++++++++++--- .../playback_speed_feed_setting_dialog.xml | 6 ++++ .../core/feed/util/PlaybackSpeedUtils.java | 22 ++++++++++++ .../core/preferences/PlaybackPreferences.java | 22 +++++++++++- .../service/playback/ExoPlayerWrapper.java | 4 +++ .../core/service/playback/LocalPSMP.java | 20 +++++++++-- .../service/playback/PlaybackService.java | 26 +++++++++++--- .../util/playback/PlaybackController.java | 12 ++++++- .../settings/SpeedPresetChangedEvent.java | 10 +++++- .../model/feed/FeedPreferences.java | 34 +++++++++++++++++-- .../base/PlaybackServiceMediaPlayer.java | 2 ++ .../antennapod/playback/cast/CastPsmp.java | 6 ++++ .../storage/database/DBUpgrader.java | 4 +++ .../storage/database/PodDBAdapter.java | 6 +++- .../mapper/FeedPreferencesCursorMapper.java | 5 +++ 16 files changed, 198 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java index 8de7dce04..c62f5df7e 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java @@ -37,6 +37,7 @@ public class VariableSpeedDialog extends BottomSheetDialogFragment { private final List selectedSpeeds; private PlaybackSpeedSeekBar speedSeekBar; private Chip addCurrentSpeedChip; + private CheckBox skipSilenceCheckbox; public VariableSpeedDialog() { DecimalFormatSymbols format = new DecimalFormatSymbols(Locale.US); @@ -51,11 +52,13 @@ public class VariableSpeedDialog extends BottomSheetDialogFragment { @Override public void loadMediaInfo() { updateSpeed(new SpeedChangedEvent(controller.getCurrentPlaybackSpeedMultiplier())); + updateSkipSilence(controller.getCurrentPlaybackSkipSilence()); } }; controller.init(); EventBus.getDefault().register(this); updateSpeed(new SpeedChangedEvent(controller.getCurrentPlaybackSpeedMultiplier())); + updateSkipSilence(controller.getCurrentPlaybackSkipSilence()); } @Override @@ -72,6 +75,10 @@ public class VariableSpeedDialog extends BottomSheetDialogFragment { addCurrentSpeedChip.setText(String.format(Locale.getDefault(), "%1$.2f", event.getNewSpeed())); } + public void updateSkipSilence(boolean skipSilence) { + skipSilenceCheckbox.setChecked(skipSilence); + } + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @@ -97,9 +104,9 @@ public class VariableSpeedDialog extends BottomSheetDialogFragment { addCurrentSpeedChip.setCloseIconContentDescription(getString(R.string.add_preset)); addCurrentSpeedChip.setOnClickListener(v -> addCurrentSpeed()); - final CheckBox skipSilence = root.findViewById(R.id.skipSilence); - skipSilence.setChecked(UserPreferences.isSkipSilence()); - skipSilence.setOnCheckedChangeListener((buttonView, isChecked) -> { + skipSilenceCheckbox = root.findViewById(R.id.skipSilence); + skipSilenceCheckbox.setChecked(UserPreferences.isSkipSilence()); + skipSilenceCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> { UserPreferences.setSkipSilence(isChecked); controller.setSkipSilence(isChecked); }); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java index c42134165..4626c061f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java @@ -241,14 +241,21 @@ public class FeedSettingsFragment extends Fragment { PlaybackSpeedFeedSettingDialogBinding.inflate(getLayoutInflater()); viewBinding.seekBar.setProgressChangedListener(speed -> viewBinding.currentSpeedLabel.setText(String.format(Locale.getDefault(), "%.2fx", speed))); - float speed = feedPreferences.getFeedPlaybackSpeed(); viewBinding.useGlobalCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> { viewBinding.seekBar.setEnabled(!isChecked); viewBinding.seekBar.setAlpha(isChecked ? 0.4f : 1f); viewBinding.currentSpeedLabel.setAlpha(isChecked ? 0.4f : 1f); + + viewBinding.skipSilenceFeed.setEnabled(!isChecked); + viewBinding.skipSilenceFeed.setAlpha(isChecked ? 0.4f : 1f); }); - viewBinding.useGlobalCheckbox.setChecked(speed == FeedPreferences.SPEED_USE_GLOBAL); - viewBinding.seekBar.updateSpeed(speed == FeedPreferences.SPEED_USE_GLOBAL ? 1 : speed); + float speed = feedPreferences.getFeedPlaybackSpeed(); + FeedPreferences.SkipSilence skipSilence = feedPreferences.getFeedSkipSilence(); + boolean isGlobal = speed == FeedPreferences.SPEED_USE_GLOBAL; + viewBinding.useGlobalCheckbox.setChecked(isGlobal); + viewBinding.seekBar.updateSpeed(isGlobal ? 1 : speed); + viewBinding.skipSilenceFeed.setChecked(!isGlobal + && skipSilence == FeedPreferences.SkipSilence.AGGRESSIVE); new MaterialAlertDialogBuilder(getContext()) .setTitle(R.string.playback_speed) .setView(viewBinding.getRoot()) @@ -256,9 +263,19 @@ public class FeedSettingsFragment extends Fragment { float newSpeed = viewBinding.useGlobalCheckbox.isChecked() ? FeedPreferences.SPEED_USE_GLOBAL : viewBinding.seekBar.getCurrentSpeed(); feedPreferences.setFeedPlaybackSpeed(newSpeed); + FeedPreferences.SkipSilence newSkipSilence; + if (viewBinding.useGlobalCheckbox.isChecked()) { + newSkipSilence = FeedPreferences.SkipSilence.GLOBAL; + } else if (viewBinding.skipSilenceFeed.isChecked()) { + newSkipSilence = FeedPreferences.SkipSilence.AGGRESSIVE; + } else { + newSkipSilence = FeedPreferences.SkipSilence.OFF; + } + feedPreferences.setFeedSkipSilence(newSkipSilence); DBWriter.setFeedPreferences(feedPreferences); - EventBus.getDefault().post( - new SpeedPresetChangedEvent(feedPreferences.getFeedPlaybackSpeed(), feed.getId())); + EventBus.getDefault().post(new SpeedPresetChangedEvent( + feedPreferences.getFeedPlaybackSpeed(), + feed.getId(), feedPreferences.getFeedSkipSilence())); }) .setNegativeButton(R.string.cancel_label, null) .show(); diff --git a/app/src/main/res/layout/playback_speed_feed_setting_dialog.xml b/app/src/main/res/layout/playback_speed_feed_setting_dialog.xml index 48d69e4a9..50eb4f84f 100644 --- a/app/src/main/res/layout/playback_speed_feed_setting_dialog.xml +++ b/app/src/main/res/layout/playback_speed_feed_setting_dialog.xml @@ -34,4 +34,10 @@ + + diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/util/PlaybackSpeedUtils.java b/core/src/main/java/de/danoeh/antennapod/core/feed/util/PlaybackSpeedUtils.java index d0824e00b..cd98507ba 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/util/PlaybackSpeedUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/util/PlaybackSpeedUtils.java @@ -4,6 +4,7 @@ import android.util.Log; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.playback.MediaType; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.storage.preferences.UserPreferences; @@ -50,4 +51,25 @@ public final class PlaybackSpeedUtils { return playbackSpeed; } + + /** + * Returns the currently configured skip silence for the specified media. + */ + public static FeedPreferences.SkipSilence getCurrentSkipSilencePreference(Playable media) { + FeedPreferences.SkipSilence skipSilence = FeedPreferences.SkipSilence.GLOBAL; + if (media != null) { + skipSilence = PlaybackPreferences.getCurrentlyPlayingTemporarySkipSilence(); + if (skipSilence == FeedPreferences.SkipSilence.GLOBAL && media instanceof FeedMedia) { + FeedItem item = ((FeedMedia) media).getItem(); + if (item != null && item.getFeed() != null && item.getFeed().getPreferences() != null) { + skipSilence = item.getFeed().getPreferences().getFeedSkipSilence(); + } + } + } + if (skipSilence == FeedPreferences.SkipSilence.GLOBAL) { + skipSilence = UserPreferences.isSkipSilence() + ? FeedPreferences.SkipSilence.AGGRESSIVE : FeedPreferences.SkipSilence.OFF; + } + return skipSilence; + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java index 160b6b774..d6f6cdb43 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java @@ -10,6 +10,7 @@ import android.util.Log; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.event.PlayerStatusEvent; import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.playback.MediaType; import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.playback.base.PlayerStatus; @@ -64,6 +65,12 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference private static final String PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED = "de.danoeh.antennapod.preferences.temporaryPlaybackSpeed"; + /** + * A temporary skip silence preference which overrides the per-feed skip silence for the currently playing + * media. Considered unset if set to null; + */ + private static final String PREF_CURRENTLY_PLAYING_TEMPORARY_SKIP_SILENCE + = "de.danoeh.antennapod.preferences.temporarySkipSilence"; /** * Value of PREF_CURRENTLY_PLAYING_MEDIA if no media is playing. @@ -123,6 +130,11 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference return prefs.getFloat(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED, SPEED_USE_GLOBAL); } + public static FeedPreferences.SkipSilence getCurrentlyPlayingTemporarySkipSilence() { + return FeedPreferences.SkipSilence.fromCode(prefs.getInt( + PREF_CURRENTLY_PLAYING_TEMPORARY_SKIP_SILENCE, FeedPreferences.SkipSilence.GLOBAL.code)); + } + public static void writeNoMediaPlaying() { SharedPreferences.Editor editor = prefs.edit(); editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, NO_MEDIA_PLAYING); @@ -170,9 +182,17 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference editor.apply(); } - public static void clearCurrentlyPlayingTemporaryPlaybackSpeed() { + public static void setCurrentlyPlayingTemporarySkipSilence(boolean skipSilence) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putInt(PREF_CURRENTLY_PLAYING_TEMPORARY_SKIP_SILENCE, skipSilence + ? FeedPreferences.SkipSilence.AGGRESSIVE.code : FeedPreferences.SkipSilence.OFF.code); + editor.apply(); + } + + public static void clearCurrentlyPlayingTemporaryPlaybackSettings() { SharedPreferences.Editor editor = prefs.edit(); editor.remove(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED); + editor.remove(PREF_CURRENTLY_PLAYING_TEMPORARY_SKIP_SILENCE); editor.apply(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java index 4e29c9b8a..8ee47a147 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java @@ -166,6 +166,10 @@ public class ExoPlayerWrapper { return playbackParameters.speed; } + public boolean getCurrentSkipSilence() { + return exoPlayer.getSkipSilenceEnabled(); + } + public int getDuration() { if (exoPlayer.getDuration() == C.TIME_UNSET) { return Playable.INVALID_TIME; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java index 69c632c4f..2ad8f2b8a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java @@ -161,7 +161,9 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { try { callback.ensureMediaInfoLoaded(media); callback.onMediaChanged(false); - setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence()); + setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), + PlaybackSpeedUtils.getCurrentSkipSilencePreference(media) + == FeedPreferences.SkipSilence.AGGRESSIVE); if (stream) { if (playable instanceof FeedMedia) { FeedMedia feedMedia = (FeedMedia) playable; @@ -212,7 +214,9 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { Log.d(TAG, "Resuming/Starting playback"); acquireWifiLockIfNecessary(); - setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence()); + setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), + PlaybackSpeedUtils.getCurrentSkipSilencePreference(media) + == FeedPreferences.SkipSilence.AGGRESSIVE); setVolume(1.0f, 1.0f); if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) { @@ -461,6 +465,18 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { return retVal; } + @Override + public boolean getSkipSilence() { + boolean retVal = false; + if ((playerStatus == PlayerStatus.PLAYING + || playerStatus == PlayerStatus.PAUSED + || playerStatus == PlayerStatus.INITIALIZED + || playerStatus == PlayerStatus.PREPARED)) { + retVal = mediaPlayer.getCurrentSkipSilence(); + } + return retVal; + } + /** * Sets the playback volume. * This method is executed on an internal executor service. diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index fd11dc4c5..401d09ad7 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -750,7 +750,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { } if (!playable.getIdentifier().equals(PlaybackPreferences.getCurrentlyPlayingFeedMediaId())) { - PlaybackPreferences.clearCurrentlyPlayingTemporaryPlaybackSpeed(); + PlaybackPreferences.clearCurrentlyPlayingTemporaryPlaybackSettings(); } mediaPlayer.playMediaObject(playable, stream, true, true); @@ -1047,7 +1047,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { */ private void onPlaybackEnded(MediaType mediaType, boolean stopPlaying) { Log.d(TAG, "Playback ended"); - PlaybackPreferences.clearCurrentlyPlayingTemporaryPlaybackSpeed(); + PlaybackPreferences.clearCurrentlyPlayingTemporaryPlaybackSettings(); if (stopPlaying) { taskManager.cancelPositionSaver(); cancelPositionObserver(); @@ -1604,8 +1604,15 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (((FeedMedia) getPlayable()).getItem().getFeed().getId() == event.getFeedId()) { if (event.getSpeed() == SPEED_USE_GLOBAL) { setSpeed(UserPreferences.getPlaybackSpeed(getPlayable().getMediaType())); + setSkipSilence(UserPreferences.isSkipSilence()); } else { setSpeed(event.getSpeed()); + FeedPreferences.SkipSilence skipSilence = event.getSkipSilence(); + if (skipSilence == FeedPreferences.SkipSilence.GLOBAL) { + setSkipSilence(UserPreferences.isSkipSilence()); + } else { + setSkipSilence(skipSilence == FeedPreferences.SkipSilence.AGGRESSIVE); + } } } } @@ -1669,20 +1676,29 @@ public class PlaybackService extends MediaBrowserServiceCompat { UserPreferences.setPlaybackSpeed(speed); } - mediaPlayer.setPlaybackParams(speed, UserPreferences.isSkipSilence()); + mediaPlayer.setPlaybackParams(speed, getCurrentSkipSilence()); } - public void skipSilence(boolean skipSilence) { + public void setSkipSilence(boolean skipSilence) { + PlaybackPreferences.setCurrentlyPlayingTemporarySkipSilence(skipSilence); + UserPreferences.setSkipSilence(skipSilence); mediaPlayer.setPlaybackParams(getCurrentPlaybackSpeed(), skipSilence); } public float getCurrentPlaybackSpeed() { - if(mediaPlayer == null) { + if (mediaPlayer == null) { return 1.0f; } return mediaPlayer.getPlaybackSpeed(); } + public boolean getCurrentSkipSilence() { + if (mediaPlayer == null) { + return false; + } + return mediaPlayer.getSkipSilence(); + } + public boolean isStartWhenPrepared() { return mediaPlayer.isStartWhenPrepared(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index 2274dcf83..f17bd7e31 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -18,6 +18,7 @@ import de.danoeh.antennapod.event.playback.PlaybackPositionEvent; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.event.playback.PlaybackServiceEvent; import de.danoeh.antennapod.event.playback.SpeedChangedEvent; +import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.playback.MediaType; import de.danoeh.antennapod.core.feed.util.PlaybackSpeedUtils; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; @@ -407,7 +408,7 @@ public abstract class PlaybackController { public void setSkipSilence(boolean skipSilence) { if (playbackService != null) { - playbackService.skipSilence(skipSilence); + playbackService.setSkipSilence(skipSilence); } } @@ -419,6 +420,15 @@ public abstract class PlaybackController { } } + public boolean getCurrentPlaybackSkipSilence() { + if (playbackService != null) { + return playbackService.getCurrentSkipSilence(); + } else { + return PlaybackSpeedUtils.getCurrentSkipSilencePreference(getMedia()) + == FeedPreferences.SkipSilence.AGGRESSIVE; + } + } + public List getAudioTracks() { if (playbackService == null) { return Collections.emptyList(); diff --git a/event/src/main/java/de/danoeh/antennapod/event/settings/SpeedPresetChangedEvent.java b/event/src/main/java/de/danoeh/antennapod/event/settings/SpeedPresetChangedEvent.java index 6ca8a1290..bc7c46785 100644 --- a/event/src/main/java/de/danoeh/antennapod/event/settings/SpeedPresetChangedEvent.java +++ b/event/src/main/java/de/danoeh/antennapod/event/settings/SpeedPresetChangedEvent.java @@ -1,18 +1,26 @@ package de.danoeh.antennapod.event.settings; +import de.danoeh.antennapod.model.feed.FeedPreferences; + public class SpeedPresetChangedEvent { private final float speed; + private final FeedPreferences.SkipSilence skipSilence; private final long feedId; - public SpeedPresetChangedEvent(float speed, long feedId) { + public SpeedPresetChangedEvent(float speed, long feedId, FeedPreferences.SkipSilence skipSilence) { this.speed = speed; this.feedId = feedId; + this.skipSilence = skipSilence; } public float getSpeed() { return speed; } + public FeedPreferences.SkipSilence getSkipSilence() { + return skipSilence; + } + public long getFeedId() { return feedId; } diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedPreferences.java b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedPreferences.java index 39b6e2bdd..02f09693e 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedPreferences.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedPreferences.java @@ -59,6 +59,25 @@ public class FeedPreferences implements Serializable { } } + public enum SkipSilence { + OFF(0), GLOBAL(1), AGGRESSIVE(2); + + public final int code; + + SkipSilence(int code) { + this.code = code; + } + + public static SkipSilence fromCode(int code) { + for (SkipSilence s : values()) { + if (s.code == code) { + return s; + } + } + return GLOBAL; + } + } + @NonNull private FeedFilter filter; private long feedID; @@ -72,6 +91,7 @@ public class FeedPreferences implements Serializable { private float feedPlaybackSpeed; private int feedSkipIntro; private int feedSkipEnding; + private SkipSilence feedSkipSilence; private boolean showEpisodeNotification; private final Set tags = new HashSet<>(); @@ -79,13 +99,14 @@ public class FeedPreferences implements Serializable { VolumeAdaptionSetting volumeAdaptionSetting, NewEpisodesAction newEpisodesAction, String username, String password) { this(feedID, autoDownload, true, autoDeleteAction, volumeAdaptionSetting, username, password, - new FeedFilter(), SPEED_USE_GLOBAL, 0, 0, false, newEpisodesAction, new HashSet<>()); + new FeedFilter(), SPEED_USE_GLOBAL, 0, 0, SkipSilence.GLOBAL, + false, newEpisodesAction, new HashSet<>()); } public FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction autoDeleteAction, VolumeAdaptionSetting volumeAdaptionSetting, String username, String password, @NonNull FeedFilter filter, - float feedPlaybackSpeed, int feedSkipIntro, int feedSkipEnding, + float feedPlaybackSpeed, int feedSkipIntro, int feedSkipEnding, SkipSilence feedSkipSilence, boolean showEpisodeNotification, NewEpisodesAction newEpisodesAction, Set tags) { this.feedID = feedID; @@ -99,6 +120,7 @@ public class FeedPreferences implements Serializable { this.feedPlaybackSpeed = feedPlaybackSpeed; this.feedSkipIntro = feedSkipIntro; this.feedSkipEnding = feedSkipEnding; + this.feedSkipSilence = feedSkipSilence; this.showEpisodeNotification = showEpisodeNotification; this.newEpisodesAction = newEpisodesAction; this.tags.addAll(tags); @@ -241,6 +263,14 @@ public class FeedPreferences implements Serializable { return feedSkipEnding; } + public void setFeedSkipSilence(SkipSilence skipSilence) { + feedSkipSilence = skipSilence; + } + + public SkipSilence getFeedSkipSilence() { + return feedSkipSilence; + } + public Set getTags() { return tags; } diff --git a/playback/base/src/main/java/de/danoeh/antennapod/playback/base/PlaybackServiceMediaPlayer.java b/playback/base/src/main/java/de/danoeh/antennapod/playback/base/PlaybackServiceMediaPlayer.java index 73b38c00c..39ee99884 100644 --- a/playback/base/src/main/java/de/danoeh/antennapod/playback/base/PlaybackServiceMediaPlayer.java +++ b/playback/base/src/main/java/de/danoeh/antennapod/playback/base/PlaybackServiceMediaPlayer.java @@ -151,6 +151,8 @@ public abstract class PlaybackServiceMediaPlayer { */ public abstract float getPlaybackSpeed(); + public abstract boolean getSkipSilence(); + /** * Sets the playback volume. * This method is executed on an internal executor service. diff --git a/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastPsmp.java b/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastPsmp.java index 8f0738e53..fd70fa18c 100644 --- a/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastPsmp.java +++ b/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastPsmp.java @@ -427,6 +427,12 @@ public class CastPsmp extends PlaybackServiceMediaPlayer { return status != null ? (float) status.getPlaybackRate() : 1.0f; } + @Override + public boolean getSkipSilence() { + // Don't think this is supported + return false; + } + @Override public void setVolume(float volumeLeft, float volumeRight) { Log.d(TAG, "Setting the Stream volume on Remote Media Player"); diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java index cbac417a9..b7aec5b39 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java @@ -334,6 +334,10 @@ class DBUpgrader { db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + " ADD COLUMN " + PodDBAdapter.KEY_NEW_EPISODES_ACTION + " INTEGER DEFAULT 0"); } + if (oldVersion < 3040000) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + + " ADD COLUMN " + PodDBAdapter.KEY_FEED_SKIP_SILENCE + " INTEGER"); + } } } diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java index 99b0972a8..e577896be 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java @@ -52,7 +52,7 @@ public class PodDBAdapter { private static final String TAG = "PodDBAdapter"; public static final String DATABASE_NAME = "Antennapod.db"; - public static final int VERSION = 3010000; + public static final int VERSION = 3040000; /** * Maximum number of arguments for IN-operator. @@ -113,6 +113,7 @@ public class PodDBAdapter { public static final String KEY_EXCLUDE_FILTER = "exclude_filter"; public static final String KEY_MINIMAL_DURATION_FILTER = "minimal_duration_filter"; public static final String KEY_FEED_PLAYBACK_SPEED = "feed_playback_speed"; + public static final String KEY_FEED_SKIP_SILENCE = "feed_skip_silence"; public static final String KEY_FEED_SKIP_INTRO = "feed_skip_intro"; public static final String KEY_FEED_SKIP_ENDING = "feed_skip_ending"; public static final String KEY_FEED_TAGS = "tags"; @@ -155,6 +156,7 @@ public class PodDBAdapter { + KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0," + KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0," + KEY_FEED_PLAYBACK_SPEED + " REAL DEFAULT " + SPEED_USE_GLOBAL + "," + + KEY_FEED_SKIP_SILENCE + " INTEGER DEFAULT " + FeedPreferences.SkipSilence.GLOBAL.code + "," + KEY_FEED_VOLUME_ADAPTION + " INTEGER DEFAULT 0," + KEY_FEED_TAGS + " TEXT," + KEY_FEED_SKIP_INTRO + " INTEGER DEFAULT 0," @@ -307,6 +309,7 @@ public class PodDBAdapter { + TABLE_NAME_FEEDS + "." + KEY_EXCLUDE_FILTER + ", " + TABLE_NAME_FEEDS + "." + KEY_MINIMAL_DURATION_FILTER + ", " + TABLE_NAME_FEEDS + "." + KEY_FEED_PLAYBACK_SPEED + ", " + + TABLE_NAME_FEEDS + "." + KEY_FEED_SKIP_SILENCE + ", " + TABLE_NAME_FEEDS + "." + KEY_FEED_TAGS + ", " + TABLE_NAME_FEEDS + "." + KEY_FEED_SKIP_INTRO + ", " + TABLE_NAME_FEEDS + "." + KEY_FEED_SKIP_ENDING + ", " @@ -456,6 +459,7 @@ public class PodDBAdapter { values.put(KEY_EXCLUDE_FILTER, prefs.getFilter().getExcludeFilterRaw()); values.put(KEY_MINIMAL_DURATION_FILTER, prefs.getFilter().getMinimalDurationFilter()); values.put(KEY_FEED_PLAYBACK_SPEED, prefs.getFeedPlaybackSpeed()); + values.put(KEY_FEED_SKIP_SILENCE, prefs.getFeedSkipSilence().code); values.put(KEY_FEED_TAGS, prefs.getTagsAsString()); values.put(KEY_FEED_SKIP_INTRO, prefs.getFeedSkipIntro()); values.put(KEY_FEED_SKIP_ENDING, prefs.getFeedSkipEnding()); diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java index 2de100dff..83b62b8a3 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java @@ -31,6 +31,7 @@ public abstract class FeedPreferencesCursorMapper { int indexExcludeFilter = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_EXCLUDE_FILTER); int indexMinimalDurationFilter = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_MINIMAL_DURATION_FILTER); int indexFeedPlaybackSpeed = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_PLAYBACK_SPEED); + int indexFeedSkipSilence = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_SKIP_SILENCE); int indexAutoSkipIntro = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_SKIP_INTRO); int indexAutoSkipEnding = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_SKIP_ENDING); int indexEpisodeNotification = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_EPISODE_NOTIFICATION); @@ -52,6 +53,8 @@ public abstract class FeedPreferencesCursorMapper { float feedPlaybackSpeed = cursor.getFloat(indexFeedPlaybackSpeed); int feedAutoSkipIntro = cursor.getInt(indexAutoSkipIntro); int feedAutoSkipEnding = cursor.getInt(indexAutoSkipEnding); + FeedPreferences.SkipSilence feedSkipSilence = + FeedPreferences.SkipSilence.fromCode(cursor.getInt(indexFeedSkipSilence)); FeedPreferences.NewEpisodesAction feedNewEpisodesAction = FeedPreferences.NewEpisodesAction.fromCode(cursor.getInt(indexNewEpisodesAction)); boolean showNotification = cursor.getInt(indexEpisodeNotification) > 0; @@ -59,6 +62,7 @@ public abstract class FeedPreferencesCursorMapper { if (TextUtils.isEmpty(tagsString)) { tagsString = FeedPreferences.TAG_ROOT; } + return new FeedPreferences(feedId, autoDownload, autoRefresh, @@ -70,6 +74,7 @@ public abstract class FeedPreferencesCursorMapper { feedPlaybackSpeed, feedAutoSkipIntro, feedAutoSkipEnding, + feedSkipSilence, showNotification, feedNewEpisodesAction, new HashSet<>(Arrays.asList(tagsString.split(FeedPreferences.TAG_SEPARATOR))));