Search in sources :

Example 16 with NotificationManagerCompat

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;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) MessageEvent(de.danoeh.antennapod.event.MessageEvent) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) File(java.io.File) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction)

Example 17 with NotificationManagerCompat

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();
}
Also used : NotificationManagerCompat(androidx.core.app.NotificationManagerCompat)

Example 18 with NotificationManagerCompat

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());
}
Also used : NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 19 with NotificationManagerCompat

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();
    }
}
Also used : PlayerStatus(de.danoeh.antennapod.playback.base.PlayerStatus) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat)

Example 20 with NotificationManagerCompat

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());
        }
    }
}
Also used : NotificationManagerCompat(androidx.core.app.NotificationManagerCompat)

Aggregations

NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)26 PendingIntent (android.app.PendingIntent)6 Notification (android.app.Notification)5 Intent (android.content.Intent)5 NotificationCompat (androidx.core.app.NotificationCompat)5 NotificationChannel (android.app.NotificationChannel)2 NotificationManager (android.app.NotificationManager)2 Bundle (android.os.Bundle)2 NotificationChannelCompat (androidx.core.app.NotificationChannelCompat)2 TaskStackBuilder (android.app.TaskStackBuilder)1 Bitmap (android.graphics.Bitmap)1 RequiresApi (androidx.annotation.RequiresApi)1 NotificationChannelGroupCompat (androidx.core.app.NotificationChannelGroupCompat)1 WearableExtender (androidx.core.app.NotificationCompat.WearableExtender)1 RemoteInput (androidx.core.app.RemoteInput)1 TaskStackBuilder (androidx.core.app.TaskStackBuilder)1 MediaStyle (androidx.media.app.NotificationCompat.MediaStyle)1 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)1 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)1 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)1