use of de.danoeh.antennapod.core.feed.FeedMedia 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());
}
use of de.danoeh.antennapod.core.feed.FeedMedia in project AntennaPod by AntennaPod.
the class FeedItemMenuHandler method onMenuItemClicked.
public static boolean onMenuItemClicked(Context context, int menuItemId, FeedItem selectedItem) throws DownloadRequestException {
switch(menuItemId) {
case R.id.skip_episode_item:
context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
break;
case R.id.remove_item:
DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId());
break;
case R.id.mark_read_item:
selectedItem.setPlayed(true);
DBWriter.markItemPlayed(selectedItem, FeedItem.PLAYED, false);
if (GpodnetPreferences.loggedIn()) {
FeedMedia media = selectedItem.getMedia();
// not all items have media, Gpodder only cares about those that do
if (media != null) {
GpodnetEpisodeAction actionPlay = new GpodnetEpisodeAction.Builder(selectedItem, Action.PLAY).currentDeviceId().currentTimestamp().started(media.getDuration() / 1000).position(media.getDuration() / 1000).total(media.getDuration() / 1000).build();
GpodnetPreferences.enqueueEpisodeAction(actionPlay);
}
}
break;
case R.id.mark_unread_item:
selectedItem.setPlayed(false);
DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, false);
if (GpodnetPreferences.loggedIn() && selectedItem.getMedia() != null) {
GpodnetEpisodeAction actionNew = new GpodnetEpisodeAction.Builder(selectedItem, Action.NEW).currentDeviceId().currentTimestamp().build();
GpodnetPreferences.enqueueEpisodeAction(actionNew);
}
break;
case R.id.add_to_queue_item:
DBWriter.addQueueItem(context, selectedItem);
break;
case R.id.remove_from_queue_item:
DBWriter.removeQueueItem(context, selectedItem, true);
break;
case R.id.add_to_favorites_item:
DBWriter.addFavoriteItem(selectedItem);
break;
case R.id.remove_from_favorites_item:
DBWriter.removeFavoriteItem(selectedItem);
break;
case R.id.reset_position:
selectedItem.getMedia().setPosition(0);
DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, true);
break;
case R.id.activate_auto_download:
selectedItem.setAutoDownload(true);
DBWriter.setFeedItemAutoDownload(selectedItem, true);
break;
case R.id.deactivate_auto_download:
selectedItem.setAutoDownload(false);
DBWriter.setFeedItemAutoDownload(selectedItem, false);
break;
case R.id.visit_website_item:
Uri uri = Uri.parse(selectedItem.getLink());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if (IntentUtils.isCallable(context, intent)) {
context.startActivity(intent);
} else {
Toast.makeText(context, context.getString(R.string.download_error_malformed_url), Toast.LENGTH_SHORT).show();
}
break;
case R.id.support_item:
DBTasks.flattrItemIfLoggedIn(context, selectedItem);
break;
case R.id.share_link_item:
ShareUtils.shareFeedItemLink(context, selectedItem);
break;
case R.id.share_download_url_item:
ShareUtils.shareFeedItemDownloadLink(context, selectedItem);
break;
case R.id.share_link_with_position_item:
ShareUtils.shareFeedItemLink(context, selectedItem, true);
break;
case R.id.share_download_url_with_position_item:
ShareUtils.shareFeedItemDownloadLink(context, selectedItem, true);
break;
default:
Log.d(TAG, "Unknown menuItemId: " + menuItemId);
return false;
}
return true;
}
use of de.danoeh.antennapod.core.feed.FeedMedia in project AntennaPod by AntennaPod.
the class ItemFragment method updateAppearance.
private void updateAppearance() {
if (item == null) {
Log.d(TAG, "updateAppearance item is null");
return;
}
getActivity().supportInvalidateOptionsMenu();
txtvPodcast.setText(item.getFeed().getTitle());
txtvTitle.setText(item.getTitle());
if (item.getPubDate() != null) {
String pubDateStr = DateUtils.formatAbbrev(getActivity(), item.getPubDate());
txtvPublished.setText(pubDateStr);
}
Glide.with(getActivity()).load(item.getImageLocation()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(imgvCover);
progbarDownload.setVisibility(View.GONE);
if (item.hasMedia() && downloaderList != null) {
for (Downloader downloader : downloaderList) {
if (downloader.getDownloadRequest().getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA && downloader.getDownloadRequest().getFeedfileId() == item.getMedia().getId()) {
progbarDownload.setVisibility(View.VISIBLE);
progbarDownload.setProgress(downloader.getDownloadRequest().getProgressPercent());
}
}
}
FeedMedia media = item.getMedia();
String butAction1Icon = null;
int butAction1Text = 0;
String butAction2Icon = null;
int butAction2Text = 0;
if (media == null) {
if (!item.isPlayed()) {
butAction1Icon = "{fa-check 24sp}";
butAction1Text = R.string.mark_read_label;
}
if (item.getLink() != null) {
butAction2Icon = "{md-web 24sp}";
butAction2Text = R.string.visit_website_label;
}
} else {
if (media.getDuration() > 0) {
txtvDuration.setText(Converter.getDurationStringLong(media.getDuration()));
}
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
if (!media.isDownloaded()) {
butAction2Icon = "{md-settings-input-antenna 24sp}";
butAction2Text = R.string.stream_label;
} else {
butAction2Icon = "{md-delete 24sp}";
butAction2Text = R.string.delete_label;
}
if (isDownloading) {
butAction1Icon = "{md-cancel 24sp}";
butAction1Text = R.string.cancel_label;
} else if (media.isDownloaded()) {
butAction1Icon = "{md-play-arrow 24sp}";
butAction1Text = R.string.play_label;
} else {
butAction1Icon = "{md-file-download 24sp}";
butAction1Text = R.string.download_label;
}
}
if (butAction1Icon != null && butAction1Text != 0) {
butAction1.setText(butAction1Icon + " " + getActivity().getString(butAction1Text));
Iconify.addIcons(butAction1);
butAction1.setVisibility(View.VISIBLE);
} else {
butAction1.setVisibility(View.INVISIBLE);
}
if (butAction2Icon != null && butAction2Text != 0) {
butAction2.setText(butAction2Icon + " " + getActivity().getString(butAction2Text));
Iconify.addIcons(butAction2);
butAction2.setVisibility(View.VISIBLE);
} else {
butAction2.setVisibility(View.INVISIBLE);
}
}
Aggregations