use of androidx.core.app.NotificationManagerCompat in project AntennaPod by AntennaPod.
the class DBWriter method deleteFeedMediaSynchronous.
private static boolean deleteFeedMediaSynchronous(@NonNull Context context, @NonNull FeedMedia media) {
Log.i(TAG, String.format(Locale.US, "Requested to delete FeedMedia [id=%d, title=%s, downloaded=%s", media.getId(), media.getEpisodeTitle(), media.isDownloaded()));
if (media.isDownloaded()) {
// delete downloaded media file
File mediaFile = new File(media.getFile_url());
if (mediaFile.exists() && !mediaFile.delete()) {
MessageEvent evt = new MessageEvent(context.getString(R.string.delete_failed));
EventBus.getDefault().post(evt);
return false;
}
media.setDownloaded(false);
media.setFile_url(null);
media.setHasEmbeddedPicture(false);
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setMedia(media);
adapter.close();
if (media.getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId()) {
PlaybackPreferences.writeNoMediaPlaying();
IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
NotificationManagerCompat nm = NotificationManagerCompat.from(context);
nm.cancel(R.id.notification_playing);
}
// Gpodder: queue delete action for synchronization
FeedItem item = media.getItem();
EpisodeAction action = new EpisodeAction.Builder(item, EpisodeAction.DELETE).currentTimestamp().build();
SynchronizationQueueSink.enqueueEpisodeActionIfSynchronizationIsActive(context, action);
}
EventBus.getDefault().post(FeedItemEvent.deletedMedia(Collections.singletonList(media.getItem())));
return true;
}
use of androidx.core.app.NotificationManagerCompat in project AntennaPod by AntennaPod.
the class PlaybackService method onDestroy.
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "Service is about to be destroyed");
if (notificationBuilder.getPlayerStatus() == PlayerStatus.PLAYING) {
notificationBuilder.setPlayerStatus(PlayerStatus.STOPPED);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
}
stateManager.stopForeground(!UserPreferences.isPersistNotify());
isRunning = false;
currentMediaType = MediaType.UNKNOWN;
castStateListener.destroy();
cancelPositionObserver();
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(prefListener);
if (mediaSession != null) {
mediaSession.release();
}
unregisterReceiver(autoStateUpdated);
unregisterReceiver(headsetDisconnected);
unregisterReceiver(shutdownReceiver);
unregisterReceiver(bluetoothStateUpdated);
unregisterReceiver(audioBecomingNoisy);
unregisterReceiver(skipCurrentEpisodeReceiver);
unregisterReceiver(pausePlayCurrentEpisodeReceiver);
mediaPlayer.shutdown();
taskManager.shutdown();
}
use of androidx.core.app.NotificationManagerCompat in project AntennaPod by AntennaPod.
the class PlaybackService method displayStreamingNotAllowedNotification.
private void displayStreamingNotAllowedNotification(Intent originalIntent) {
Intent intentAllowThisTime = new Intent(originalIntent);
intentAllowThisTime.setAction(EXTRA_ALLOW_STREAM_THIS_TIME);
intentAllowThisTime.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true);
PendingIntent pendingIntentAllowThisTime;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
pendingIntentAllowThisTime = PendingIntent.getForegroundService(this, R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntentAllowThisTime = PendingIntent.getService(this, R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
}
Intent intentAlwaysAllow = new Intent(intentAllowThisTime);
intentAlwaysAllow.setAction(EXTRA_ALLOW_STREAM_ALWAYS);
intentAlwaysAllow.putExtra(EXTRA_ALLOW_STREAM_ALWAYS, true);
PendingIntent pendingIntentAlwaysAllow;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this, R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntentAlwaysAllow = PendingIntent.getService(this, R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_USER_ACTION).setSmallIcon(R.drawable.ic_notification_stream).setContentTitle(getString(R.string.confirm_mobile_streaming_notification_title)).setContentText(getString(R.string.confirm_mobile_streaming_notification_message)).setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.confirm_mobile_streaming_notification_message))).setPriority(NotificationCompat.PRIORITY_DEFAULT).setContentIntent(pendingIntentAllowThisTime).addAction(R.drawable.ic_notification_stream, getString(R.string.confirm_mobile_streaming_button_once), pendingIntentAllowThisTime).addAction(R.drawable.ic_notification_stream, getString(R.string.confirm_mobile_streaming_button_always), pendingIntentAlwaysAllow).setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(R.id.notification_streaming_confirmation, builder.build());
}
use of androidx.core.app.NotificationManagerCompat in project AntennaPod by AntennaPod.
the class PlaybackService method setupNotification.
/**
* Prepares notification and starts the service in the foreground.
*/
private synchronized void setupNotification(final Playable playable) {
Log.d(TAG, "setupNotification");
if (playableIconLoaderThread != null) {
playableIconLoaderThread.interrupt();
}
if (playable == null || mediaPlayer == null) {
Log.d(TAG, "setupNotification: playable=" + playable);
Log.d(TAG, "setupNotification: mediaPlayer=" + mediaPlayer);
if (!stateManager.hasReceivedValidStartCommand()) {
stateManager.stopService();
}
return;
}
PlayerStatus playerStatus = mediaPlayer.getPlayerStatus();
notificationBuilder.setPlayable(playable);
notificationBuilder.setMediaSessionToken(mediaSession.getSessionToken());
notificationBuilder.setPlayerStatus(playerStatus);
notificationBuilder.updatePosition(getCurrentPosition(), getCurrentPlaybackSpeed());
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
startForegroundIfPlaying(playerStatus);
if (!notificationBuilder.isIconCached()) {
playableIconLoaderThread = new Thread(() -> {
Log.d(TAG, "Loading notification icon");
notificationBuilder.loadIcon();
if (!Thread.currentThread().isInterrupted()) {
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
updateMediaSessionMetadata(playable);
}
});
playableIconLoaderThread.start();
}
}
use of androidx.core.app.NotificationManagerCompat in project AntennaPod by AntennaPod.
the class PlaybackService method startForegroundIfPlaying.
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());
}
}
}
Aggregations