From 1e87e34797c8167eeec835b13b01441b61cd6719 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 19 Feb 2022 13:58:47 +0100 Subject: Remove startWhenPrepared and prepareImmediately They are always `true` anyway. --- .../test/antennapod/storage/AutoDownloadTest.java | 1 - .../adapter/FeedItemlistDescriptionAdapter.java | 1 - .../adapter/actionbutton/PlayActionButton.java | 1 - .../actionbutton/PlayLocalActionButton.java | 1 - .../adapter/actionbutton/StreamActionButton.java | 1 - .../dialog/StreamingConfirmationDialog.java | 1 - .../core/service/playback/LocalPSMP.java | 1 - .../core/service/playback/PlaybackService.java | 23 ++++++---------------- .../core/util/playback/PlaybackController.java | 5 +---- .../core/util/playback/PlaybackServiceStarter.java | 21 -------------------- 10 files changed, 7 insertions(+), 49 deletions(-) diff --git a/app/src/androidTest/java/de/test/antennapod/storage/AutoDownloadTest.java b/app/src/androidTest/java/de/test/antennapod/storage/AutoDownloadTest.java index c9b8ef371..7723d4941 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/AutoDownloadTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/AutoDownloadTest.java @@ -99,7 +99,6 @@ public class AutoDownloadTest { FeedMedia media = item.getMedia(); new PlaybackServiceStarter(context, media) .callEvenIfRunning(true) - .startWhenPrepared(true) .start(); Awaitility.await("episode is playing") .atMost(2000, MILLISECONDS) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistDescriptionAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistDescriptionAdapter.java index 6073e97be..f790a5784 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistDescriptionAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistDescriptionAdapter.java @@ -80,7 +80,6 @@ public class FeedItemlistDescriptionAdapter extends ArrayAdapter { } new PlaybackServiceStarter(getContext(), playable) - .startWhenPrepared(true) .callEvenIfRunning(true) .start(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PlayActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PlayActionButton.java index 528f38ba7..983ae3df9 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PlayActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PlayActionButton.java @@ -41,7 +41,6 @@ public class PlayActionButton extends ItemActionButton { } new PlaybackServiceStarter(context, media) .callEvenIfRunning(true) - .startWhenPrepared(true) .start(); if (media.getMediaType() == MediaType.VIDEO) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PlayLocalActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PlayLocalActionButton.java index 47cd4d66b..ce251f5a6 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PlayLocalActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PlayLocalActionButton.java @@ -37,7 +37,6 @@ public class PlayLocalActionButton extends ItemActionButton { new PlaybackServiceStarter(context, media) .callEvenIfRunning(true) - .startWhenPrepared(true) .start(); if (media.getMediaType() == MediaType.VIDEO) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java index 244022c1c..2f5cb5430 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java @@ -47,7 +47,6 @@ public class StreamActionButton extends ItemActionButton { } new PlaybackServiceStarter(context, media) .callEvenIfRunning(true) - .startWhenPrepared(true) .start(); if (media.getMediaType() == MediaType.VIDEO) { diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/StreamingConfirmationDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/StreamingConfirmationDialog.java index e0bd59625..a38463c4a 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/StreamingConfirmationDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/StreamingConfirmationDialog.java @@ -32,7 +32,6 @@ public class StreamingConfirmationDialog { private void stream() { new PlaybackServiceStarter(context, playable) .callEvenIfRunning(true) - .startWhenPrepared(true) .shouldStreamThisTime(true) .start(); } 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 1ef06c511..d54d10dc6 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 @@ -867,7 +867,6 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { if (focusChange == AudioManager.AUDIOFOCUS_GAIN && pausedBecauseOfTransientAudiofocusLoss) { pausedBecauseOfTransientAudiofocusLoss = false; new PlaybackServiceStarter(context, getPlayable()) - .startWhenPrepared(true) .callEvenIfRunning(false) .start(); } 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 c6cff1bd3..e46e8d72c 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 @@ -110,9 +110,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { public static final String EXTRA_PLAYABLE = "PlaybackService.PlayableExtra"; public static final String EXTRA_ALLOW_STREAM_THIS_TIME = "extra.de.danoeh.antennapod.core.service.allowStream"; public static final String EXTRA_ALLOW_STREAM_ALWAYS = "extra.de.danoeh.antennapod.core.service.allowStreamAlways"; - public static final String EXTRA_START_WHEN_PREPARED = "extra.de.danoeh.antennapod.core.service.startWhenPrepared"; - - public static final String EXTRA_PREPARE_IMMEDIATELY = "extra.de.danoeh.antennapod.core.service.prepareImmediately"; public static final String ACTION_PLAYER_STATUS_CHANGED = "action.de.danoeh.antennapod.core.service.playerStatusChanged"; private static final String AVRCP_ACTION_PLAYER_STATUS_CHANGED = "com.android.music.playstatechanged"; @@ -523,8 +520,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { stateManager.validStartCommandWasReceived(); boolean allowStreamThisTime = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_THIS_TIME, false); boolean allowStreamAlways = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_ALWAYS, false); - boolean startWhenPrepared = intent.getBooleanExtra(EXTRA_START_WHEN_PREPARED, false); - boolean prepareImmediately = intent.getBooleanExtra(EXTRA_PREPARE_IMMEDIATELY, false); sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0); if (allowStreamAlways) { UserPreferences.setAllowMobileStreaming(true); @@ -540,8 +535,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( - loadedPlayable -> startPlaying(loadedPlayable, allowStreamThisTime, - startWhenPrepared, prepareImmediately), + loadedPlayable -> startPlaying(loadedPlayable, allowStreamThisTime), error -> { Log.d(TAG, "Playable was not found. Stopping service."); error.printStackTrace(); @@ -725,7 +719,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( - playable -> startPlaying(playable, false, true, true), + playable -> startPlaying(playable, false), error -> { Log.d(TAG, "Playable was not loaded from preferences. Stopping service."); error.printStackTrace(); @@ -733,15 +727,12 @@ public class PlaybackService extends MediaBrowserServiceCompat { }); } - private void startPlaying(Playable playable, boolean allowStreamThisTime, - boolean startWhenPrepared, boolean prepareImmediately) { + private void startPlaying(Playable playable, boolean allowStreamThisTime) { boolean localFeed = URLUtil.isContentUrl(playable.getStreamUrl()); boolean stream = !playable.localFileAvailable() || localFeed; if (stream && !localFeed && !NetworkUtils.isStreamingAllowed() && !allowStreamThisTime) { displayStreamingNotAllowedNotification( new PlaybackServiceStarter(this, playable) - .prepareImmediately(true) - .startWhenPrepared(true) .getIntent()); PlaybackPreferences.writeNoMediaPlaying(); stateManager.stopService(); @@ -752,7 +743,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { PlaybackPreferences.clearCurrentlyPlayingTemporaryPlaybackSpeed(); } - mediaPlayer.playMediaObject(playable, stream, startWhenPrepared, prepareImmediately); + mediaPlayer.playMediaObject(playable, stream, true, true); stateManager.validStartCommandWasReceived(); updateNotificationAndMediaSession(playable); addPlayableToQueue(playable); @@ -1005,8 +996,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { && UserPreferences.isFollowQueue() && !nextItem.getFeed().isLocalFeed()) { displayStreamingNotAllowedNotification( new PlaybackServiceStarter(this, nextItem.getMedia()) - .prepareImmediately(true) - .startWhenPrepared(true) .getIntent()); PlaybackPreferences.writeNoMediaPlaying(); stateManager.stopService(); @@ -1795,7 +1784,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { Log.d(TAG, "onPlayFromMediaId: mediaId: " + mediaId + " extras: " + extras.toString()); FeedMedia p = DBReader.getFeedMedia(Long.parseLong(mediaId)); if (p != null) { - startPlaying(p, false, true, true); + startPlaying(p, false); } } @@ -1806,7 +1795,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { List results = FeedSearcher.searchFeedItems(getBaseContext(), query, 0); if (results.size() > 0 && results.get(0).getMedia() != null) { FeedMedia media = results.get(0).getMedia(); - startPlaying(media, false, true, true); + startPlaying(media, false); return; } onPlay(); 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 687a0d80a..ea1c737a7 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 @@ -329,9 +329,7 @@ public abstract class PlaybackController { public void playPause() { if (playbackService == null) { - new PlaybackServiceStarter(activity, media) - .startWhenPrepared(true) - .start(); + new PlaybackServiceStarter(activity, media).start(); Log.w(TAG, "Play/Pause button was pressed, but playbackservice was null!"); return; } @@ -352,7 +350,6 @@ public abstract class PlaybackController { break; default: new PlaybackServiceStarter(activity, media) - .startWhenPrepared(true) .callEvenIfRunning(true) .start(); Log.w(TAG, "Play/Pause button was pressed and PlaybackService state was unknown"); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java index 7cf6b9adb..62d981b55 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java @@ -11,24 +11,14 @@ import de.danoeh.antennapod.model.playback.Playable; public class PlaybackServiceStarter { private final Context context; private final Playable media; - private boolean startWhenPrepared = false; private boolean shouldStreamThisTime = false; private boolean callEvenIfRunning = false; - private boolean prepareImmediately = true; public PlaybackServiceStarter(Context context, Playable media) { this.context = context; this.media = media; } - /** - * Default value: false - */ - public PlaybackServiceStarter startWhenPrepared(boolean startWhenPrepared) { - this.startWhenPrepared = startWhenPrepared; - return this; - } - /** * Default value: false */ @@ -37,14 +27,6 @@ public class PlaybackServiceStarter { return this; } - /** - * Default value: true - */ - public PlaybackServiceStarter prepareImmediately(boolean prepareImmediately) { - this.prepareImmediately = prepareImmediately; - return this; - } - public PlaybackServiceStarter shouldStreamThisTime(boolean shouldStreamThisTime) { this.shouldStreamThisTime = shouldStreamThisTime; return this; @@ -53,10 +35,7 @@ public class PlaybackServiceStarter { public Intent getIntent() { Intent launchIntent = new Intent(context, PlaybackService.class); launchIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, (Parcelable) media); - launchIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, startWhenPrepared); - launchIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY, prepareImmediately); launchIntent.putExtra(PlaybackService.EXTRA_ALLOW_STREAM_THIS_TIME, shouldStreamThisTime); - return launchIntent; } -- cgit v1.2.3