Search in sources :

Example 41 with PodDBAdapter

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

the class DBWriterTest method testMoveQueueItem.

public void testMoveQueueItem() throws InterruptedException, ExecutionException, TimeoutException {
    final int NUM_ITEMS = 10;
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < NUM_ITEMS; i++) {
        FeedItem item = new FeedItem(0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.PLAYED, feed);
        feed.getItems().add(item);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
    }
    for (int from = 0; from < NUM_ITEMS; from++) {
        for (int to = 0; to < NUM_ITEMS; to++) {
            if (from == to) {
                continue;
            }
            Log.d(TAG, String.format("testMoveQueueItem: From=%d, To=%d", from, to));
            final long fromID = feed.getItems().get(from).getId();
            adapter = PodDBAdapter.getInstance();
            adapter.open();
            adapter.setQueue(feed.getItems());
            adapter.close();
            DBWriter.moveQueueItem(from, to, false).get(TIMEOUT, TimeUnit.SECONDS);
            adapter = PodDBAdapter.getInstance();
            adapter.open();
            Cursor queue = adapter.getQueueIDCursor();
            assertTrue(queue.getCount() == NUM_ITEMS);
            assertTrue(queue.moveToPosition(from));
            assertFalse(queue.getLong(0) == fromID);
            assertTrue(queue.moveToPosition(to));
            assertTrue(queue.getLong(0) == fromID);
            queue.close();
            adapter.close();
        }
    }
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 42 with PodDBAdapter

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

the class DBWriterTest method playbackHistorySetup.

private FeedMedia playbackHistorySetup(Date playbackCompletionDate) {
    final Context context = getInstrumentation().getTargetContext();
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<FeedItem>());
    FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
    FeedMedia media = new FeedMedia(0, item, 10, 0, 1, "mime", null, "url", false, playbackCompletionDate, 0, 0);
    feed.getItems().add(item);
    item.setMedia(media);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(media.getId() != 0);
    return media;
}
Also used : Context(android.content.Context) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 43 with PodDBAdapter

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

the class MainActivityTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Context context = getInstrumentation().getTargetContext();
    uiTestUtils = new UITestUtils(context);
    uiTestUtils.setup();
    // create new database
    PodDBAdapter.init(context);
    PodDBAdapter.deleteDatabase();
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.close();
    // override first launch preference
    // do this BEFORE calling getActivity()!
    prefs = getInstrumentation().getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE);
    prefs.edit().putBoolean(MainActivity.PREF_IS_FIRST_LAUNCH, false).commit();
    solo = new Solo(getInstrumentation(), getActivity());
}
Also used : Context(android.content.Context) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) Solo(com.robotium.solo.Solo)

Example 44 with PodDBAdapter

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

the class DBWriterTest method testClearQueue.

public void testClearQueue() throws InterruptedException, ExecutionException, TimeoutException {
    final int NUM_ITEMS = 10;
    Feed feed = queueTestSetupMultipleItems(NUM_ITEMS);
    DBWriter.clearQueue().get(TIMEOUT, TimeUnit.SECONDS);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor cursor = adapter.getQueueIDCursor();
    assertFalse(cursor.moveToFirst());
    cursor.close();
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) Cursor(android.database.Cursor) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 45 with PodDBAdapter

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

the class DBWriterTest method testAddItemToPlaybackHistoryAlreadyPlayed.

public void testAddItemToPlaybackHistoryAlreadyPlayed() throws ExecutionException, InterruptedException, TimeoutException {
    final long OLD_DATE = 0;
    FeedMedia media = playbackHistorySetup(new Date(OLD_DATE));
    DBWriter.addItemToPlaybackHistory(media).get(TIMEOUT, TimeUnit.SECONDS);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    media = DBReader.getFeedMedia(media.getId());
    adapter.close();
    assertNotNull(media);
    assertNotNull(media.getPlaybackCompletionDate());
    assertFalse(OLD_DATE == media.getPlaybackCompletionDate().getTime());
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Date(java.util.Date)

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