Search in sources :

Example 66 with FeedItem

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

the class APCleanupAlgorithm method performCleanup.

@Override
public int performCleanup(Context context, int numberOfEpisodesToDelete) {
    List<FeedItem> candidates = getCandidates();
    List<FeedItem> delete;
    Collections.sort(candidates, (lhs, rhs) -> {
        Date l = lhs.getMedia().getPlaybackCompletionDate();
        Date r = rhs.getMedia().getPlaybackCompletionDate();
        if (l == null) {
            l = new Date();
        }
        if (r == null) {
            r = new Date();
        }
        return l.compareTo(r);
    });
    if (candidates.size() > numberOfEpisodesToDelete) {
        delete = candidates.subList(0, numberOfEpisodesToDelete);
    } else {
        delete = candidates;
    }
    for (FeedItem item : delete) {
        try {
            DBWriter.deleteFeedMediaOfItem(context, item.getMedia().getId()).get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }
    int counter = delete.size();
    Log.i(TAG, String.format("Auto-delete deleted %d episodes (%d requested)", counter, numberOfEpisodesToDelete));
    return counter;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) ExecutionException(java.util.concurrent.ExecutionException) Date(java.util.Date)

Example 67 with FeedItem

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

the class APQueueCleanupAlgorithm method getCandidates.

@NonNull
private List<FeedItem> getCandidates() {
    List<FeedItem> candidates = new ArrayList<>();
    List<FeedItem> downloadedItems = DBReader.getDownloadedItems();
    for (FeedItem item : downloadedItems) {
        if (item.hasMedia() && item.getMedia().isDownloaded() && !item.isTagged(FeedItem.TAG_QUEUE) && !item.isTagged(FeedItem.TAG_FAVORITE)) {
            candidates.add(item);
        }
    }
    return candidates;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) ArrayList(java.util.ArrayList) NonNull(android.support.annotation.NonNull)

Example 68 with FeedItem

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

the class APQueueCleanupAlgorithm method performCleanup.

@Override
public int performCleanup(Context context, int numberOfEpisodesToDelete) {
    List<FeedItem> candidates = getCandidates();
    List<FeedItem> delete;
    // in the absence of better data, we'll sort by item publication date
    Collections.sort(candidates, (lhs, rhs) -> {
        Date l = lhs.getPubDate();
        Date r = rhs.getPubDate();
        if (l == null) {
            l = new Date();
        }
        if (r == null) {
            r = new Date();
        }
        return l.compareTo(r);
    });
    if (candidates.size() > numberOfEpisodesToDelete) {
        delete = candidates.subList(0, numberOfEpisodesToDelete);
    } else {
        delete = candidates;
    }
    for (FeedItem item : delete) {
        try {
            DBWriter.deleteFeedMediaOfItem(context, item.getMedia().getId()).get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }
    int counter = delete.size();
    Log.i(TAG, String.format("Auto-delete deleted %d episodes (%d requested)", counter, numberOfEpisodesToDelete));
    return counter;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) ExecutionException(java.util.concurrent.ExecutionException) Date(java.util.Date)

Example 69 with FeedItem

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

the class DBReader method getStatistics.

/**
     * Searches the DB for statistics
     *
     * @return The StatisticsInfo object
     */
public static StatisticsData getStatistics() {
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    long totalTime = 0;
    List<StatisticsItem> feedTime = new ArrayList<>();
    List<Feed> feeds = getFeedList();
    for (Feed feed : feeds) {
        long feedPlayedTime = 0;
        long feedTotalTime = 0;
        long episodes = 0;
        long episodesStarted = 0;
        List<FeedItem> items = getFeed(feed.getId()).getItems();
        for (FeedItem item : items) {
            FeedMedia media = item.getMedia();
            if (media == null) {
                continue;
            }
            // played duration used to be reset when the item is added to the playback history
            if (media.getPlaybackCompletionDate() != null) {
                feedPlayedTime += media.getDuration() / 1000;
            }
            feedPlayedTime += media.getPlayedDuration() / 1000;
            if (media.getPlaybackCompletionDate() != null || media.getPlayedDuration() > 0) {
                episodesStarted++;
            }
            feedTotalTime += media.getDuration() / 1000;
            episodes++;
        }
        feedTime.add(new StatisticsItem(feed, feedTotalTime, feedPlayedTime, episodes, episodesStarted));
        totalTime += feedPlayedTime;
    }
    Collections.sort(feedTime, (item1, item2) -> {
        if (item1.timePlayed > item2.timePlayed) {
            return -1;
        } else if (item1.timePlayed < item2.timePlayed) {
            return 1;
        } else {
            return 0;
        }
    });
    adapter.close();
    return new StatisticsData(totalTime, feedTime);
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 70 with FeedItem

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

the class DBReader method getFeedItemList.

/**
     * Loads the list of FeedItems for a certain Feed-object. This method should NOT be used if the FeedItems are not
     * used. In order to get information ABOUT the list of FeedItems, consider using {@link #getFeedStatisticsList()} instead.
     *
     * @param feed    The Feed whose items should be loaded
     * @return A list with the FeedItems of the Feed. The Feed-attribute of the FeedItems will already be set correctly.
     * The method does NOT change the items-attribute of the feed.
     */
public static List<FeedItem> getFeedItemList(final Feed feed) {
    Log.d(TAG, "getFeedItemList() called with: " + "feed = [" + feed + "]");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor itemlistCursor = adapter.getAllItemsOfFeedCursor(feed);
    List<FeedItem> items = extractItemlistFromCursor(adapter, itemlistCursor);
    itemlistCursor.close();
    adapter.close();
    Collections.sort(items, new FeedItemPubdateComparator());
    for (FeedItem item : items) {
        item.setFeed(feed);
    }
    return items;
}
Also used : FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) 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