Search in sources :

Example 76 with FeedItem

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

the class GpodnetSyncService method processEpisodeActions.

private synchronized void processEpisodeActions(List<GpodnetEpisodeAction> localActions, List<GpodnetEpisodeAction> remoteActions) throws DownloadRequestException {
    if (remoteActions.size() == 0) {
        return;
    }
    Map<Pair<String, String>, GpodnetEpisodeAction> localMostRecentPlayAction = new ArrayMap<>();
    for (GpodnetEpisodeAction action : localActions) {
        Pair<String, String> key = new Pair<>(action.getPodcast(), action.getEpisode());
        GpodnetEpisodeAction mostRecent = localMostRecentPlayAction.get(key);
        if (mostRecent == null || mostRecent.getTimestamp() == null) {
            localMostRecentPlayAction.put(key, action);
        } else if (mostRecent.getTimestamp().before(action.getTimestamp())) {
            localMostRecentPlayAction.put(key, action);
        }
    }
    // make sure more recent local actions are not overwritten by older remote actions
    Map<Pair<String, String>, GpodnetEpisodeAction> mostRecentPlayAction = new ArrayMap<>();
    for (GpodnetEpisodeAction action : remoteActions) {
        switch(action.getAction()) {
            case NEW:
                FeedItem newItem = DBReader.getFeedItem(action.getPodcast(), action.getEpisode());
                if (newItem != null) {
                    DBWriter.markItemPlayed(newItem, FeedItem.UNPLAYED, true);
                } else {
                    Log.i(TAG, "Unknown feed item: " + action);
                }
                break;
            case DOWNLOAD:
                break;
            case PLAY:
                Pair<String, String> key = new Pair<>(action.getPodcast(), action.getEpisode());
                GpodnetEpisodeAction localMostRecent = localMostRecentPlayAction.get(key);
                if (localMostRecent == null || localMostRecent.getTimestamp() == null || localMostRecent.getTimestamp().before(action.getTimestamp())) {
                    GpodnetEpisodeAction mostRecent = mostRecentPlayAction.get(key);
                    if (mostRecent == null || mostRecent.getTimestamp() == null) {
                        mostRecentPlayAction.put(key, action);
                    } else if (action.getTimestamp() != null && mostRecent.getTimestamp().before(action.getTimestamp())) {
                        mostRecentPlayAction.put(key, action);
                    } else {
                        Log.d(TAG, "No date information in action, skipping it");
                    }
                }
                break;
            case DELETE:
                // NEVER EVER call DBWriter.deleteFeedMediaOfItem() here, leads to an infinite loop
                break;
        }
    }
    for (GpodnetEpisodeAction action : mostRecentPlayAction.values()) {
        FeedItem playItem = DBReader.getFeedItem(action.getPodcast(), action.getEpisode());
        if (playItem != null) {
            FeedMedia media = playItem.getMedia();
            media.setPosition(action.getPosition() * 1000);
            DBWriter.setFeedMedia(media);
            if (playItem.getMedia().hasAlmostEnded()) {
                DBWriter.markItemPlayed(playItem, FeedItem.PLAYED, true);
                DBWriter.addItemToPlaybackHistory(playItem.getMedia());
            }
        }
    }
}
Also used : GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayMap(android.support.v4.util.ArrayMap) Pair(android.util.Pair)

Example 77 with FeedItem

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

the class DBReader method getFeedItem.

/**
     * Loads a specific FeedItem from the database.
     *
     * @param podcastUrl the corresponding feed's url
     * @param episodeUrl the feed item's url
     * @return The FeedItem or null if the FeedItem could not be found. All FeedComponent-attributes
     * as well as chapter marks of the FeedItem will also be loaded from the database.
     */
public static FeedItem getFeedItem(final String podcastUrl, final String episodeUrl) {
    Log.d(TAG, "getFeedItem() called with: " + "podcastUrl = [" + podcastUrl + "], episodeUrl = [" + episodeUrl + "]");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    FeedItem item = getFeedItem(podcastUrl, episodeUrl, adapter);
    adapter.close();
    return item;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Example 78 with FeedItem

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

the class DBReader method getFeedItem.

static FeedItem getFeedItem(final long itemId, PodDBAdapter adapter) {
    Log.d(TAG, "Loading feeditem with id " + itemId);
    FeedItem item = null;
    Cursor itemCursor = adapter.getFeedItemCursor(Long.toString(itemId));
    if (!itemCursor.moveToFirst()) {
        itemCursor.close();
        return null;
    }
    List<FeedItem> list = extractItemlistFromCursor(adapter, itemCursor);
    itemCursor.close();
    if (list.size() > 0) {
        item = list.get(0);
        loadAdditionalFeedItemListData(list);
        if (item.hasChapters()) {
            loadChaptersOfFeedItem(adapter, item);
        }
    }
    return item;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 79 with FeedItem

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

the class DBReader method getFavoriteItemsList.

public static List<FeedItem> getFavoriteItemsList() {
    Log.d(TAG, "getFavoriteItemsList() called");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor itemlistCursor = adapter.getFavoritesCursor();
    List<FeedItem> items = extractItemlistFromCursor(adapter, itemlistCursor);
    itemlistCursor.close();
    loadAdditionalFeedItemListData(items);
    adapter.close();
    return items;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 80 with FeedItem

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

the class DBReader method getFeedMedia.

/**
     * Searches the DB for a FeedMedia of the given id.
     *
     * @param mediaId The id of the object
     * @return The found object
     */
public static FeedMedia getFeedMedia(final long mediaId) {
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor mediaCursor = adapter.getSingleFeedMediaCursor(mediaId);
    if (!mediaCursor.moveToFirst()) {
        mediaCursor.close();
        return null;
    }
    int indexFeedItem = mediaCursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM);
    long itemId = mediaCursor.getLong(indexFeedItem);
    FeedMedia media = FeedMedia.fromCursor(mediaCursor);
    mediaCursor.close();
    if (media != null) {
        FeedItem item = getFeedItem(itemId);
        if (item != null) {
            media.setItem(item);
            item.setMedia(media);
        }
    }
    adapter.close();
    return media;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Cursor(android.database.Cursor)

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