use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class FeedFilterTest method testComboFilter.
@Test
public void testComboFilter() {
String includeFilter = "Hello world";
String excludeFilter = "dislike";
FeedFilter filter = new FeedFilter(includeFilter, excludeFilter);
FeedItem download = new FeedItem();
download.setTitle("Hello everyone!");
// because, while it has words from the include filter it also has exclude words
FeedItem doNotDownload = new FeedItem();
doNotDownload.setTitle("I dislike the world");
// because it has no words from the include filter
FeedItem doNotDownload2 = new FeedItem();
doNotDownload2.setTitle("no words to include");
assertTrue(filter.hasExcludeFilter());
assertTrue(filter.hasIncludeFilter());
assertTrue(filter.shouldAutoDownload(download));
assertFalse(filter.shouldAutoDownload(doNotDownload));
assertFalse(filter.shouldAutoDownload(doNotDownload2));
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class FeedFilterTest method testComplexIncludeFilter.
@Test
public void testComplexIncludeFilter() {
String includeFilter = "Hello \n\"Two words\"";
FeedFilter filter = new FeedFilter(includeFilter, "");
FeedItem item = new FeedItem();
item.setTitle("hello world");
FeedItem item2 = new FeedItem();
item2.setTitle("Two three words");
FeedItem item3 = new FeedItem();
item3.setTitle("One two words");
assertFalse(filter.excludeOnly());
assertTrue(filter.includeOnly());
assertEquals("", filter.getExcludeFilter());
assertEquals(includeFilter, filter.getIncludeFilter());
assertTrue(filter.shouldAutoDownload(item));
assertFalse(filter.shouldAutoDownload(item2));
assertTrue(filter.shouldAutoDownload(item3));
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class FeedItemTest method testAutoDownloadBackoff.
@Test
public void testAutoDownloadBackoff() {
FeedItem item = new FeedItem();
item.setMedia(new FeedMedia(item, "https://example.com/file.mp3", 0, "audio/mpeg"));
// In reality, this is System.currentTimeMillis()
long now = ONE_HOUR;
assertTrue(item.isAutoDownloadable(now));
item.increaseFailedAutoDownloadAttempts(now);
assertFalse(item.isAutoDownloadable(now));
now += ONE_HOUR;
assertTrue(item.isAutoDownloadable(now));
item.increaseFailedAutoDownloadAttempts(now);
assertFalse(item.isAutoDownloadable(now));
now += ONE_HOUR;
// Should backoff, so more than 1 hour needed
assertFalse(item.isAutoDownloadable(now));
now += ONE_HOUR;
// Now it's enough
assertTrue(item.isAutoDownloadable(now));
item.increaseFailedAutoDownloadAttempts(now);
item.increaseFailedAutoDownloadAttempts(now);
item.increaseFailedAutoDownloadAttempts(now);
now += 1000L * ONE_HOUR;
// Should have given up
assertFalse(item.isAutoDownloadable(now));
item.increaseFailedAutoDownloadAttempts(now);
now += 1000L * ONE_HOUR;
// Still given up
assertFalse(item.isAutoDownloadable(now));
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class SyncService method processEpisodeActions.
private synchronized void processEpisodeActions(List<EpisodeAction> remoteActions) {
Log.d(TAG, "Processing " + remoteActions.size() + " actions");
if (remoteActions.size() == 0) {
return;
}
Map<Pair<String, String>, EpisodeAction> playActionsToUpdate = EpisodeActionFilter.getRemoteActionsOverridingLocalActions(remoteActions, synchronizationQueueStorage.getQueuedEpisodeActions());
LongList queueToBeRemoved = new LongList();
List<FeedItem> updatedItems = new ArrayList<>();
for (EpisodeAction action : playActionsToUpdate.values()) {
String guid = GuidValidator.isValidGuid(action.getGuid()) ? action.getGuid() : null;
FeedItem feedItem = DBReader.getFeedItemByGuidOrEpisodeUrl(guid, action.getEpisode());
if (feedItem == null) {
Log.i(TAG, "Unknown feed item: " + action);
continue;
}
if (feedItem.getMedia() == null) {
Log.i(TAG, "Feed item has no media: " + action);
continue;
}
if (action.getAction() == EpisodeAction.NEW) {
DBWriter.markItemPlayed(feedItem, FeedItem.UNPLAYED, true);
continue;
}
feedItem.getMedia().setPosition(action.getPosition() * 1000);
if (FeedItemUtil.hasAlmostEnded(feedItem.getMedia())) {
Log.d(TAG, "Marking as played: " + action);
feedItem.setPlayed(true);
feedItem.getMedia().setPosition(0);
queueToBeRemoved.add(feedItem.getId());
} else {
Log.d(TAG, "Setting position: " + action);
}
updatedItems.add(feedItem);
}
DBWriter.removeQueueItem(getApplicationContext(), false, queueToBeRemoved.toArray());
DBReader.loadAdditionalFeedItemListData(updatedItems);
DBWriter.setItemList(updatedItems);
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class LocalFeedUpdaterTest method verifySingleFeedInDatabaseAndItemCount.
/**
* Verify that the database contains exactly one feed and the number of
* items in the feed.
*
* @param expectedItemCount expected number of items in the feed
*/
private static void verifySingleFeedInDatabaseAndItemCount(int expectedItemCount) {
Feed feed = verifySingleFeedInDatabase();
List<FeedItem> feedItems = DBReader.getFeedItemList(feed);
assertEquals(expectedItemCount, feedItems.size());
}
Aggregations