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());
});
}
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());
});
}
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());
});
}
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);
}
}
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());
}
Aggregations