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