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);
}
}
}
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;
}
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);
}
}
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());
}
}
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]);
}
}
Aggregations