refactor stop PlaybackService setupNotification() - extract common
code as private helper.
This commit is contained in:
parent
f0f8623937
commit
221cd4b480
|
@ -1336,29 +1336,30 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||||
Log.v(TAG, "DBG - notificationSetupTask: make service foreground");
|
Log.v(TAG, "DBG - notificationSetupTask: make service foreground");
|
||||||
startForeground(NOTIFICATION_ID, notification);
|
startForeground(NOTIFICATION_ID, notification);
|
||||||
} else if (playerStatus == PlayerStatus.PAUSED) {
|
} else if (playerStatus == PlayerStatus.PAUSED) {
|
||||||
// TODO: logic originally in mediaPlayerCallback case PAUSED.
|
|
||||||
if (treatPauseAsStop) {
|
if (treatPauseAsStop) {
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
} else if ((UserPreferences.isPersistNotify() || isCasting) &&
|
} else if ((UserPreferences.isPersistNotify() || isCasting) &&
|
||||||
android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
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
|
// do not remove notification on pause based on user pref and whether android version supports expanded notifications
|
||||||
// Change [Play] button to [Pause]
|
// Change [Play] button to [Pause]
|
||||||
// TODO LATER: logic same as outer else clause: setupNotification(info)
|
leaveNotificationAsBackground(notification);
|
||||||
stopForeground(false);
|
|
||||||
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
||||||
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
|
||||||
} else if (!UserPreferences.isPersistNotify() && !isCasting) {
|
} else if (!UserPreferences.isPersistNotify() && !isCasting) {
|
||||||
// remove notification on pause
|
// remove notification on pause
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stopForeground(false);
|
leaveNotificationAsBackground(notification);
|
||||||
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
||||||
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Notification set up");
|
Log.d(TAG, "Notification set up");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void leaveNotificationAsBackground(@NonNull Notification notification) {
|
||||||
|
stopForeground(false);
|
||||||
|
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
notificationSetupThread = new Thread(notificationSetupTask);
|
notificationSetupThread = new Thread(notificationSetupTask);
|
||||||
notificationSetupThread.start();
|
notificationSetupThread.start();
|
||||||
|
|
Loading…
Reference in New Issue