diff options
author | ByteHamster <info@bytehamster.com> | 2022-11-05 13:18:48 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-11-05 13:54:33 +0100 |
commit | ae3971a58ff00755148b036794b7e5dc1c57017a (patch) | |
tree | f76f08ec94611d77f7f34b36e1bee2ad3ad241e9 /core/src/main | |
parent | 323149642a46af75e091b9980f08151b484d0155 (diff) | |
download | AntennaPod-ae3971a58ff00755148b036794b7e5dc1c57017a.zip |
No need to have other classes depend on the entire playback service when they just need one constant
Diffstat (limited to 'core/src/main')
6 files changed, 55 insertions, 65 deletions
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 4a88e3851..a6d90dc7d 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 @@ -109,54 +109,22 @@ public class PlaybackService extends MediaBrowserServiceCompat { */ private static final String TAG = "PlaybackService"; - 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 ACTION_PLAYER_STATUS_CHANGED = "action.de.danoeh.antennapod.core.service.playerStatusChanged"; private static final String AVRCP_ACTION_PLAYER_STATUS_CHANGED = "com.android.music.playstatechanged"; private static final String AVRCP_ACTION_META_CHANGED = "com.android.music.metachanged"; - public static final String ACTION_PLAYER_NOTIFICATION = "action.de.danoeh.antennapod.core.service.playerNotification"; - public static final String EXTRA_NOTIFICATION_CODE = "extra.de.danoeh.antennapod.core.service.notificationCode"; - public static final String EXTRA_NOTIFICATION_TYPE = "extra.de.danoeh.antennapod.core.service.notificationType"; - - /** - * If the PlaybackService receives this action, it will stop playback and - * try to shutdown. - */ - public static final String ACTION_SHUTDOWN_PLAYBACK_SERVICE = "action.de.danoeh.antennapod.core.service.actionShutdownPlaybackService"; - /** * Custom action used by Android Wear, Android Auto */ private static final String CUSTOM_ACTION_FAST_FORWARD = "action.de.danoeh.antennapod.core.service.fastForward"; private static final String CUSTOM_ACTION_REWIND = "action.de.danoeh.antennapod.core.service.rewind"; - - /** - * Used in NOTIFICATION_TYPE_RELOAD. - */ - public static final int EXTRA_CODE_AUDIO = 1; - public static final int EXTRA_CODE_VIDEO = 2; - public static final int EXTRA_CODE_CAST = 3; - - /** - * Receivers of this intent should update their information about the curently playing media - */ - public static final int NOTIFICATION_TYPE_RELOAD = 3; - /** * Set a max number of episodes to load for Android Auto, otherwise there could be performance issues */ public static final int MAX_ANDROID_AUTO_EPISODES_PER_FEED = 100; /** - * No more episodes are going to be played. - */ - public static final int NOTIFICATION_TYPE_PLAYBACK_END = 7; - - /** * Is true if service is running. */ public static boolean isRunning = false; @@ -243,7 +211,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { registerReceiver(autoStateUpdated, new IntentFilter("com.google.android.gms.car.media.STATUS")); registerReceiver(headsetDisconnected, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); - registerReceiver(shutdownReceiver, new IntentFilter(ACTION_SHUTDOWN_PLAYBACK_SERVICE)); + registerReceiver(shutdownReceiver, new IntentFilter(PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE)); registerReceiver(bluetoothStateUpdated, new IntentFilter(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED)); registerReceiver(audioBecomingNoisy, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY)); EventBus.getDefault().register(this); @@ -478,7 +446,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1); final boolean hardwareButton = intent.getBooleanExtra(MediaButtonReceiver.EXTRA_HARDWAREBUTTON, false); - Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE); + Playable playable = intent.getParcelableExtra(PlaybackServiceInterface.EXTRA_PLAYABLE); if (keycode == -1 && playable == null) { Log.e(TAG, "PlaybackService was started with no arguments"); stateManager.stopService(); @@ -505,9 +473,11 @@ public class PlaybackService extends MediaBrowserServiceCompat { } } else { stateManager.validStartCommandWasReceived(); - boolean allowStreamThisTime = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_THIS_TIME, false); - boolean allowStreamAlways = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_ALWAYS, false); - sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0); + boolean allowStreamThisTime = intent.getBooleanExtra( + PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME, false); + boolean allowStreamAlways = intent.getBooleanExtra( + PlaybackServiceInterface.EXTRA_ALLOW_STREAM_ALWAYS, false); + sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD, 0); if (allowStreamAlways) { UserPreferences.setAllowMobileStreaming(true); } @@ -561,8 +531,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { private void displayStreamingNotAllowedNotification(Intent originalIntent) { Intent intentAllowThisTime = new Intent(originalIntent); - intentAllowThisTime.setAction(EXTRA_ALLOW_STREAM_THIS_TIME); - intentAllowThisTime.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true); + intentAllowThisTime.setAction(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME); + intentAllowThisTime.putExtra(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME, true); PendingIntent pendingIntentAllowThisTime; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { pendingIntentAllowThisTime = PendingIntent.getForegroundService(this, @@ -575,8 +545,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { } Intent intentAlwaysAllow = new Intent(intentAllowThisTime); - intentAlwaysAllow.setAction(EXTRA_ALLOW_STREAM_ALWAYS); - intentAlwaysAllow.putExtra(EXTRA_ALLOW_STREAM_ALWAYS, true); + intentAlwaysAllow.setAction(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_ALWAYS); + intentAlwaysAllow.putExtra(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_ALWAYS, true); PendingIntent pendingIntentAlwaysAllow; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this, @@ -766,7 +736,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { @Override public void onChapterLoaded(Playable media) { - sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0); + sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD, 0); } }; @@ -848,7 +818,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { public void onMediaChanged(boolean reloadUI) { Log.d(TAG, "reloadUI callback reached"); if (reloadUI) { - sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0); + sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD, 0); } updateNotificationAndMediaSession(getPlayable()); } @@ -1011,11 +981,12 @@ public class PlaybackService extends MediaBrowserServiceCompat { } } if (mediaType == null) { - sendNotificationBroadcast(NOTIFICATION_TYPE_PLAYBACK_END, 0); + sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_PLAYBACK_END, 0); } else { - sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, - isCasting ? EXTRA_CODE_CAST : - (mediaType == MediaType.VIDEO) ? EXTRA_CODE_VIDEO : EXTRA_CODE_AUDIO); + sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD, + isCasting ? PlaybackServiceInterface.EXTRA_CODE_CAST : + (mediaType == MediaType.VIDEO) ? PlaybackServiceInterface.EXTRA_CODE_VIDEO : + PlaybackServiceInterface.EXTRA_CODE_AUDIO); } } @@ -1114,9 +1085,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { } private void sendNotificationBroadcast(int type, int code) { - Intent intent = new Intent(ACTION_PLAYER_NOTIFICATION); - intent.putExtra(EXTRA_NOTIFICATION_TYPE, type); - intent.putExtra(EXTRA_NOTIFICATION_CODE, code); + Intent intent = new Intent(PlaybackServiceInterface.ACTION_PLAYER_NOTIFICATION); + intent.putExtra(PlaybackServiceInterface.EXTRA_NOTIFICATION_TYPE, type); + intent.putExtra(PlaybackServiceInterface.EXTRA_NOTIFICATION_CODE, code); intent.setPackage(getPackageName()); sendBroadcast(intent); } @@ -1521,7 +1492,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { @Override public void onReceive(Context context, Intent intent) { - if (TextUtils.equals(intent.getAction(), ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { + if (TextUtils.equals(intent.getAction(), PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { EventBus.getDefault().post(new PlaybackServiceEvent(PlaybackServiceEvent.Action.SERVICE_SHUT_DOWN)); stateManager.stopService(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceInterface.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceInterface.java new file mode 100644 index 000000000..18ead601d --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceInterface.java @@ -0,0 +1,20 @@ +package de.danoeh.antennapod.core.service.playback; + +public abstract class PlaybackServiceInterface { + 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 ACTION_PLAYER_NOTIFICATION + = "action.de.danoeh.antennapod.core.service.playerNotification"; + public static final String EXTRA_NOTIFICATION_CODE = "extra.de.danoeh.antennapod.core.service.notificationCode"; + public static final String EXTRA_NOTIFICATION_TYPE = "extra.de.danoeh.antennapod.core.service.notificationType"; + public static final int NOTIFICATION_TYPE_PLAYBACK_END = 7; + public static final int NOTIFICATION_TYPE_RELOAD = 3; + public static final int EXTRA_CODE_AUDIO = 1; // Used in NOTIFICATION_TYPE_RELOAD + public static final int EXTRA_CODE_VIDEO = 2; + public static final int EXTRA_CODE_CAST = 3; + + public static final String ACTION_SHUTDOWN_PLAYBACK_SERVICE + = "action.de.danoeh.antennapod.core.service.actionShutdownPlaybackService"; +} diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index 91754e057..083916ff9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -9,6 +9,7 @@ import androidx.annotation.Nullable; import androidx.core.app.NotificationManagerCompat; import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface; import de.danoeh.antennapod.storage.database.PodDBAdapter; import org.greenrobot.eventbus.EventBus; @@ -36,7 +37,6 @@ import de.danoeh.antennapod.core.feed.FeedEvent; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.model.download.DownloadStatus; -import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink; import de.danoeh.antennapod.core.util.FeedItemPermutors; import de.danoeh.antennapod.core.util.IntentUtils; @@ -128,7 +128,7 @@ public class DBWriter { if (media.getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId()) { PlaybackPreferences.writeNoMediaPlaying(); - IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE); + IntentUtils.sendLocalBroadcast(context, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE); NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.cancel(R.id.notification_playing); @@ -201,7 +201,7 @@ public class DBWriter { if (item.getMedia().getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId()) { // Applies to both downloaded and streamed media PlaybackPreferences.writeNoMediaPlaying(); - IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE); + IntentUtils.sendLocalBroadcast(context, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE); } if (item.getMedia().isDownloaded()) { deleteFeedMediaSynchronous(context, item.getMedia()); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java index e6f6654ca..93d354096 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java @@ -4,8 +4,6 @@ import androidx.annotation.NonNull; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; -import de.danoeh.antennapod.core.service.playback.PlaybackService; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; 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 06757a1e2..a08694e66 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 @@ -12,6 +12,7 @@ import android.util.Log; import android.util.Pair; import android.view.SurfaceHolder; import androidx.annotation.NonNull; +import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.event.playback.PlaybackPositionEvent; import de.danoeh.antennapod.model.feed.FeedMedia; @@ -84,10 +85,9 @@ public abstract class PlaybackController { initialized = true; activity.registerReceiver(statusUpdate, new IntentFilter( - PlaybackService.ACTION_PLAYER_STATUS_CHANGED)); - + PlaybackService.ACTION_PLAYER_STATUS_CHANGED)); activity.registerReceiver(notificationReceiver, new IntentFilter( - PlaybackService.ACTION_PLAYER_NOTIFICATION)); + PlaybackServiceInterface.ACTION_PLAYER_NOTIFICATION)); if (!released) { bindToService(); @@ -202,14 +202,14 @@ public abstract class PlaybackController { @Override public void onReceive(Context context, Intent intent) { - int type = intent.getIntExtra(PlaybackService.EXTRA_NOTIFICATION_TYPE, -1); - int code = intent.getIntExtra(PlaybackService.EXTRA_NOTIFICATION_CODE, -1); + int type = intent.getIntExtra(PlaybackServiceInterface.EXTRA_NOTIFICATION_TYPE, -1); + int code = intent.getIntExtra(PlaybackServiceInterface.EXTRA_NOTIFICATION_CODE, -1); if (code == -1 || type == -1) { Log.d(TAG, "Bad arguments. Won't handle intent"); return; } switch (type) { - case PlaybackService.NOTIFICATION_TYPE_RELOAD: + case PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD: if (playbackService == null && PlaybackService.isRunning) { bindToService(); return; @@ -217,7 +217,7 @@ public abstract class PlaybackController { mediaInfoLoaded = false; queryService(); break; - case PlaybackService.NOTIFICATION_TYPE_PLAYBACK_END: + case PlaybackServiceInterface.NOTIFICATION_TYPE_PLAYBACK_END: onPlaybackEnd(); break; } 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 62d981b55..3b20e3d25 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 @@ -6,6 +6,7 @@ import android.os.Parcelable; import androidx.core.content.ContextCompat; import de.danoeh.antennapod.core.service.playback.PlaybackService; +import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface; import de.danoeh.antennapod.model.playback.Playable; public class PlaybackServiceStarter { @@ -34,8 +35,8 @@ public class PlaybackServiceStarter { public Intent getIntent() { Intent launchIntent = new Intent(context, PlaybackService.class); - launchIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, (Parcelable) media); - launchIntent.putExtra(PlaybackService.EXTRA_ALLOW_STREAM_THIS_TIME, shouldStreamThisTime); + launchIntent.putExtra(PlaybackServiceInterface.EXTRA_PLAYABLE, (Parcelable) media); + launchIntent.putExtra(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME, shouldStreamThisTime); return launchIntent; } |