Search in sources :

Example 41 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia in project AntennaPod by AntennaPod.

the class DefaultActionButtonCallback method onActionButtonPressed.

@Override
public void onActionButtonPressed(final FeedItem item, final LongList queueIds) {
    if (item.hasMedia()) {
        final FeedMedia media = item.getMedia();
        boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
        if (!isDownloading && !media.isDownloaded()) {
            if (NetworkUtils.isDownloadAllowed() || userAllowedMobileDownloads()) {
                try {
                    DBTasks.downloadFeedItems(context, item);
                    Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
                } catch (DownloadRequestException e) {
                    e.printStackTrace();
                    DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
                }
            } else if (userChoseAddToQueue() && !queueIds.contains(item.getId())) {
                DBWriter.addQueueItem(context, item);
                Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
            } else {
                confirmMobileDownload(context, item);
            }
        } else if (isDownloading) {
            DownloadRequester.getInstance().cancelDownload(context, media);
            if (UserPreferences.isEnableAutodownload()) {
                DBWriter.setFeedItemAutoDownload(media.getItem(), false);
                Toast.makeText(context, R.string.download_canceled_autodownload_enabled_msg, Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(context, R.string.download_canceled_msg, Toast.LENGTH_LONG).show();
            }
        } else {
            // media is downloaded
            if (item.hasMedia() && item.getMedia().isCurrentlyPlaying()) {
                context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
            } else if (item.hasMedia() && item.getMedia().isCurrentlyPaused()) {
                context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE));
            } else {
                DBTasks.playMedia(context, media, false, true, false);
            }
        }
    } else {
        if (!item.isPlayed()) {
            DBWriter.markItemPlayed(item, FeedItem.PLAYED, true);
        }
    }
}
Also used : FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Intent(android.content.Intent) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException)

Example 42 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia 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 43 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia 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 44 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia 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 45 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia 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)

Aggregations

FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)53 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)39 Feed (de.danoeh.antennapod.core.feed.Feed)20 Date (java.util.Date)19 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)16 ArrayList (java.util.ArrayList)13 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)10 File (java.io.File)9 Intent (android.content.Intent)7 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Cursor (android.database.Cursor)6 SharedPreferences (android.content.SharedPreferences)4 TypedArray (android.content.res.TypedArray)3 Uri (android.net.Uri)3 View (android.view.View)3 Chapter (de.danoeh.antennapod.core.feed.Chapter)3 GpodnetEpisodeAction (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction)3 Context (android.content.Context)2 ArrayMap (android.support.v4.util.ArrayMap)2 FlakyTest (android.test.FlakyTest)2