From e9ed796fd432f8bcd9b41f52c2777b00cadcbed8 Mon Sep 17 00:00:00 2001 From: Lee Yeong Khang Date: Thu, 11 Dec 2014 19:54:58 +0900 Subject: [PATCH 1/3] Combine play and pause button into 1 detailed in https://github.com/danieloeh/AntennaPod/issues/574 --- .../service/playback/PlaybackService.java | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 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 a5560e3fb..7df4af504 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 @@ -284,18 +284,13 @@ public class PlaybackService extends Service { private void handleKeycode(int keycode) { if (BuildConfig.DEBUG) Log.d(TAG, "Handling keycode: " + keycode); - final PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo(); final PlayerStatus status = info.playerStatus; switch (keycode) { case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: if (status == PlayerStatus.PLAYING) { - if (UserPreferences.isPersistNotify()) { - mediaPlayer.pause(false, true); - } else { - mediaPlayer.pause(true, true); - } + mediaPlayer.pause(false, true); } else if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) { mediaPlayer.resume(); } else if (status == PlayerStatus.PREPARING) { @@ -315,11 +310,7 @@ public class PlaybackService extends Service { break; case KeyEvent.KEYCODE_MEDIA_PAUSE: if (status == PlayerStatus.PLAYING) { - if (UserPreferences.isPersistNotify()) { - mediaPlayer.pause(false, true); - } else { - mediaPlayer.pause(true, true); - } + mediaPlayer.pause(false, true); } break; case KeyEvent.KEYCODE_MEDIA_NEXT: @@ -333,7 +324,9 @@ public class PlaybackService extends Service { case KeyEvent.KEYCODE_MEDIA_STOP: if (status == PlayerStatus.PLAYING) { mediaPlayer.pause(true, true); + started = false; } + stopForeground(true); // gets rid of persistent notification break; default: @@ -409,12 +402,8 @@ public class PlaybackService extends Service { taskManager.cancelPositionSaver(); saveCurrentPosition(false, 0); taskManager.cancelWidgetUpdater(); - if (UserPreferences.isPersistNotify() && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - // do not remove notification on pause based on user pref and whether android version supports expanded notifications - } else { - // remove notifcation on pause - stopForeground(true); - } + setupNotification(newInfo); + break; case STOPPED: @@ -431,6 +420,7 @@ public class PlaybackService extends Service { taskManager.startPositionSaver(); taskManager.startWidgetUpdater(); setupNotification(newInfo); + started = true; break; case ERROR: writePlaybackPreferencesNoMediaPlaying(); @@ -734,8 +724,9 @@ public class PlaybackService extends Service { PlaybackServiceMediaPlayer.PSMPInfo newInfo = mediaPlayer.getPSMPInfo(); final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext()); - if (!isCancelled() && info.playerStatus == PlayerStatus.PLAYING - && info.playable != null) { + if (!isCancelled() && + started == true && + info.playable != null) { String contentText = info.playable.getFeedTitle(); String contentTitle = info.playable.getEpisodeTitle(); Notification notification = null; @@ -775,14 +766,17 @@ public class PlaybackService extends Service { .setContentIntent(pIntent) .setLargeIcon(icon) .setSmallIcon(smallIcon) - .setPriority(UserPreferences.getNotifyPriority()) // set notification priority - .addAction(android.R.drawable.ic_media_play, //play action - getString(R.string.play_label), - playButtonPendingIntent) - .addAction(android.R.drawable.ic_media_pause, //pause action - getString(R.string.pause_label), - pauseButtonPendingIntent) - .addAction(android.R.drawable.ic_menu_close_clear_cancel, // stop action + .setPriority(UserPreferences.getNotifyPriority()); // set notification priority + if(newInfo.playerStatus==PlayerStatus.PLAYING){ + notificationBuilder.addAction(android.R.drawable.ic_media_pause, //pause action + getString(R.string.pause_label), + pauseButtonPendingIntent); + } else { + notificationBuilder.addAction(android.R.drawable.ic_media_play, //play action + getString(R.string.play_label), + playButtonPendingIntent); + } + notificationBuilder.addAction(android.R.drawable.ic_menu_close_clear_cancel, // stop action getString(R.string.stop_label), stopButtonPendingIntent); notification = notificationBuilder.build(); @@ -795,9 +789,7 @@ public class PlaybackService extends Service { .setSmallIcon(smallIcon); notification = notificationBuilder.getNotification(); } - if (newInfo.playerStatus == PlayerStatus.PLAYING) { - startForeground(NOTIFICATION_ID, notification); - } + startForeground(NOTIFICATION_ID, notification); if (BuildConfig.DEBUG) Log.d(TAG, "Notification set up"); } From 282b29eb5d2b27379662854220476d591494265d Mon Sep 17 00:00:00 2001 From: Lee Yeong Khang Date: Sat, 20 Dec 2014 17:25:52 +0900 Subject: [PATCH 2/3] Honor User Preference on Persistence notification commented in https://github.com/danieloeh/AntennaPod/pull/578#issuecomment-67489354 - option disabled notification has only "play/pause" button, hitting pause hides notification - option enabled notification has both "play/pause" button and "close" button, hitting pause does not hide notification --- .../service/playback/PlaybackService.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 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 7df4af504..649ca42b8 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 @@ -290,7 +290,11 @@ public class PlaybackService extends Service { case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: if (status == PlayerStatus.PLAYING) { - mediaPlayer.pause(false, true); + if (UserPreferences.isPersistNotify()) { + mediaPlayer.pause(false, true); + } else { + mediaPlayer.pause(true, true); + } } else if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) { mediaPlayer.resume(); } else if (status == PlayerStatus.PREPARING) { @@ -312,6 +316,12 @@ public class PlaybackService extends Service { if (status == PlayerStatus.PLAYING) { mediaPlayer.pause(false, true); } + if (UserPreferences.isPersistNotify()) { + mediaPlayer.pause(false, true); + } else { + mediaPlayer.pause(true, true); + } + break; case KeyEvent.KEYCODE_MEDIA_NEXT: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: @@ -402,7 +412,14 @@ public class PlaybackService extends Service { taskManager.cancelPositionSaver(); saveCurrentPosition(false, 0); taskManager.cancelWidgetUpdater(); - setupNotification(newInfo); + if (UserPreferences.isPersistNotify() && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + // do not remove notification on pause based on user pref and whether android version supports expanded notifications + // Change [Play] button to [Pause] + setupNotification(newInfo); + } else { + // remove notifcation on pause + stopForeground(true); + } break; @@ -767,7 +784,7 @@ public class PlaybackService extends Service { .setLargeIcon(icon) .setSmallIcon(smallIcon) .setPriority(UserPreferences.getNotifyPriority()); // set notification priority - if(newInfo.playerStatus==PlayerStatus.PLAYING){ + if(newInfo.playerStatus == PlayerStatus.PLAYING){ notificationBuilder.addAction(android.R.drawable.ic_media_pause, //pause action getString(R.string.pause_label), pauseButtonPendingIntent); @@ -776,9 +793,11 @@ public class PlaybackService extends Service { getString(R.string.play_label), playButtonPendingIntent); } - notificationBuilder.addAction(android.R.drawable.ic_menu_close_clear_cancel, // stop action - getString(R.string.stop_label), - stopButtonPendingIntent); + if(UserPreferences.isPersistNotify()) { + notificationBuilder.addAction(android.R.drawable.ic_menu_close_clear_cancel, // stop action + getString(R.string.stop_label), + stopButtonPendingIntent); + } notification = notificationBuilder.build(); } else { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( @@ -1000,7 +1019,6 @@ public class PlaybackService extends Service { } else { mediaPlayer.pause(true, true); } - } } private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() { From 5f503cc5fde5c4fc38536090f5c30bdf7d184818 Mon Sep 17 00:00:00 2001 From: Lee Yeong Khang Date: Thu, 25 Dec 2014 15:23:10 +0900 Subject: [PATCH 3/3] Adding Missing semicolon --- .../danoeh/antennapod/core/service/playback/PlaybackService.java | 1 + 1 file changed, 1 insertion(+) 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 649ca42b8..04e29a054 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 @@ -1019,6 +1019,7 @@ public class PlaybackService extends Service { } else { mediaPlayer.pause(true, true); } + } } private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {