diff options
author | ByteHamster <info@bytehamster.com> | 2023-02-20 23:19:34 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2023-02-20 23:19:34 +0100 |
commit | 2b22d4b6977f9a22abfd4bc2d269c79834551ee2 (patch) | |
tree | 58582dd73eafe2c536aa2c842b5609ded3735040 /core/src/main | |
parent | e58e2d063948fe52e5fed1536548b6c4220be8fb (diff) | |
parent | 2833812238c19d16d464c337adeecc575ff484ba (diff) | |
download | AntennaPod-2b22d4b6977f9a22abfd4bc2d269c79834551ee2.zip |
Merge branch 'master' into develop
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java | 58 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceStateManager.java | 5 | ||||
-rw-r--r-- | core/src/main/res/drawable-nodpi/launcher_animate_bg.png | bin | 0 -> 37291 bytes | |||
-rw-r--r-- | core/src/main/res/drawable-nodpi/launcher_animate_wave1.png | bin | 0 -> 20533 bytes | |||
-rw-r--r-- | core/src/main/res/drawable-nodpi/launcher_animate_wave2.png | bin | 0 -> 31797 bytes | |||
-rw-r--r-- | core/src/main/res/drawable/launcher_animate.xml | 45 | ||||
-rw-r--r-- | core/src/main/res/drawable/splash_icon.xml | 35 | ||||
-rw-r--r-- | core/src/main/res/values/styles.xml | 2 |
8 files changed, 78 insertions, 67 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 14e11af23..176a78f0f 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 @@ -220,6 +220,24 @@ public class PlaybackService extends MediaBrowserServiceCompat { PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(prefListener); + recreateMediaSessionIfNeeded(); + castStateListener = new CastStateListener(this) { + @Override + public void onSessionStartedOrEnded() { + recreateMediaPlayer(); + } + }; + EventBus.getDefault().post(new PlaybackServiceEvent(PlaybackServiceEvent.Action.SERVICE_STARTED)); + } + + void recreateMediaSessionIfNeeded() { + if (mediaSession != null) { + // Media session was not destroyed, so we can re-use it. + if (!mediaSession.isActive()) { + mediaSession.setActive(true); + } + return; + } ComponentName eventReceiver = new ComponentName(getApplicationContext(), MediaButtonReceiver.class); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(eventReceiver); @@ -243,13 +261,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { recreateMediaPlayer(); mediaSession.setActive(true); - castStateListener = new CastStateListener(this) { - @Override - public void onSessionStartedOrEnded() { - recreateMediaPlayer(); - } - }; - EventBus.getDefault().post(new PlaybackServiceEvent(PlaybackServiceEvent.Action.SERVICE_STARTED)); } void recreateMediaPlayer() { @@ -290,6 +301,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(prefListener); if (mediaSession != null) { mediaSession.release(); + mediaSession = null; } unregisterReceiver(autoStateUpdated); unregisterReceiver(headsetDisconnected); @@ -702,6 +714,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { mediaPlayer.playMediaObject(playable, stream, true, true); stateManager.validStartCommandWasReceived(); + stateManager.startForeground(R.id.notification_playing, notificationBuilder.build()); + recreateMediaSessionIfNeeded(); updateNotificationAndMediaSession(playable); addPlayableToQueue(playable); } @@ -760,13 +774,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { taskManager.startChapterLoader(newInfo.playable); break; case PAUSED: - if (UserPreferences.isPersistNotify() || isCasting) { - // do not remove notification on pause based on user pref - // Change [Play] button to [Pause] - updateNotificationAndMediaSession(newInfo.playable); - } else if (!UserPreferences.isPersistNotify() && !isCasting) { - // remove notification on pause - stateManager.stopForeground(true); + updateNotificationAndMediaSession(newInfo.playable); + if (!isCasting) { + stateManager.stopForeground(!UserPreferences.isPersistNotify()); } cancelPositionObserver(); PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus()); @@ -778,9 +788,11 @@ public class PlaybackService extends MediaBrowserServiceCompat { case PLAYING: PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus()); saveCurrentPosition(true, null, Playable.INVALID_TIME); + recreateMediaSessionIfNeeded(); updateNotificationAndMediaSession(newInfo.playable); setupPositionObserver(); stateManager.validStartCommandWasReceived(); + stateManager.startForeground(R.id.notification_playing, notificationBuilder.build()); // set sleep timer if auto-enabled if (newInfo.oldPlayerStatus != null && newInfo.oldPlayerStatus != PlayerStatus.SEEKING && SleepTimerPreferences.autoEnable() && !sleepTimerActive()) { @@ -811,7 +823,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { @Override public void shouldStop() { - updateNotificationAndMediaSession(getPlayable()); // Stops foreground if not playing + stateManager.stopForeground(!UserPreferences.isPersistNotify()); } @Override @@ -1271,7 +1283,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(R.id.notification_playing, notificationBuilder.build()); - startForegroundIfPlaying(playerStatus); if (!notificationBuilder.isIconCached()) { playableIconLoaderThread = new Thread(() -> { @@ -1286,21 +1297,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { } } - private void startForegroundIfPlaying(@NonNull PlayerStatus status) { - Log.d(TAG, "startForegroundIfPlaying: " + status); - if (stateManager.hasReceivedValidStartCommand()) { - if (isCasting || status == PlayerStatus.PLAYING || status == PlayerStatus.PREPARING - || status == PlayerStatus.SEEKING) { - stateManager.startForeground(R.id.notification_playing, notificationBuilder.build()); - Log.d(TAG, "foreground"); - } else { - stateManager.stopForeground(false); - NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); - notificationManager.notify(R.id.notification_playing, notificationBuilder.build()); - } - } - } - /** * Persists the current position and last played time of the media file. * diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceStateManager.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceStateManager.java index addc6b996..9926e01da 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceStateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceStateManager.java @@ -1,10 +1,12 @@ package de.danoeh.antennapod.core.service.playback; import android.app.Notification; +import android.util.Log; import androidx.core.app.ServiceCompat; class PlaybackServiceStateManager { + private static final String TAG = "PlaybackSrvState"; private final PlaybackService playbackService; private volatile boolean isInForeground = false; @@ -15,17 +17,20 @@ class PlaybackServiceStateManager { } void startForeground(int notificationId, Notification notification) { + Log.d(TAG, "startForeground"); playbackService.startForeground(notificationId, notification); isInForeground = true; } void stopService() { + Log.d(TAG, "stopService"); stopForeground(true); playbackService.stopSelf(); hasReceivedValidStartCommand = false; } void stopForeground(boolean removeNotification) { + Log.d(TAG, "stopForeground"); if (isInForeground) { if (removeNotification) { ServiceCompat.stopForeground(playbackService, ServiceCompat.STOP_FOREGROUND_REMOVE); diff --git a/core/src/main/res/drawable-nodpi/launcher_animate_bg.png b/core/src/main/res/drawable-nodpi/launcher_animate_bg.png Binary files differnew file mode 100644 index 000000000..00eb3a2d6 --- /dev/null +++ b/core/src/main/res/drawable-nodpi/launcher_animate_bg.png diff --git a/core/src/main/res/drawable-nodpi/launcher_animate_wave1.png b/core/src/main/res/drawable-nodpi/launcher_animate_wave1.png Binary files differnew file mode 100644 index 000000000..432e497c3 --- /dev/null +++ b/core/src/main/res/drawable-nodpi/launcher_animate_wave1.png diff --git a/core/src/main/res/drawable-nodpi/launcher_animate_wave2.png b/core/src/main/res/drawable-nodpi/launcher_animate_wave2.png Binary files differnew file mode 100644 index 000000000..16d4e5023 --- /dev/null +++ b/core/src/main/res/drawable-nodpi/launcher_animate_wave2.png diff --git a/core/src/main/res/drawable/launcher_animate.xml b/core/src/main/res/drawable/launcher_animate.xml new file mode 100644 index 000000000..189a01d26 --- /dev/null +++ b/core/src/main/res/drawable/launcher_animate.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<animation-list + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:aapt="http://schemas.android.com/aapt" + android:oneshot="false"> + + <item android:duration="1000"> + <aapt:attr name="android:drawable"> + <layer-list> + <item android:drawable="@drawable/launcher_animate_bg" /> + <item android:drawable="@drawable/launcher_animate_wave1" /> + <item android:drawable="@drawable/launcher_animate_wave2" /> + </layer-list> + </aapt:attr> + </item> + + <item android:duration="80"> + <aapt:attr name="android:drawable"> + <layer-list> + <item android:drawable="@drawable/launcher_animate_bg" /> + <item android:drawable="@drawable/launcher_animate_wave1" /> + </layer-list> + </aapt:attr> + </item> + + <item android:duration="200"> + <aapt:attr name="android:drawable"> + <layer-list> + <item android:drawable="@drawable/launcher_animate_bg" /> + </layer-list> + </aapt:attr> + </item> + + <item android:duration="80"> + <aapt:attr name="android:drawable"> + <layer-list> + <item android:drawable="@drawable/launcher_animate_bg" /> + <item android:drawable="@drawable/launcher_animate_wave1" /> + </layer-list> + </aapt:attr> + </item> + +</animation-list> + + diff --git a/core/src/main/res/drawable/splash_icon.xml b/core/src/main/res/drawable/splash_icon.xml deleted file mode 100644 index acd17670e..000000000 --- a/core/src/main/res/drawable/splash_icon.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<animated-vector - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:aapt="http://schemas.android.com/aapt"> - - <aapt:attr name="android:drawable"> - <vector - android:height="80dp" android:width="80dp" - android:viewportHeight="72" android:viewportWidth="72"> - <group android:name="icon" android:pivotX="36" android:pivotY="36"> - <path android:fillColor="@color/accent_light" - android:pathData="M 36 23.4 A 12.6 12.6 90 0 0 23.4 36 A 12.6 12.6 90 0 0 30.96 47.515 L 34.46 37.61 C 34.04 37.19 33.76 36.63 33.76 36 c 0 -1.225 0.98 -2.24 2.24 -2.24 c 1.225 0 2.24 0.98 2.24 2.24 c 0 0.63 -0.245 1.19 -0.665 1.61 L 41.04 47.515 A 12.6 12.6 90 0 0 48.6 36 A 12.6 12.6 90 0 0 36 23.4 Z m 0 2.975 c 5.32 0 9.625 4.305 9.625 9.625 c 0 3.395 -1.75 6.37 -4.41 8.085 L 40.725 42.65 C 42.79 41.18 44.155 38.765 44.155 36 c 0 -4.515 -3.64 -8.155 -8.1602 -8.1364 c -4.515 0 -8.155 3.64 -8.155 8.155 c 0 2.765 1.365 5.18 3.43 6.65 L 30.785 44.085 C 28.125 42.37 26.375 39.395 26.375 36 C 26.375 30.68 30.68 26.375 36 26.375 Z m 0 3.71 c 3.29 0 5.915 2.66 5.915 5.915 c 0 1.785 -0.77 3.36 -1.995 4.445 l -0.56 -1.54 c 0.665 -0.77 1.085 -1.785 1.085 -2.905 c 0 -2.45 -1.995 -4.445 -4.445 -4.445 c -2.45 0 -4.445 1.995 -4.445 4.445 c 0 1.12 0.385 2.1 1.085 2.905 l -0.56 1.54 C 30.855 39.36 30.085 37.785 30.085 36 c 0 -3.29 2.66 -5.915 5.915 -5.915 z m 0 8.715 l -1.715 4.83 c 0.56 0.105 1.12 0.175 1.715 0.175 c 0.595 0 1.155 -0.07 1.715 -0.175 z m -2.31 6.58 l -0.98 2.8 a 12.6 12.6 90 0 0 3.29 0.455 a 12.6 12.6 90 0 0 3.29 -0.455 l -0.98 -2.8 c -0.735 0.175 -1.505 0.28 -2.31 0.28 c -0.805 0 -1.575 -0.105 -2.31 -0.28 z" /> - </group> - </vector> - </aapt:attr> - - <target android:name="icon"> - <aapt:attr name="android:animation"> - <objectAnimator - android:duration="1000" - android:repeatCount="infinite" - android:repeatMode="reverse"> - <propertyValuesHolder android:propertyName="scaleX" - android:valueType="floatType" - android:valueFrom="1.0" - android:valueTo="1.1" /> - <propertyValuesHolder android:propertyName="scaleY" - android:valueType="floatType" - android:valueFrom="1.0" - android:valueTo="1.1" /> - </objectAnimator> - </aapt:attr> - </target> - -</animated-vector>
\ No newline at end of file diff --git a/core/src/main/res/values/styles.xml b/core/src/main/res/values/styles.xml index 09e3cadf8..45f13931e 100644 --- a/core/src/main/res/values/styles.xml +++ b/core/src/main/res/values/styles.xml @@ -218,7 +218,7 @@ <item name="android:windowTranslucentNavigation">false</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:enforceNavigationBarContrast" tools:targetApi="q">false</item> - <item name="windowSplashScreenAnimatedIcon">@drawable/splash_icon</item> + <item name="windowSplashScreenAnimatedIcon">@drawable/launcher_animate</item> </style> <style name="Theme.AntennaPod.VideoPlayer" parent="@style/Theme.AntennaPod.Dark"> |