Search in sources :

Example 21 with PodDBAdapter

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

the class DBReaderTest method testGetFeedListSortOrder.

public void testGetFeedListSortOrder() {
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Feed feed1 = new Feed(0, null, "A", "link", "d", null, null, null, "rss", "A", null, "", "", true);
    Feed feed2 = new Feed(0, null, "b", "link", "d", null, null, null, "rss", "b", null, "", "", true);
    Feed feed3 = new Feed(0, null, "C", "link", "d", null, null, null, "rss", "C", null, "", "", true);
    Feed feed4 = new Feed(0, null, "d", "link", "d", null, null, null, "rss", "d", null, "", "", true);
    adapter.setCompleteFeed(feed1);
    adapter.setCompleteFeed(feed2);
    adapter.setCompleteFeed(feed3);
    adapter.setCompleteFeed(feed4);
    assertTrue(feed1.getId() != 0);
    assertTrue(feed2.getId() != 0);
    assertTrue(feed3.getId() != 0);
    assertTrue(feed4.getId() != 0);
    adapter.close();
    List<Feed> saved = DBReader.getFeedList();
    assertNotNull(saved);
    assertEquals("Wrong size: ", 4, saved.size());
    assertEquals("Wrong id of feed 1: ", feed1.getId(), saved.get(0).getId());
    assertEquals("Wrong id of feed 2: ", feed2.getId(), saved.get(1).getId());
    assertEquals("Wrong id of feed 3: ", feed3.getId(), saved.get(2).getId());
    assertEquals("Wrong id of feed 4: ", feed4.getId(), saved.get(3).getId());
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 22 with PodDBAdapter

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

the class DBReaderTest method saveDownloadedItems.

private List<FeedItem> saveDownloadedItems(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> downloaded = new ArrayList<>();
    Random random = new Random();
    while (downloaded.size() < numItems) {
        int i = random.nextInt(numItems);
        if (!downloaded.contains(items.get(i))) {
            FeedItem item = items.get(i);
            item.getMedia().setDownloaded(true);
            item.getMedia().setFile_url("file" + i);
            downloaded.add(item);
        }
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setFeedItemlist(downloaded);
    adapter.close();
    return downloaded;
}
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 23 with PodDBAdapter

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

the class PlaybackServiceMediaPlayerTest method writeTestPlayable.

private Playable writeTestPlayable(String downloadUrl, String fileUrl) {
    final Context c = getInstrumentation().getTargetContext();
    Feed f = new Feed(0, null, "f", "l", "d", null, null, null, null, "i", null, null, "l", false);
    FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NO, null, null);
    f.setPreferences(prefs);
    f.setItems(new ArrayList<>());
    FeedItem i = new FeedItem(0, "t", "i", "l", new Date(), FeedItem.UNPLAYED, f);
    f.getItems().add(i);
    FeedMedia media = new FeedMedia(0, i, 0, 0, 0, "audio/wav", fileUrl, downloadUrl, fileUrl != null, null, 0, 0);
    i.setMedia(media);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(f);
    assertTrue(media.getId() != 0);
    adapter.close();
    return media;
}
Also used : Context(android.content.Context) FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) 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 24 with PodDBAdapter

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

the class PlaybackServiceMediaPlayerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    assertionError = null;
    final Context context = getInstrumentation().getTargetContext();
    // create new database
    PodDBAdapter.init(context);
    PodDBAdapter.deleteDatabase();
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.close();
    httpServer = new HTTPBin();
    httpServer.start();
    File cacheDir = context.getExternalFilesDir("testFiles");
    if (cacheDir == null)
        cacheDir = context.getExternalFilesDir("testFiles");
    File dest = new File(cacheDir, PLAYABLE_DEST_URL);
    assertNotNull(cacheDir);
    assertTrue(cacheDir.canWrite());
    assertTrue(cacheDir.canRead());
    if (!dest.exists()) {
        InputStream i = getInstrumentation().getContext().getAssets().open("testfile.mp3");
        OutputStream o = new FileOutputStream(new File(cacheDir, PLAYABLE_DEST_URL));
        IOUtils.copy(i, o);
        o.flush();
        o.close();
        i.close();
    }
    PLAYABLE_LOCAL_URL = "file://" + dest.getAbsolutePath();
    assertEquals(0, httpServer.serveFile(dest));
}
Also used : Context(android.content.Context) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) HTTPBin(de.test.antennapod.util.service.download.HTTPBin) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 25 with PodDBAdapter

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

the class PlaybackServiceTaskManagerTest 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)

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