Search in sources :

Example 51 with FeedMedia

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());
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Date(java.util.Date)

Example 52 with FeedMedia

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;
}
Also used : GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Intent(android.content.Intent) Uri(android.net.Uri)

Example 53 with FeedMedia

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);
    }
}
Also used : FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Downloader(de.danoeh.antennapod.core.service.download.Downloader)

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