Search in sources :

Example 1 with FeedFilter

use of de.danoeh.antennapod.model.feed.FeedFilter 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 2 with FeedFilter

use of de.danoeh.antennapod.model.feed.FeedFilter 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 3 with FeedFilter

use of de.danoeh.antennapod.model.feed.FeedFilter in project AntennaPod by AntennaPod.

the class FeedPreferencesCursorMapper method convert.

/**
 * Create a {@link FeedPreferences} instance from a database row (cursor).
 */
@NonNull
public static FeedPreferences convert(@NonNull Cursor cursor) {
    int indexId = cursor.getColumnIndex(PodDBAdapter.KEY_ID);
    int indexAutoDownload = cursor.getColumnIndex(PodDBAdapter.KEY_AUTO_DOWNLOAD_ENABLED);
    int indexAutoRefresh = cursor.getColumnIndex(PodDBAdapter.KEY_KEEP_UPDATED);
    int indexAutoDeleteAction = cursor.getColumnIndex(PodDBAdapter.KEY_AUTO_DELETE_ACTION);
    int indexVolumeAdaption = cursor.getColumnIndex(PodDBAdapter.KEY_FEED_VOLUME_ADAPTION);
    int indexUsername = cursor.getColumnIndex(PodDBAdapter.KEY_USERNAME);
    int indexPassword = cursor.getColumnIndex(PodDBAdapter.KEY_PASSWORD);
    int indexIncludeFilter = cursor.getColumnIndex(PodDBAdapter.KEY_INCLUDE_FILTER);
    int indexExcludeFilter = cursor.getColumnIndex(PodDBAdapter.KEY_EXCLUDE_FILTER);
    int indexMinimalDurationFilter = cursor.getColumnIndex(PodDBAdapter.KEY_MINIMAL_DURATION_FILTER);
    int indexFeedPlaybackSpeed = cursor.getColumnIndex(PodDBAdapter.KEY_FEED_PLAYBACK_SPEED);
    int indexAutoSkipIntro = cursor.getColumnIndex(PodDBAdapter.KEY_FEED_SKIP_INTRO);
    int indexAutoSkipEnding = cursor.getColumnIndex(PodDBAdapter.KEY_FEED_SKIP_ENDING);
    int indexEpisodeNotification = cursor.getColumnIndex(PodDBAdapter.KEY_EPISODE_NOTIFICATION);
    int indexTags = cursor.getColumnIndex(PodDBAdapter.KEY_FEED_TAGS);
    long feedId = cursor.getLong(indexId);
    boolean autoDownload = cursor.getInt(indexAutoDownload) > 0;
    boolean autoRefresh = cursor.getInt(indexAutoRefresh) > 0;
    int autoDeleteActionIndex = cursor.getInt(indexAutoDeleteAction);
    FeedPreferences.AutoDeleteAction autoDeleteAction = FeedPreferences.AutoDeleteAction.values()[autoDeleteActionIndex];
    int volumeAdaptionValue = cursor.getInt(indexVolumeAdaption);
    VolumeAdaptionSetting volumeAdaptionSetting = VolumeAdaptionSetting.fromInteger(volumeAdaptionValue);
    String username = cursor.getString(indexUsername);
    String password = cursor.getString(indexPassword);
    String includeFilter = cursor.getString(indexIncludeFilter);
    String excludeFilter = cursor.getString(indexExcludeFilter);
    int minimalDurationFilter = cursor.getInt(indexMinimalDurationFilter);
    float feedPlaybackSpeed = cursor.getFloat(indexFeedPlaybackSpeed);
    int feedAutoSkipIntro = cursor.getInt(indexAutoSkipIntro);
    int feedAutoSkipEnding = cursor.getInt(indexAutoSkipEnding);
    boolean showNotification = cursor.getInt(indexEpisodeNotification) > 0;
    String tagsString = cursor.getString(indexTags);
    if (TextUtils.isEmpty(tagsString)) {
        tagsString = FeedPreferences.TAG_ROOT;
    }
    return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, volumeAdaptionSetting, username, password, new FeedFilter(includeFilter, excludeFilter, minimalDurationFilter), feedPlaybackSpeed, feedAutoSkipIntro, feedAutoSkipEnding, showNotification, new HashSet<>(Arrays.asList(tagsString.split(FeedPreferences.TAG_SEPARATOR))));
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) VolumeAdaptionSetting(de.danoeh.antennapod.model.feed.VolumeAdaptionSetting) FeedFilter(de.danoeh.antennapod.model.feed.FeedFilter) NonNull(androidx.annotation.NonNull)

Example 4 with FeedFilter

use of de.danoeh.antennapod.model.feed.FeedFilter in project AntennaPod by AntennaPod.

the class FeedFilterTest method testBasicIncludeFilter.

@Test
public void testBasicIncludeFilter() {
    String includeFilter = "Hello";
    FeedFilter filter = new FeedFilter(includeFilter, "");
    FeedItem item = new FeedItem();
    item.setTitle("Hello world");
    FeedItem item2 = new FeedItem();
    item2.setTitle("Don't include me");
    assertFalse(filter.excludeOnly());
    assertTrue(filter.includeOnly());
    assertEquals("", filter.getExcludeFilter());
    assertEquals(includeFilter, filter.getIncludeFilter());
    assertTrue(filter.shouldAutoDownload(item));
    assertFalse(filter.shouldAutoDownload(item2));
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedFilter(de.danoeh.antennapod.model.feed.FeedFilter) Test(org.junit.Test)

Example 5 with FeedFilter

use of de.danoeh.antennapod.model.feed.FeedFilter in project AntennaPod by AntennaPod.

the class FeedFilterTest method testBasicExcludeFilter.

@Test
public void testBasicExcludeFilter() {
    String excludeFilter = "Hello";
    FeedFilter filter = new FeedFilter("", excludeFilter);
    FeedItem item = new FeedItem();
    item.setTitle("Hello world");
    FeedItem item2 = new FeedItem();
    item2.setTitle("Item2");
    assertTrue(filter.excludeOnly());
    assertFalse(filter.includeOnly());
    assertEquals(excludeFilter, filter.getExcludeFilter());
    assertEquals("", filter.getIncludeFilter());
    assertFalse(filter.shouldAutoDownload(item));
    assertTrue(filter.shouldAutoDownload(item2));
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedFilter(de.danoeh.antennapod.model.feed.FeedFilter) Test(org.junit.Test)

Aggregations

FeedFilter (de.danoeh.antennapod.model.feed.FeedFilter)8 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)7 Test (org.junit.Test)7 NonNull (androidx.annotation.NonNull)1 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)1 FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)1 VolumeAdaptionSetting (de.danoeh.antennapod.model.feed.VolumeAdaptionSetting)1