Search in sources :

Example 1 with MediaType

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

Example 2 with MediaType

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

the class PlaybackService method writePlaybackPreferences.

private void writePlaybackPreferences() {
    Log.d(TAG, "Writing playback preferences");
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
    PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo();
    MediaType mediaType = mediaPlayer.getCurrentMediaType();
    boolean stream = mediaPlayer.isStreaming();
    int playerStatus = getCurrentPlayerStatusAsInt(info.playerStatus);
    if (info.playable != null) {
        editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA, info.playable.getPlayableType());
        editor.putBoolean(PlaybackPreferences.PREF_CURRENT_EPISODE_IS_STREAM, stream);
        editor.putBoolean(PlaybackPreferences.PREF_CURRENT_EPISODE_IS_VIDEO, mediaType == MediaType.VIDEO);
        if (info.playable instanceof FeedMedia) {
            FeedMedia fMedia = (FeedMedia) info.playable;
            editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, fMedia.getItem().getFeed().getId());
            editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, fMedia.getId());
        } else {
            editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
            editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
        }
        info.playable.writeToPreferences(editor);
    } else {
        editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA, PlaybackPreferences.NO_MEDIA_PLAYING);
        editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
        editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
    }
    editor.putInt(PlaybackPreferences.PREF_CURRENT_PLAYER_STATUS, playerStatus);
    editor.commit();
}
Also used : SharedPreferences(android.content.SharedPreferences) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) MediaType(de.danoeh.antennapod.core.feed.MediaType)

Aggregations

FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)2 MediaType (de.danoeh.antennapod.core.feed.MediaType)2 SharedPreferences (android.content.SharedPreferences)1 TypedArray (android.content.res.TypedArray)1 LayoutInflater (android.view.LayoutInflater)1 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)1