Search in sources :

Example 31 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class QueueFragment method onEventMainThread.

public void onEventMainThread(FeedItemEvent event) {
    Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
    if (queue == null || recyclerAdapter == null) {
        return;
    }
    for (int i = 0, size = event.items.size(); i < size; i++) {
        FeedItem item = event.items.get(i);
        int pos = FeedItemUtil.indexOfItemWithId(queue, item.getId());
        if (pos >= 0) {
            queue.remove(pos);
            queue.add(pos, item);
            recyclerAdapter.notifyItemChanged(pos);
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Example 32 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class CastUtils method convertFromFeedMedia.

/**
     * Converts {@link FeedMedia} objects into a format suitable for sending to a Cast Device.
     * Before using this method, one should make sure {@link #isCastable(Playable)} returns
     * {@code true}.
     *
     * Unless media.{@link FeedMedia#loadMetadata() loadMetadata()} has already been called,
     * this method should not run on the main thread.
     *
     * @param media The {@link FeedMedia} object to be converted.
     * @return {@link MediaInfo} object in a format proper for casting.
     */
public static MediaInfo convertFromFeedMedia(FeedMedia media) {
    if (media == null) {
        return null;
    }
    MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC);
    try {
        media.loadMetadata();
    } catch (Playable.PlayableException e) {
        Log.e(TAG, "Unable to load FeedMedia metadata", e);
    }
    FeedItem feedItem = media.getItem();
    if (feedItem != null) {
        metadata.putString(MediaMetadata.KEY_TITLE, media.getEpisodeTitle());
        String subtitle = media.getFeedTitle();
        if (subtitle != null) {
            metadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle);
        }
        FeedImage image = feedItem.getImage();
        if (image != null && !TextUtils.isEmpty(image.getDownload_url())) {
            metadata.addImage(new WebImage(Uri.parse(image.getDownload_url())));
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(media.getItem().getPubDate());
        metadata.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar);
        Feed feed = feedItem.getFeed();
        if (feed != null) {
            if (!TextUtils.isEmpty(feed.getAuthor())) {
                metadata.putString(MediaMetadata.KEY_ARTIST, feed.getAuthor());
            }
            if (!TextUtils.isEmpty(feed.getDownload_url())) {
                metadata.putString(KEY_FEED_URL, feed.getDownload_url());
            }
            if (!TextUtils.isEmpty(feed.getLink())) {
                metadata.putString(KEY_FEED_WEBSITE, feed.getLink());
            }
        }
        if (!TextUtils.isEmpty(feedItem.getItemIdentifier())) {
            metadata.putString(KEY_EPISODE_IDENTIFIER, feedItem.getItemIdentifier());
        } else {
            metadata.putString(KEY_EPISODE_IDENTIFIER, media.getStreamUrl());
        }
        if (!TextUtils.isEmpty(feedItem.getLink())) {
            metadata.putString(KEY_EPISODE_LINK, feedItem.getLink());
        }
    }
    String notes = null;
    try {
        notes = media.loadShownotes().call();
    } catch (Exception e) {
        Log.e(TAG, "Unable to load FeedMedia notes", e);
    }
    if (notes != null) {
        if (notes.length() > EPISODE_NOTES_MAX_LENGTH) {
            notes = notes.substring(0, EPISODE_NOTES_MAX_LENGTH);
        }
        metadata.putString(KEY_EPISODE_NOTES, notes);
    }
    // This field only identifies the id on the device that has the original version.
    // Idea is to perhaps, on a first approach, check if the version on the local DB with the
    // same id matches the remote object, and if not then search for episode and feed identifiers.
    // This at least should make media recognition for a single device much quicker.
    metadata.putInt(KEY_MEDIA_ID, ((Long) media.getIdentifier()).intValue());
    // A way to identify different casting media formats in case we change it in the future and
    // senders with different versions share a casting device.
    metadata.putInt(KEY_FORMAT_VERSION, FORMAT_VERSION_VALUE);
    MediaInfo.Builder builder = new MediaInfo.Builder(media.getStreamUrl()).setContentType(media.getMime_type()).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(metadata);
    if (media.getDuration() > 0) {
        builder.setStreamDuration(media.getDuration());
    }
    return builder.build();
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) MediaInfo(com.google.android.gms.cast.MediaInfo) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) Calendar(java.util.Calendar) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 33 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class RemoteMedia method equals.

@Override
public boolean equals(Object other) {
    if (other instanceof RemoteMedia) {
        RemoteMedia rm = (RemoteMedia) other;
        return TextUtils.equals(downloadUrl, rm.downloadUrl) && TextUtils.equals(feedUrl, rm.feedUrl) && TextUtils.equals(itemIdentifier, rm.itemIdentifier);
    }
    if (other instanceof FeedMedia) {
        FeedMedia fm = (FeedMedia) other;
        if (!TextUtils.equals(downloadUrl, fm.getStreamUrl())) {
            return false;
        }
        FeedItem fi = fm.getItem();
        if (fi == null || !TextUtils.equals(itemIdentifier, fi.getItemIdentifier())) {
            return false;
        }
        Feed feed = fi.getFeed();
        return feed != null && TextUtils.equals(feedUrl, feed.getDownload_url());
    }
    return false;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 34 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class APCleanupAlgorithm method getCandidates.

@NonNull
private List<FeedItem> getCandidates() {
    List<FeedItem> candidates = new ArrayList<>();
    List<FeedItem> downloadedItems = DBReader.getDownloadedItems();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_MONTH, -1 * numberOfDaysAfterPlayback);
    Date mostRecentDateForDeletion = cal.getTime();
    for (FeedItem item : downloadedItems) {
        if (item.hasMedia() && item.getMedia().isDownloaded() && !item.isTagged(FeedItem.TAG_QUEUE) && item.isPlayed() && !item.isTagged(FeedItem.TAG_FAVORITE)) {
            FeedMedia media = item.getMedia();
            // to now
            if (media != null && media.getPlaybackCompletionDate() != null && media.getPlaybackCompletionDate().before(mostRecentDateForDeletion)) {
                candidates.add(item);
            }
        }
    }
    return candidates;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Date(java.util.Date) NonNull(android.support.annotation.NonNull)

Example 35 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class QueueSorter method sort.

public static void sort(final Context context, final Rule rule, final boolean broadcastUpdate) {
    Comparator<FeedItem> comparator = null;
    switch(rule) {
        case EPISODE_TITLE_ASC:
            comparator = (f1, f2) -> f1.getTitle().compareTo(f2.getTitle());
            break;
        case EPISODE_TITLE_DESC:
            comparator = (f1, f2) -> f2.getTitle().compareTo(f1.getTitle());
            break;
        case DATE_ASC:
            comparator = (f1, f2) -> f1.getPubDate().compareTo(f2.getPubDate());
            break;
        case DATE_DESC:
            comparator = (f1, f2) -> f2.getPubDate().compareTo(f1.getPubDate());
            break;
        case DURATION_ASC:
            comparator = (f1, f2) -> {
                FeedMedia f1Media = f1.getMedia();
                FeedMedia f2Media = f2.getMedia();
                int duration1 = f1Media != null ? f1Media.getDuration() : -1;
                int duration2 = f2Media != null ? f2Media.getDuration() : -1;
                if (duration1 == -1 || duration2 == -1)
                    return duration2 - duration1;
                else
                    return duration1 - duration2;
            };
            break;
        case DURATION_DESC:
            comparator = (f1, f2) -> {
                FeedMedia f1Media = f1.getMedia();
                FeedMedia f2Media = f2.getMedia();
                int duration1 = f1Media != null ? f1Media.getDuration() : -1;
                int duration2 = f2Media != null ? f2Media.getDuration() : -1;
                return -1 * (duration1 - duration2);
            };
            break;
        case FEED_TITLE_ASC:
            comparator = (f1, f2) -> f1.getFeed().getTitle().compareTo(f2.getFeed().getTitle());
            break;
        case FEED_TITLE_DESC:
            comparator = (f1, f2) -> f2.getFeed().getTitle().compareTo(f1.getFeed().getTitle());
            break;
        default:
    }
    if (comparator != null) {
        DBWriter.sortQueue(comparator, broadcastUpdate);
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Aggregations

FeedItem (de.danoeh.antennapod.core.feed.FeedItem)149 Feed (de.danoeh.antennapod.core.feed.Feed)53 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)40 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)28 Cursor (android.database.Cursor)23 File (java.io.File)18 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)15 Context (android.content.Context)12 FlakyTest (android.test.FlakyTest)11 View (android.view.View)10 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Intent (android.content.Intent)6 LayoutInflater (android.view.LayoutInflater)5 ListView (android.widget.ListView)5 SharedPreferences (android.content.SharedPreferences)4 Chapter (de.danoeh.antennapod.core.feed.Chapter)4 FeedFilter (de.danoeh.antennapod.core.feed.FeedFilter)4 LongList (de.danoeh.antennapod.core.util.LongList)4