Search in sources :

Example 31 with PodDBAdapter

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

the class DBReaderTest method testGetNavDrawerDataQueueNotEmptyWithUnreadItems.

public void testGetNavDrawerDataQueueNotEmptyWithUnreadItems() {
    final int NUM_FEEDS = 10;
    final int NUM_ITEMS = 10;
    final int NUM_QUEUE = 1;
    final int NUM_NEW = 2;
    List<Feed> feeds = DBTestUtils.saveFeedlist(NUM_FEEDS, NUM_ITEMS, true);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    for (int i = 0; i < NUM_NEW; i++) {
        FeedItem item = feeds.get(0).getItems().get(i);
        item.setNew();
        adapter.setSingleFeedItem(item);
    }
    List<FeedItem> queue = new ArrayList<>();
    for (int i = 0; i < NUM_QUEUE; i++) {
        FeedItem item = feeds.get(1).getItems().get(i);
        queue.add(item);
    }
    adapter.setQueue(queue);
    adapter.close();
    DBReader.NavDrawerData navDrawerData = DBReader.getNavDrawerData();
    assertEquals(NUM_FEEDS, navDrawerData.feeds.size());
    assertEquals(NUM_NEW, navDrawerData.numNewItems);
    assertEquals(NUM_QUEUE, navDrawerData.queueSize);
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) DBReader(de.danoeh.antennapod.core.storage.DBReader) ArrayList(java.util.ArrayList) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 32 with PodDBAdapter

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

the class DBReaderTest method testGetPlaybackHistory.

public void testGetPlaybackHistory() {
    final int numItems = (DBReader.PLAYBACK_HISTORY_SIZE + 1) * 2;
    final int playedItems = DBReader.PLAYBACK_HISTORY_SIZE + 1;
    final int numReturnedItems = Math.min(playedItems, DBReader.PLAYBACK_HISTORY_SIZE);
    final int numFeeds = 1;
    Feed feed = DBTestUtils.saveFeedlist(numFeeds, numItems, true).get(0);
    long[] ids = new long[playedItems];
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    for (int i = 0; i < playedItems; i++) {
        FeedMedia m = feed.getItems().get(i).getMedia();
        m.setPlaybackCompletionDate(new Date(i + 1));
        adapter.setFeedMediaPlaybackCompletionDate(m);
        ids[ids.length - 1 - i] = m.getItem().getId();
    }
    adapter.close();
    List<FeedItem> saved = DBReader.getPlaybackHistory();
    assertNotNull(saved);
    assertEquals("Wrong size: ", numReturnedItems, saved.size());
    for (int i = 0; i < numReturnedItems; i++) {
        FeedItem item = saved.get(i);
        assertNotNull(item.getMedia().getPlaybackCompletionDate());
        assertEquals("Wrong sort order: ", item.getId(), ids[i]);
    }
}
Also used : 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 33 with PodDBAdapter

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

the class DBReaderTest 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 34 with PodDBAdapter

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

the class DBReaderTest method saveUnreadItems.

private List<FeedItem> saveUnreadItems(int numItems) {
    if (numItems <= 0) {
        throw new IllegalArgumentException("numItems<=0");
    }
    List<Feed> feeds = saveFeedlist(numItems, numItems, true);
    List<FeedItem> items = new ArrayList<>();
    for (Feed f : feeds) {
        items.addAll(f.getItems());
    }
    List<FeedItem> unread = new ArrayList<>();
    Random random = new Random();
    while (unread.size() < numItems) {
        int i = random.nextInt(numItems);
        if (!unread.contains(items.get(i))) {
            FeedItem item = items.get(i);
            item.setPlayed(false);
            unread.add(item);
        }
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setFeedItemlist(unread);
    adapter.close();
    return unread;
}
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)

Example 35 with PodDBAdapter

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

the class DBTasksTest method testUpdateFeedMediaUrlResetState.

public void testUpdateFeedMediaUrlResetState() {
    final Feed feed = new Feed("url", null, "title");
    FeedItem item = new FeedItem(0, "item", "id", "link", new Date(), FeedItem.PLAYED, feed);
    feed.setItems(Arrays.asList(item));
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    // ensure that objects have been saved in db, then reset
    assertTrue(feed.getId() != 0);
    assertTrue(item.getId() != 0);
    FeedMedia media = new FeedMedia(item, "url", 1024, "mime/type");
    item.setMedia(media);
    feed.setItems(Arrays.asList(item));
    final Feed newFeed = DBTasks.updateFeed(context, feed)[0];
    assertTrue(feed != newFeed);
    final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
    final FeedItem feedItemFromDB = feedFromDB.getItems().get(0);
    assertTrue("state: " + feedItemFromDB.getState(), feedItemFromDB.isNew());
}
Also used : 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)

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