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
This commit is contained in:
Lee Yeong Khang 2014-12-20 17:25:52 +09:00
parent e9ed796fd4
commit 282b29eb5d
1 changed files with 25 additions and 7 deletions

View File

@ -290,7 +290,11 @@ public class PlaybackService extends Service {
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);
}
} 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();
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;
@ -776,9 +793,11 @@ public class PlaybackService extends Service {
getString(R.string.play_label),
playButtonPendingIntent);
}
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(
@ -1001,7 +1020,6 @@ public class PlaybackService extends Service {
mediaPlayer.pause(true, true);
}
}
}
private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {