Search in sources :

Example 16 with PodDBAdapter

use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.

the class DBWriterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // create new database
    PodDBAdapter.init(getInstrumentation().getTargetContext());
    PodDBAdapter.deleteDatabase();
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter)

Example 17 with PodDBAdapter

use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.

the class PlaybackServiceTaskManagerTest method writeTestQueue.

private List<FeedItem> writeTestQueue(String pref) {
    final Context c = getInstrumentation().getTargetContext();
    final int NUM_ITEMS = 10;
    Feed f = new Feed(0, null, "title", "link", "d", null, null, null, null, "id", null, "null", "url", false);
    f.setItems(new ArrayList<>());
    for (int i = 0; i < NUM_ITEMS; i++) {
        f.getItems().add(new FeedItem(0, pref + i, pref + i, "link", new Date(), FeedItem.PLAYED, f));
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(f);
    adapter.setQueue(f.getItems());
    adapter.close();
    for (FeedItem item : f.getItems()) {
        assertTrue(item.getId() != 0);
    }
    return f.getItems();
}
Also used : Context(android.content.Context) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 18 with PodDBAdapter

use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.

the class DBCleanupTests method testPerformAutoCleanupShouldNotDeleteBecauseInQueue_withFeedsWithNoMedia.

/**
     * Reproduces a bug where DBTasks.performAutoCleanup(android.content.Context) would use the ID of the FeedItem in the
     * call to DBWriter.deleteFeedMediaOfItem instead of the ID of the FeedMedia. This would cause the wrong item to be deleted.
     * @throws IOException
     */
@FlakyTest(tolerance = 3)
public void testPerformAutoCleanupShouldNotDeleteBecauseInQueue_withFeedsWithNoMedia() throws IOException {
    // add feed with no enclosures so that item ID != media ID
    saveFeedlist(1, 10, false);
    // add candidate for performAutoCleanup
    List<Feed> feeds = saveFeedlist(1, 1, true);
    FeedMedia m = feeds.get(0).getItems().get(0).getMedia();
    m.setDownloaded(true);
    m.setFile_url("file");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setMedia(m);
    adapter.close();
    testPerformAutoCleanupShouldNotDeleteBecauseInQueue();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Feed(de.danoeh.antennapod.core.feed.Feed) FlakyTest(android.test.FlakyTest)

Example 19 with PodDBAdapter

use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.

the class DBNullCleanupAlgorithmTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    context = getInstrumentation().getTargetContext();
    destFolder = context.getExternalCacheDir();
    cleanupDestFolder(destFolder);
    assertNotNull(destFolder);
    assertTrue(destFolder.exists());
    assertTrue(destFolder.canWrite());
    // create new database
    PodDBAdapter.init(context);
    PodDBAdapter.deleteDatabase();
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.close();
    SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).edit();
    prefEdit.putString(UserPreferences.PREF_EPISODE_CACHE_SIZE, Integer.toString(EPISODE_CACHE_SIZE));
    prefEdit.putString(UserPreferences.PREF_EPISODE_CLEANUP, Integer.toString(UserPreferences.EPISODE_CLEANUP_NULL));
    prefEdit.commit();
    UserPreferences.init(context);
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) SharedPreferences(android.content.SharedPreferences)

Example 20 with PodDBAdapter

use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.

the class DBReaderTest method saveQueue.

private List<FeedItem> saveQueue(int numItems) {
    if (numItems <= 0) {
        throw new IllegalArgumentException("numItems<=0");
    }
    List<Feed> feeds = saveFeedlist(numItems, numItems, false);
    List<FeedItem> allItems = new ArrayList<>();
    for (Feed f : feeds) {
        allItems.addAll(f.getItems());
    }
    // take random items from every feed
    Random random = new Random();
    List<FeedItem> queue = new ArrayList<>();
    while (queue.size() < numItems) {
        int index = random.nextInt(numItems);
        if (!queue.contains(allItems.get(index))) {
            queue.add(allItems.get(index));
        }
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setQueue(queue);
    adapter.close();
    return queue;
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Random(java.util.Random) ArrayList(java.util.ArrayList) Feed(de.danoeh.antennapod.core.feed.Feed)

Aggregations

PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)45 Feed (de.danoeh.antennapod.core.feed.Feed)32 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)28 Date (java.util.Date)25 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)16 ArrayList (java.util.ArrayList)14 Cursor (android.database.Cursor)13 File (java.io.File)11 Context (android.content.Context)10 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)7 SharedPreferences (android.content.SharedPreferences)4 Solo (com.robotium.solo.Solo)3 Random (java.util.Random)3 FlakyTest (android.test.FlakyTest)2 Chapter (de.danoeh.antennapod.core.feed.Chapter)2 SimpleChapter (de.danoeh.antennapod.core.feed.SimpleChapter)2 FeedPreferences (de.danoeh.antennapod.core.feed.FeedPreferences)1 DBReader (de.danoeh.antennapod.core.storage.DBReader)1 FeedItemPubdateComparator (de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator)1 FlattrStatus (de.danoeh.antennapod.core.util.flattr.FlattrStatus)1