Search in sources :

Example 76 with FeedItem

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));
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedFilter(de.danoeh.antennapod.model.feed.FeedFilter) Test(org.junit.Test)

Example 77 with FeedItem

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));
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedFilter(de.danoeh.antennapod.model.feed.FeedFilter) Test(org.junit.Test)

Example 78 with FeedItem

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));
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Test(org.junit.Test)

Example 79 with FeedItem

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);
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ArrayList(java.util.ArrayList) LongList(de.danoeh.antennapod.core.util.LongList) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) Pair(androidx.core.util.Pair)

Example 80 with FeedItem

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());
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

FeedItem (de.danoeh.antennapod.model.feed.FeedItem)178 Feed (de.danoeh.antennapod.model.feed.Feed)74 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)48 Date (java.util.Date)47 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)46 File (java.io.File)26 Cursor (android.database.Cursor)20 NonNull (androidx.annotation.NonNull)15 Nullable (androidx.annotation.Nullable)11 Subscribe (org.greenrobot.eventbus.Subscribe)9 Intent (android.content.Intent)7 FeedFilter (de.danoeh.antennapod.model.feed.FeedFilter)7 View (android.view.View)6 LongList (de.danoeh.antennapod.core.util.LongList)6 SQLException (android.database.SQLException)5 Playable (de.danoeh.antennapod.model.playback.Playable)5 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)5 ExecutionException (java.util.concurrent.ExecutionException)5 FeedItemPubdateComparator (de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator)4