Search in sources :

Example 1 with MessageEvent

use of de.danoeh.antennapod.event.MessageEvent in project AntennaPod by AntennaPod.

the class DBTasks method notifyMissingFeedMediaFile.

/**
 * Notifies the database about a missing FeedMedia file. This method will correct the FeedMedia object's
 * values in the DB and send a FeedItemEvent.
 */
public static void notifyMissingFeedMediaFile(final Context context, final FeedMedia media) {
    Log.i(TAG, "The feedmanager was notified about a missing episode. It will update its database now.");
    media.setDownloaded(false);
    media.setFile_url(null);
    DBWriter.setFeedMedia(media);
    EventBus.getDefault().post(FeedItemEvent.deletedMedia(media.getItem()));
    EventBus.getDefault().post(new MessageEvent(context.getString(R.string.error_file_not_found)));
}
Also used : MessageEvent(de.danoeh.antennapod.event.MessageEvent)

Example 2 with MessageEvent

use of de.danoeh.antennapod.event.MessageEvent 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)

Aggregations

MessageEvent (de.danoeh.antennapod.event.MessageEvent)2 NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)1 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)1 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)1 File (java.io.File)1