Search in sources :

Example 16 with FeedMedia

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

the class UITestUtils method addHostedFeedData.

/**
     * Adds feeds, images and episodes to the webserver for testing purposes.
     */
public void addHostedFeedData() throws IOException {
    if (feedDataHosted)
        throw new IllegalStateException("addHostedFeedData was called twice on the same instance");
    for (int i = 0; i < NUM_FEEDS; i++) {
        File bitmapFile = newBitmapFile("image" + i);
        FeedImage image = new FeedImage(0, "image " + i, null, hostFile(bitmapFile), false);
        Feed feed = new Feed(0, null, "Title " + i, "http://example.com/" + i, "Description of feed " + i, "http://example.com/pay/feed" + i, "author " + i, "en", Feed.TYPE_RSS2, "feed" + i, image, null, "http://example.com/feed/src/" + i, false);
        image.setOwner(feed);
        // create items
        List<FeedItem> items = new ArrayList<FeedItem>();
        for (int j = 0; j < NUM_ITEMS_PER_FEED; j++) {
            FeedItem item = new FeedItem(j, "Feed " + (i + 1) + ": Item " + (j + 1), "item" + j, "http://example.com/feed" + i + "/item/" + j, new Date(), FeedItem.UNPLAYED, feed);
            items.add(item);
            File mediaFile = newMediaFile("feed-" + i + "-episode-" + j + ".mp3");
            item.setMedia(new FeedMedia(j, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0, 0));
        }
        feed.setItems(items);
        feed.setDownload_url(hostFeed(feed));
        hostedFeeds.add(feed);
    }
    feedDataHosted = true;
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) 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)

Example 17 with FeedMedia

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

the class UITestUtils method addLocalFeedData.

/**
     * Adds feeds, images and episodes to the local database. This method will also call addHostedFeedData if it has not
     * been called yet.
     *
     * Adds one item of each feed to the queue and to the playback history.
     *
     * This method should NOT be called if the testing class wants to download the hosted feed data.
     *
     * @param downloadEpisodes true if episodes should also be marked as downloaded.
     */
public void addLocalFeedData(boolean downloadEpisodes) throws Exception {
    if (localFeedDataAdded) {
        Log.w(TAG, "addLocalFeedData was called twice on the same instance");
        // might be a flaky test, this is actually not that severe
        return;
    }
    if (!feedDataHosted) {
        addHostedFeedData();
    }
    List<FeedItem> queue = new ArrayList<>();
    for (Feed feed : hostedFeeds) {
        feed.setDownloaded(true);
        if (feed.getImage() != null) {
            FeedImage image = feed.getImage();
            int fileId = Integer.parseInt(StringUtils.substringAfter(image.getDownload_url(), "files/"));
            image.setFile_url(server.accessFile(fileId).getAbsolutePath());
            image.setDownloaded(true);
        }
        if (downloadEpisodes) {
            for (FeedItem item : feed.getItems()) {
                if (item.hasMedia()) {
                    FeedMedia media = item.getMedia();
                    int fileId = Integer.parseInt(StringUtils.substringAfter(media.getDownload_url(), "files/"));
                    media.setFile_url(server.accessFile(fileId).getAbsolutePath());
                    media.setDownloaded(true);
                }
            }
        }
        queue.add(feed.getItems().get(0));
        feed.getItems().get(1).getMedia().setPlaybackCompletionDate(new Date());
    }
    localFeedDataAdded = true;
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()]));
    adapter.setQueue(queue);
    adapter.close();
    EventDistributor.getInstance().sendFeedUpdateBroadcast();
    EventBus.getDefault().post(QueueEvent.setQueue(queue));
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 18 with FeedMedia

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

the class ItemFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View layout = inflater.inflate(R.layout.feeditem_fragment, container, false);
    root = (ViewGroup) layout.findViewById(R.id.content_root);
    LinearLayout header = (LinearLayout) root.findViewById(R.id.header);
    if (feedItems.length > 0) {
        header.setOnTouchListener((v, event) -> headerGestureDetector.onTouchEvent(event));
    }
    txtvPodcast = (TextView) layout.findViewById(R.id.txtvPodcast);
    txtvPodcast.setOnClickListener(v -> openPodcast());
    txtvTitle = (TextView) layout.findViewById(R.id.txtvTitle);
    if (Build.VERSION.SDK_INT >= 23) {
        txtvTitle.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL);
    }
    txtvDuration = (TextView) layout.findViewById(R.id.txtvDuration);
    txtvPublished = (TextView) layout.findViewById(R.id.txtvPublished);
    if (Build.VERSION.SDK_INT >= 14) {
        // ellipsize is causing problems on old versions, see #448
        txtvTitle.setEllipsize(TextUtils.TruncateAt.END);
    }
    webvDescription = (WebView) layout.findViewById(R.id.webvDescription);
    if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) {
        if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        webvDescription.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.black));
    }
    webvDescription.getSettings().setUseWideViewPort(false);
    webvDescription.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webvDescription.getSettings().setLoadWithOverviewMode(true);
    if (feedItems.length > 0) {
        webvDescription.setOnLongClickListener(webViewLongClickListener);
    }
    webvDescription.setOnTouchListener((v, event) -> webviewGestureDetector.onTouchEvent(event));
    webvDescription.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            if (IntentUtils.isCallable(getActivity(), intent)) {
                startActivity(intent);
            }
            return true;
        }
    });
    registerForContextMenu(webvDescription);
    imgvCover = (ImageView) layout.findViewById(R.id.imgvCover);
    imgvCover.setOnClickListener(v -> openPodcast());
    progbarDownload = (ProgressBar) layout.findViewById(R.id.progbarDownload);
    progbarLoading = (ProgressBar) layout.findViewById(R.id.progbarLoading);
    butAction1 = (IconButton) layout.findViewById(R.id.butAction1);
    butAction2 = (IconButton) layout.findViewById(R.id.butAction2);
    butAction1.setOnClickListener(v -> {
        if (item == null) {
            return;
        }
        DefaultActionButtonCallback actionButtonCallback = new DefaultActionButtonCallback(getActivity());
        actionButtonCallback.onActionButtonPressed(item, item.isTagged(FeedItem.TAG_QUEUE) ? LongList.of(item.getId()) : new LongList(0));
        FeedMedia media = item.getMedia();
        if (media != null && media.isDownloaded()) {
            ((MainActivity) getActivity()).dismissChildFragment();
        }
    });
    butAction2.setOnClickListener(v -> {
        if (item == null) {
            return;
        }
        if (item.hasMedia()) {
            FeedMedia media = item.getMedia();
            if (!media.isDownloaded()) {
                DBTasks.playMedia(getActivity(), media, true, true, true);
                ((MainActivity) getActivity()).dismissChildFragment();
            } else {
                DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId());
            }
        } else if (item.getLink() != null) {
            Uri uri = Uri.parse(item.getLink());
            getActivity().startActivity(new Intent(Intent.ACTION_VIEW, uri));
        }
    });
    return layout;
}
Also used : DefaultActionButtonCallback(de.danoeh.antennapod.adapter.DefaultActionButtonCallback) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Intent(android.content.Intent) LongList(de.danoeh.antennapod.core.util.LongList) MainActivity(de.danoeh.antennapod.activity.MainActivity) WebView(android.webkit.WebView) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) Uri(android.net.Uri) LinearLayout(android.widget.LinearLayout) WebViewClient(android.webkit.WebViewClient)

Example 19 with FeedMedia

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

the class NewEpisodesFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = super.onCreateViewHelper(inflater, container, savedInstanceState, R.layout.all_episodes_fragment);
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
            AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder) viewHolder;
            Log.d(TAG, "remove(" + holder.getItemId() + ")");
            if (subscription != null) {
                subscription.unsubscribe();
            }
            FeedItem item = holder.getFeedItem();
            // we're marking it as unplayed since the user didn't actually play it
            // but they don't want it considered 'NEW' anymore
            DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
            final Handler h = new Handler(getActivity().getMainLooper());
            final Runnable r = () -> {
                FeedMedia media = item.getMedia();
                if (media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) {
                    DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId());
                }
            };
            Snackbar snackbar = Snackbar.make(root, getString(R.string.marked_as_seen_label), Snackbar.LENGTH_LONG);
            snackbar.setAction(getString(R.string.undo), v -> {
                DBWriter.markItemPlayed(FeedItem.NEW, item.getId());
                h.removeCallbacks(r);
            });
            snackbar.show();
            h.postDelayed(r, (int) Math.ceil(snackbar.getDuration() * 1.05f));
        }

        @Override
        public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
            // We only want the active item
            if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
                if (viewHolder instanceof AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder) {
                    AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder itemViewHolder = (AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder) viewHolder;
                    itemViewHolder.onItemSelected();
                }
            }
            super.onSelectedChanged(viewHolder, actionState);
        }

        @Override
        public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            super.clearView(recyclerView, viewHolder);
            if (viewHolder instanceof AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder) {
                AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder itemViewHolder = (AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder) viewHolder;
                itemViewHolder.onItemClear();
            }
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    return root;
}
Also used : AllEpisodesRecycleAdapter(de.danoeh.antennapod.adapter.AllEpisodesRecycleAdapter) Handler(android.os.Handler) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) RecyclerView(android.support.v7.widget.RecyclerView) Snackbar(android.support.design.widget.Snackbar)

Example 20 with FeedMedia

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

the class FeedItemlistAdapter method getView.

@Override
@SuppressWarnings("ResourceType")
public View getView(final int position, View convertView, ViewGroup parent) {
    Holder holder;
    final FeedItem item = getItem(position);
    if (convertView == null) {
        holder = new Holder();
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.feeditemlist_item, parent, false);
        holder.container = (LinearLayout) convertView.findViewById(R.id.container);
        holder.title = (TextView) convertView.findViewById(R.id.txtvItemname);
        if (Build.VERSION.SDK_INT >= 23) {
            holder.title.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL);
        }
        holder.lenSize = (TextView) convertView.findViewById(R.id.txtvLenSize);
        holder.butAction = (ImageButton) convertView.findViewById(R.id.butSecondaryAction);
        holder.published = (TextView) convertView.findViewById(R.id.txtvPublished);
        holder.inPlaylist = (ImageView) convertView.findViewById(R.id.imgvInPlaylist);
        holder.type = (ImageView) convertView.findViewById(R.id.imgvType);
        holder.statusUnread = convertView.findViewById(R.id.statusUnread);
        holder.episodeProgress = (ProgressBar) convertView.findViewById(R.id.pbar_episode_progress);
        convertView.setTag(holder);
    } else {
        holder = (Holder) convertView.getTag();
    }
    if (!(getItemViewType(position) == Adapter.IGNORE_ITEM_VIEW_TYPE)) {
        convertView.setVisibility(View.VISIBLE);
        if (position == selectedItemIndex) {
            convertView.setBackgroundColor(ContextCompat.getColor(convertView.getContext(), ThemeUtils.getSelectionBackgroundColor()));
        } else {
            convertView.setBackgroundResource(0);
        }
        StringBuilder buffer = new StringBuilder(item.getTitle());
        if (showFeedtitle) {
            buffer.append(" (");
            buffer.append(item.getFeed().getTitle());
            buffer.append(")");
        }
        holder.title.setText(buffer.toString());
        if (item.isNew()) {
            holder.statusUnread.setVisibility(View.VISIBLE);
        } else {
            holder.statusUnread.setVisibility(View.INVISIBLE);
        }
        if (item.isPlayed() && makePlayedItemsTransparent) {
            ViewHelper.setAlpha(convertView, 0.5f);
        } else {
            ViewHelper.setAlpha(convertView, 1.0f);
        }
        String pubDateStr = DateUtils.formatAbbrev(context, item.getPubDate());
        holder.published.setText(pubDateStr);
        boolean isInQueue = item.isTagged(FeedItem.TAG_QUEUE);
        FeedMedia media = item.getMedia();
        if (media == null) {
            holder.episodeProgress.setVisibility(View.GONE);
            holder.inPlaylist.setVisibility(View.INVISIBLE);
            holder.type.setVisibility(View.INVISIBLE);
            holder.lenSize.setVisibility(View.INVISIBLE);
        } else {
            AdapterUtils.updateEpisodePlaybackProgress(item, holder.lenSize, holder.episodeProgress);
            if (isInQueue) {
                holder.inPlaylist.setVisibility(View.VISIBLE);
            } else {
                holder.inPlaylist.setVisibility(View.INVISIBLE);
            }
            if (DownloadRequester.getInstance().isDownloadingFile(item.getMedia())) {
                holder.episodeProgress.setVisibility(View.VISIBLE);
                holder.episodeProgress.setProgress(itemAccess.getItemDownloadProgressPercent(item));
            } else {
                if (media.getPosition() == 0) {
                    holder.episodeProgress.setVisibility(View.GONE);
                }
            }
            TypedArray typeDrawables = context.obtainStyledAttributes(new int[] { R.attr.type_audio, R.attr.type_video });
            final int[] labels = new int[] { R.string.media_type_audio_label, R.string.media_type_video_label };
            MediaType mediaType = item.getMedia().getMediaType();
            if (mediaType == MediaType.AUDIO) {
                holder.type.setImageDrawable(typeDrawables.getDrawable(0));
                holder.type.setContentDescription(context.getString(labels[0]));
                holder.type.setVisibility(View.VISIBLE);
            } else if (mediaType == MediaType.VIDEO) {
                holder.type.setImageDrawable(typeDrawables.getDrawable(1));
                holder.type.setContentDescription(context.getString(labels[1]));
                holder.type.setVisibility(View.VISIBLE);
            } else {
                holder.type.setImageBitmap(null);
                holder.type.setVisibility(View.GONE);
            }
            typeDrawables.recycle();
            if (media.isCurrentlyPlaying()) {
                holder.container.setBackgroundColor(playingBackGroundColor);
            } else {
                holder.container.setBackgroundColor(normalBackGroundColor);
            }
        }
        actionButtonUtils.configureActionButton(holder.butAction, item, isInQueue);
        holder.butAction.setFocusable(false);
        holder.butAction.setTag(item);
        holder.butAction.setOnClickListener(butActionListener);
    } else {
        convertView.setVisibility(View.GONE);
    }
    return convertView;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) LayoutInflater(android.view.LayoutInflater) TypedArray(android.content.res.TypedArray) MediaType(de.danoeh.antennapod.core.feed.MediaType)

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