Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisMediaSession.java
Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Line(s) | 161 | private void updateCurrentPlayer(BackgroundService service) { | |||
---|---|---|---|---|---|
206 | notificationDevice = device == null ? null : device.getDeviceId(); | 206 | notificationDevice = device == null ? null : device.getDeviceId(); | ||
207 | notificationPlayer = playing; | 207 | notificationPlayer = playing; | ||
208 | } | 208 | } | ||
209 | 209 | | |||
210 | /** | 210 | /** | ||
211 | * Update the media control notification | 211 | * Update the media control notification | ||
212 | */ | 212 | */ | ||
213 | private void updateMediaNotification() { | 213 | private void updateMediaNotification() { | ||
214 | BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() { | 214 | BackgroundService.RunCommand(context, service -> { | ||
215 | @Override | | |||
216 | public void onServiceStart(BackgroundService service) { | | |||
217 | //If the user disabled the media notification, do not show it | 215 | //If the user disabled the media notification, do not show it | ||
218 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | 216 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | ||
219 | if (!prefs.getBoolean(context.getString(R.string.mpris_notification_key), true)) { | 217 | if (!prefs.getBoolean(context.getString(R.string.mpris_notification_key), true)) { | ||
220 | closeMediaNotification(); | 218 | closeMediaNotification(); | ||
221 | return; | 219 | return; | ||
222 | } | 220 | } | ||
223 | 221 | | |||
224 | //Make sure our information is up-to-date | 222 | //Make sure our information is up-to-date | ||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Line(s) | |||||
389 | } | 387 | } | ||
390 | mediaStyle.setMediaSession(mediaSession.getSessionToken()); | 388 | mediaStyle.setMediaSession(mediaSession.getSessionToken()); | ||
391 | notification.setStyle(mediaStyle); | 389 | notification.setStyle(mediaStyle); | ||
392 | 390 | | |||
393 | //Display the notification | 391 | //Display the notification | ||
394 | mediaSession.setActive(true); | 392 | mediaSession.setActive(true); | ||
395 | final NotificationManager nm = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE); | 393 | final NotificationManager nm = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE); | ||
396 | nm.notify(MPRIS_MEDIA_NOTIFICATION_ID, notification.build()); | 394 | nm.notify(MPRIS_MEDIA_NOTIFICATION_ID, notification.build()); | ||
397 | } | | |||
398 | }); | 395 | }); | ||
399 | } | 396 | } | ||
400 | 397 | | |||
401 | public void closeMediaNotification() { | 398 | public void closeMediaNotification() { | ||
402 | //Remove the notification | 399 | //Remove the notification | ||
403 | NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | 400 | NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
404 | nm.cancel(MPRIS_MEDIA_NOTIFICATION_ID); | 401 | nm.cancel(MPRIS_MEDIA_NOTIFICATION_ID); | ||
405 | 402 | | |||
Show All 18 Lines |