Search in sources :

Example 26 with PodDBAdapter

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

the class DBCleanupTests 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(cleanupAlgorithm));
    prefEdit.commit();
    UserPreferences.init(context);
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) SharedPreferences(android.content.SharedPreferences)

Example 27 with PodDBAdapter

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

the class DBCleanupTests method populateItems.

protected void populateItems(final int numItems, Feed feed, List<FeedItem> items, List<File> files, int itemState, boolean addToQueue, boolean addToFavorites) throws IOException {
    for (int i = 0; i < numItems; i++) {
        Date itemDate = new Date(numItems - i);
        Date playbackCompletionDate = null;
        if (itemState == FeedItem.PLAYED) {
            playbackCompletionDate = itemDate;
        }
        FeedItem item = new FeedItem(0, "title", "id", "link", itemDate, itemState, feed);
        File f = new File(destFolder, "file " + i);
        assertTrue(f.createNewFile());
        files.add(f);
        item.setMedia(new FeedMedia(0, item, 1, 0, 1L, "m", f.getAbsolutePath(), "url", true, playbackCompletionDate, 0, 0));
        items.add(item);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    if (addToQueue) {
        adapter.setQueue(items);
    }
    if (addToFavorites) {
        adapter.setFavorites(items);
    }
    adapter.close();
    assertTrue(feed.getId() != 0);
    for (FeedItem item : items) {
        assertTrue(item.getId() != 0);
        assertTrue(item.getMedia().getId() != 0);
    }
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) File(java.io.File) Date(java.util.Date)

Example 28 with PodDBAdapter

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

the class DBNullCleanupAlgorithmTest method testPerformAutoCleanupShouldNotDelete.

/**
     * A test with no items in the queue, but multiple items downloaded.
     * The null algorithm should never delete any items, even if they're played and not in the queue.
     * @throws IOException
     */
@FlakyTest(tolerance = 3)
public void testPerformAutoCleanupShouldNotDelete() throws IOException {
    final int NUM_ITEMS = EPISODE_CACHE_SIZE * 2;
    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    List<File> files = new ArrayList<>();
    for (int i = 0; i < NUM_ITEMS; i++) {
        FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
        File f = new File(destFolder, "file " + i);
        assertTrue(f.createNewFile());
        files.add(f);
        item.setMedia(new FeedMedia(0, item, 1, 0, 1L, "m", f.getAbsolutePath(), "url", true, new Date(NUM_ITEMS - i), 0, 0));
        items.add(item);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    for (FeedItem item : items) {
        assertTrue(item.getId() != 0);
        assertTrue(item.getMedia().getId() != 0);
    }
    DBTasks.performAutoCleanup(context);
    for (int i = 0; i < files.size(); i++) {
        assertTrue(files.get(i).exists());
    }
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed) FlakyTest(android.test.FlakyTest)

Example 29 with PodDBAdapter

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

the class PlaybackSonicTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    context = getInstrumentation().getTargetContext();
    PodDBAdapter.init(context);
    PodDBAdapter.deleteDatabase();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    prefs.edit().clear().putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false).putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false).putBoolean(UserPreferences.PREF_SONIC, true).commit();
    solo = new Solo(getInstrumentation(), getActivity());
    uiTestUtils = new UITestUtils(context);
    uiTestUtils.setup();
    // create database
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) SharedPreferences(android.content.SharedPreferences) Solo(com.robotium.solo.Solo)

Example 30 with PodDBAdapter

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

the class PlaybackTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    context = getInstrumentation().getTargetContext();
    PodDBAdapter.init(context);
    PodDBAdapter.deleteDatabase();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    prefs.edit().clear().putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false).putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false).commit();
    solo = new Solo(getInstrumentation(), getActivity());
    uiTestUtils = new UITestUtils(context);
    uiTestUtils.setup();
    // create database
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) SharedPreferences(android.content.SharedPreferences) Solo(com.robotium.solo.Solo)

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