Search in sources :

Example 6 with UnreadItemsUpdateEvent

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

the class DBWriter method markAllItemsRead.

/**
 * Sets the 'read'-attribute of all FeedItems to PLAYED.
 */
public static Future<?> markAllItemsRead() {
    return dbExec.submit(() -> {
        final PodDBAdapter adapter = PodDBAdapter.getInstance();
        adapter.open();
        adapter.setFeedItems(FeedItem.PLAYED);
        adapter.close();
        EventBus.getDefault().post(new UnreadItemsUpdateEvent());
    });
}
Also used : UnreadItemsUpdateEvent(de.danoeh.antennapod.event.UnreadItemsUpdateEvent)

Example 7 with UnreadItemsUpdateEvent

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

the class DBWriter method removeFeedNewFlag.

/**
 * Sets the 'read'-attribute of all NEW FeedItems of a specific Feed to UNPLAYED.
 *
 * @param feedId ID of the Feed.
 */
public static Future<?> removeFeedNewFlag(final long feedId) {
    return dbExec.submit(() -> {
        final PodDBAdapter adapter = PodDBAdapter.getInstance();
        adapter.open();
        adapter.setFeedItems(FeedItem.NEW, FeedItem.UNPLAYED, feedId);
        adapter.close();
        EventBus.getDefault().post(new UnreadItemsUpdateEvent());
    });
}
Also used : UnreadItemsUpdateEvent(de.danoeh.antennapod.event.UnreadItemsUpdateEvent)

Example 8 with UnreadItemsUpdateEvent

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

the class DBWriter method markItemPlayed.

@NonNull
private static Future<?> markItemPlayed(final long itemId, final int played, final long mediaId, final boolean resetMediaPosition) {
    return dbExec.submit(() -> {
        final PodDBAdapter adapter = PodDBAdapter.getInstance();
        adapter.open();
        adapter.setFeedItemRead(played, itemId, mediaId, resetMediaPosition);
        adapter.close();
        EventBus.getDefault().post(new UnreadItemsUpdateEvent());
    });
}
Also used : UnreadItemsUpdateEvent(de.danoeh.antennapod.event.UnreadItemsUpdateEvent) NonNull(androidx.annotation.NonNull)

Example 9 with UnreadItemsUpdateEvent

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

the class MediaDownloadedHandler method run.

@Override
public void run() {
    updatedStatus = status;
    FeedMedia media = DBReader.getFeedMedia(request.getFeedfileId());
    if (media == null) {
        Log.e(TAG, "Could not find downloaded media object in database");
        return;
    }
    // media.setDownloaded modifies played state
    boolean broadcastUnreadStateUpdate = media.getItem() != null && media.getItem().isNew();
    media.setDownloaded(true);
    media.setFile_url(request.getDestination());
    media.setSize(new File(request.getDestination()).length());
    // enforce check
    media.checkEmbeddedPicture();
    // check if file has chapters
    if (media.getItem() != null && !media.getItem().hasChapters()) {
        media.setChapters(ChapterUtils.loadChaptersFromMediaFile(media, context));
    }
    // Get duration
    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    String durationStr = null;
    try {
        mmr.setDataSource(media.getFile_url());
        durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
        media.setDuration(Integer.parseInt(durationStr));
        Log.d(TAG, "Duration of file is " + media.getDuration());
    } catch (NumberFormatException e) {
        Log.d(TAG, "Invalid file duration: " + durationStr);
    } catch (Exception e) {
        Log.e(TAG, "Get duration failed", e);
    } finally {
        mmr.release();
    }
    final FeedItem item = media.getItem();
    try {
        DBWriter.setFeedMedia(media).get();
        // we've received the media, we don't want to autodownload it again
        if (item != null) {
            item.disableAutoDownload();
            // setFeedItem() signals (via EventBus) that the item has been updated,
            // so we do it after the enclosing media has been updated above,
            // to ensure subscribers will get the updated FeedMedia as well
            DBWriter.setFeedItem(item).get();
            if (broadcastUnreadStateUpdate) {
                EventBus.getDefault().post(new UnreadItemsUpdateEvent());
            }
        }
    } catch (InterruptedException e) {
        Log.e(TAG, "MediaHandlerThread was interrupted");
    } catch (ExecutionException e) {
        Log.e(TAG, "ExecutionException in MediaHandlerThread: " + e.getMessage());
        updatedStatus = new DownloadStatus(media, media.getEpisodeTitle(), DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage(), request.isInitiatedByUser());
    }
    if (item != null) {
        EpisodeAction action = new EpisodeAction.Builder(item, EpisodeAction.DOWNLOAD).currentTimestamp().build();
        SynchronizationQueueSink.enqueueEpisodeActionIfSynchronizationIsActive(context, action);
    }
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) UnreadItemsUpdateEvent(de.danoeh.antennapod.event.UnreadItemsUpdateEvent) MediaMetadataRetriever(android.media.MediaMetadataRetriever) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File)

Example 10 with UnreadItemsUpdateEvent

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

the class SubscriptionsFilterDialog method updateFilter.

private static void updateFilter(Set<String> filterValues) {
    SubscriptionsFilter subscriptionsFilter = new SubscriptionsFilter(filterValues.toArray(new String[0]));
    UserPreferences.setSubscriptionsFilter(subscriptionsFilter);
    EventBus.getDefault().post(new UnreadItemsUpdateEvent());
}
Also used : UnreadItemsUpdateEvent(de.danoeh.antennapod.event.UnreadItemsUpdateEvent) SubscriptionsFilter(de.danoeh.antennapod.core.feed.SubscriptionsFilter)

Aggregations

UnreadItemsUpdateEvent (de.danoeh.antennapod.event.UnreadItemsUpdateEvent)12 AlertDialog (androidx.appcompat.app.AlertDialog)2 PreferenceActivity (de.danoeh.antennapod.activity.PreferenceActivity)2 Activity (android.app.Activity)1 Context (android.content.Context)1 MediaMetadataRetriever (android.media.MediaMetadataRetriever)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 ActivityCompat (androidx.core.app.ActivityCompat)1 ListPreference (androidx.preference.ListPreference)1 PreferenceFragmentCompat (androidx.preference.PreferenceFragmentCompat)1 Snackbar (com.google.android.material.snackbar.Snackbar)1 Balloon (com.skydoves.balloon.Balloon)1 R (de.danoeh.antennapod.R)1 MainActivity (de.danoeh.antennapod.activity.MainActivity)1 CancelDownloadActionButton (de.danoeh.antennapod.adapter.actionbutton.CancelDownloadActionButton)1