Search in sources :

Example 1 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia 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 2 with FeedMedia

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

the class PlaybackController method getPlayLastPlayedMediaIntent.

/**
     * Returns an intent that starts the PlaybackService and plays the last
     * played media or null if no last played media could be found.
     */
private Intent getPlayLastPlayedMediaIntent() {
    Log.d(TAG, "Trying to restore last played media");
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
    long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMedia();
    if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) {
        Playable media = PlayableUtils.createInstanceFromPreferences(activity, (int) currentlyPlayingMedia, prefs);
        if (media != null) {
            Intent serviceIntent = new Intent(activity, PlaybackService.class);
            serviceIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
            serviceIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, false);
            serviceIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY, true);
            boolean fileExists = media.localFileAvailable();
            boolean lastIsStream = PlaybackPreferences.getCurrentEpisodeIsStream();
            if (!fileExists && !lastIsStream && media instanceof FeedMedia) {
                DBTasks.notifyMissingFeedMediaFile(activity, (FeedMedia) media);
            }
            serviceIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, lastIsStream || !fileExists);
            return serviceIntent;
        }
    }
    Log.d(TAG, "No last played media found");
    return null;
}
Also used : SharedPreferences(android.content.SharedPreferences) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Intent(android.content.Intent)

Example 3 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia 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 4 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia 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)

Example 5 with FeedMedia

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

the class NSRSS20 method handleElementStart.

@Override
public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
    if (ITEM.equals(localName)) {
        state.setCurrentItem(new FeedItem());
        state.getItems().add(state.getCurrentItem());
        state.getCurrentItem().setFeed(state.getFeed());
    } else if (ENCLOSURE.equals(localName)) {
        String type = attributes.getValue(ENC_TYPE);
        String url = attributes.getValue(ENC_URL);
        boolean validType = SyndTypeUtils.enclosureTypeValid(type);
        if (!validType) {
            type = SyndTypeUtils.getMimeTypeFromUrl(url);
            validType = SyndTypeUtils.enclosureTypeValid(type);
        }
        boolean validUrl = !TextUtils.isEmpty(url);
        if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null && validType && validUrl) {
            long size = 0;
            try {
                size = Long.parseLong(attributes.getValue(ENC_LEN));
                if (size < 16384) {
                    // less than 16kb is suspicious, check manually
                    size = 0;
                }
            } catch (NumberFormatException e) {
                Log.d(TAG, "Length attribute could not be parsed.");
            }
            FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
            state.getCurrentItem().setMedia(media);
        }
    } else if (IMAGE.equals(localName)) {
        if (state.getTagstack().size() >= 1) {
            String parent = state.getTagstack().peek().getName();
            if (CHANNEL.equals(parent)) {
                Feed feed = state.getFeed();
                if (feed != null && feed.getImage() == null) {
                    feed.setImage(new FeedImage());
                    feed.getImage().setOwner(state.getFeed());
                }
            }
        }
    }
    return new SyndElement(localName, this);
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Feed(de.danoeh.antennapod.core.feed.Feed)

Aggregations

FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)53 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)39 Feed (de.danoeh.antennapod.core.feed.Feed)20 Date (java.util.Date)19 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)16 ArrayList (java.util.ArrayList)13 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)10 File (java.io.File)9 Intent (android.content.Intent)7 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Cursor (android.database.Cursor)6 SharedPreferences (android.content.SharedPreferences)4 TypedArray (android.content.res.TypedArray)3 Uri (android.net.Uri)3 View (android.view.View)3 Chapter (de.danoeh.antennapod.core.feed.Chapter)3 GpodnetEpisodeAction (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction)3 Context (android.content.Context)2 ArrayMap (android.support.v4.util.ArrayMap)2 FlakyTest (android.test.FlakyTest)2