diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-05-17 13:22:15 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-05-17 13:22:15 +0200 |
commit | 640b36912abe3b27cb8188e7d6c3b4acafe27d6a (patch) | |
tree | 67d7ed5cb9a7588ab0f85d1047d5ad2d7e50d685 /src/de/danoeh/antennapod/adapter | |
parent | bb9683b86a29cece5bec4f7af357290ada70548b (diff) | |
download | AntennaPod-640b36912abe3b27cb8188e7d6c3b4acafe27d6a.zip |
Improved spacing in FeedItemlist and Downloads list
- Removed InternalFeedItemlistAdapter
Diffstat (limited to 'src/de/danoeh/antennapod/adapter')
3 files changed, 243 insertions, 346 deletions
diff --git a/src/de/danoeh/antennapod/adapter/DefaultFeedItemlistAdapter.java b/src/de/danoeh/antennapod/adapter/DefaultFeedItemlistAdapter.java deleted file mode 100644 index e384ecffc..000000000 --- a/src/de/danoeh/antennapod/adapter/DefaultFeedItemlistAdapter.java +++ /dev/null @@ -1,129 +0,0 @@ -package de.danoeh.antennapod.adapter; - -import android.content.Context; -import android.content.res.TypedArray; -import android.text.format.DateUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Adapter; -import android.widget.BaseAdapter; -import android.widget.ImageView; -import android.widget.TextView; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.feed.FeedItem; -import de.danoeh.antennapod.feed.MediaType; -import de.danoeh.antennapod.util.Converter; - -public class DefaultFeedItemlistAdapter extends BaseAdapter { - - ItemAccess itemAccess; - private Context context; - - public DefaultFeedItemlistAdapter(Context context, ItemAccess itemAccess) { - super(); - this.context = context; - if (itemAccess == null) { - throw new IllegalArgumentException("itemAccess must not be null"); - } - this.itemAccess = itemAccess; - } - - @Override - public int getCount() { - return itemAccess.getCount(); - - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public FeedItem getItem(int position) { - return itemAccess.getItem(position); - } - - @Override - public View getView(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.default_feeditemlist_item, null); - holder.title = (TextView) convertView - .findViewById(R.id.txtvItemname); - holder.lenSize = (TextView) convertView - .findViewById(R.id.txtvLenSize); - - holder.published = (TextView) convertView - .findViewById(R.id.txtvPublished); - holder.type = (ImageView) convertView.findViewById(R.id.imgvType); - convertView.setTag(holder); - - } else { - holder = (Holder) convertView.getTag(); - } - if (!(getItemViewType(position) == Adapter.IGNORE_ITEM_VIEW_TYPE)) { - convertView.setVisibility(View.VISIBLE); - holder.title.setText(item.getTitle()); - holder.published.setText(convertView.getResources().getString( - R.string.published_prefix) - + DateUtils.getRelativeTimeSpanString( - item.getPubDate().getTime(), - System.currentTimeMillis(), 0, 0)); - if (item.getMedia() == null) { - holder.type.setVisibility(View.GONE); - holder.lenSize.setVisibility(View.GONE); - } else { - holder.lenSize.setVisibility(View.VISIBLE); - holder.lenSize.setText(convertView.getResources().getString( - R.string.size_prefix) - + Converter.byteToString(item.getMedia().getSize())); - - TypedArray typeDrawables = context - .obtainStyledAttributes(new int[] { R.attr.type_audio, - R.attr.type_video }); - MediaType mediaType = item.getMedia().getMediaType(); - if (mediaType == MediaType.AUDIO) { - holder.type.setImageDrawable(typeDrawables.getDrawable(0)); - holder.type.setContentDescription(context.getString(R.string.media_type_audio_label)); - holder.type.setVisibility(View.VISIBLE); - } else if (mediaType == MediaType.VIDEO) { - holder.type.setImageDrawable(typeDrawables.getDrawable(1)); - holder.type.setContentDescription(context.getString(R.string.media_type_video_label)); - holder.type.setVisibility(View.VISIBLE); - } else { - holder.type.setImageBitmap(null); - holder.type.setVisibility(View.GONE); - } - } - - } else { - convertView.setVisibility(View.GONE); - } - return convertView; - } - - protected static class Holder { - TextView title; - TextView published; - TextView lenSize; - ImageView type; - - } - - public static interface ItemAccess { - int getCount(); - - FeedItem getItem(int position); - } - - protected Context getContext() { - return context; - } -} diff --git a/src/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java b/src/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java new file mode 100644 index 000000000..5475f122f --- /dev/null +++ b/src/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java @@ -0,0 +1,243 @@ +package de.danoeh.antennapod.adapter; + +import android.content.Context; +import android.content.res.TypedArray; +import android.text.format.DateUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.*; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.feed.FeedItem; +import de.danoeh.antennapod.feed.FeedMedia; +import de.danoeh.antennapod.feed.MediaType; +import de.danoeh.antennapod.storage.DownloadRequester; +import de.danoeh.antennapod.util.Converter; +import de.danoeh.antennapod.util.ThemeUtils; + +/** + * List adapter for items of feeds that the user has already subscribed to. + */ +public class FeedItemlistAdapter extends BaseAdapter { + + private ActionButtonCallback callback; + private final ItemAccess itemAccess; + private final Context context; + private boolean showFeedtitle; + private int selectedItemIndex; + private final ActionButtonUtils actionButtonUtils; + + public static final int SELECTION_NONE = -1; + + public FeedItemlistAdapter(Context context, + ItemAccess itemAccess, + ActionButtonCallback callback, boolean showFeedtitle) { + super(); + this.callback = callback; + this.context = context; + this.itemAccess = itemAccess; + this.showFeedtitle = showFeedtitle; + this.selectedItemIndex = SELECTION_NONE; + this.actionButtonUtils = new ActionButtonUtils(context); + } + + @Override + public int getCount() { + return itemAccess.getCount(); + + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public FeedItem getItem(int position) { + return itemAccess.getItem(position); + } + + @Override + 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, null); + holder.title = (TextView) convertView + .findViewById(R.id.txtvItemname); + 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 = (View) 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(convertView.getResources() + .getColor(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()); + + FeedItem.State state = item.getState(); + switch (state) { + case PLAYING: + holder.statusUnread.setVisibility(View.GONE); + holder.episodeProgress.setVisibility(View.VISIBLE); + break; + case IN_PROGRESS: + holder.statusUnread.setVisibility(View.GONE); + holder.episodeProgress.setVisibility(View.VISIBLE); + break; + case NEW: + holder.statusUnread.setVisibility(View.VISIBLE); + break; + default: + holder.statusUnread.setVisibility(View.GONE); + break; + } + + holder.published.setText(DateUtils.formatDateTime(context, item.getPubDate().getTime(), DateUtils.FORMAT_SHOW_DATE)); + + + 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 { + + if (state == FeedItem.State.PLAYING + || state == FeedItem.State.IN_PROGRESS) { + if (media.getDuration() > 0) { + holder.episodeProgress + .setProgress((int) (((double) media + .getPosition()) / media.getDuration() * 100)); + holder.lenSize.setText(Converter + .getDurationStringLong(media.getDuration() + - media.getPosition())); + } + } else if (!media.isDownloaded()) { + holder.lenSize.setText(context.getString( + R.string.size_prefix) + + Converter.byteToString(media.getSize())); + } else { + holder.lenSize.setText(context.getString( + R.string.length_prefix) + + Converter.getDurationStringLong(media + .getDuration())); + } + + holder.lenSize.setVisibility(View.VISIBLE); + if (((ItemAccess) itemAccess).isInQueue(item)) { + 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) itemAccess).getItemDownloadProgressPercent(item)); + } else if (!(state == FeedItem.State.IN_PROGRESS + || state == FeedItem.State.PLAYING)) { + 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); + } + } + + actionButtonUtils.configureActionButton(holder.butAction, item); + holder.butAction.setFocusable(false); + holder.butAction.setTag(item); + holder.butAction.setOnClickListener(butActionListener); + + } else { + convertView.setVisibility(View.GONE); + } + return convertView; + + } + + private final OnClickListener butActionListener = new OnClickListener() { + @Override + public void onClick(View v) { + FeedItem item = (FeedItem) v.getTag(); + callback.onActionButtonPressed(item); + } + }; + + static class Holder { + TextView title; + TextView published; + TextView lenSize; + ImageView type; + ImageView inPlaylist; + ImageButton butAction; + View statusUnread; + ProgressBar episodeProgress; + } + + public int getSelectedItemIndex() { + return selectedItemIndex; + } + + public void setSelectedItemIndex(int selectedItemIndex) { + this.selectedItemIndex = selectedItemIndex; + notifyDataSetChanged(); + } + + public static interface ItemAccess { + public boolean isInQueue(FeedItem item); + + int getItemDownloadProgressPercent(FeedItem item); + + int getCount(); + + FeedItem getItem(int position); + } + +} diff --git a/src/de/danoeh/antennapod/adapter/InternalFeedItemlistAdapter.java b/src/de/danoeh/antennapod/adapter/InternalFeedItemlistAdapter.java deleted file mode 100644 index 736b65d24..000000000 --- a/src/de/danoeh/antennapod/adapter/InternalFeedItemlistAdapter.java +++ /dev/null @@ -1,217 +0,0 @@ -package de.danoeh.antennapod.adapter; - -import android.content.Context; -import android.content.res.TypedArray; -import android.text.format.DateUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.*; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.feed.FeedItem; -import de.danoeh.antennapod.feed.FeedMedia; -import de.danoeh.antennapod.feed.MediaType; -import de.danoeh.antennapod.service.playback.PlayerStatus; -import de.danoeh.antennapod.storage.DownloadRequester; -import de.danoeh.antennapod.util.Converter; -import de.danoeh.antennapod.util.ThemeUtils; - -/** List adapter for items of feeds that the user has already subscribed to. */ -public class InternalFeedItemlistAdapter extends DefaultFeedItemlistAdapter { - - private ActionButtonCallback callback; - private boolean showFeedtitle; - private int selectedItemIndex; - private final ActionButtonUtils actionButtonUtils; - - public static final int SELECTION_NONE = -1; - - public InternalFeedItemlistAdapter(Context context, - ItemAccess itemAccess, - ActionButtonCallback callback, boolean showFeedtitle) { - super(context, itemAccess); - this.callback = callback; - this.showFeedtitle = showFeedtitle; - this.selectedItemIndex = SELECTION_NONE; - this.actionButtonUtils = new ActionButtonUtils(context); - } - - @Override - 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) getContext() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.feeditemlist_item, null); - holder.title = (TextView) convertView - .findViewById(R.id.txtvItemname); - 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 = (View) 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(convertView.getResources() - .getColor(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()); - - FeedItem.State state = item.getState(); - switch (state) { - case PLAYING: - holder.statusUnread.setVisibility(View.GONE); - holder.episodeProgress.setVisibility(View.VISIBLE); - break; - case IN_PROGRESS: - holder.statusUnread.setVisibility(View.GONE); - holder.episodeProgress.setVisibility(View.VISIBLE); - break; - case NEW: - holder.statusUnread.setVisibility(View.VISIBLE); - break; - default: - holder.statusUnread.setVisibility(View.GONE); - break; - } - - holder.published.setText(convertView.getResources().getString( - R.string.published_prefix) - + DateUtils.getRelativeTimeSpanString( - item.getPubDate().getTime(), - System.currentTimeMillis(), 0, 0)); - - 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 { - - if (state == FeedItem.State.PLAYING - || state == FeedItem.State.IN_PROGRESS) { - if (media.getDuration() > 0) { - holder.episodeProgress - .setProgress((int) (((double) media - .getPosition()) / media.getDuration() * 100)); - holder.lenSize.setText(Converter - .getDurationStringLong(media.getDuration() - - media.getPosition())); - } - } else if (!media.isDownloaded()) { - holder.lenSize.setText(getContext().getString( - R.string.size_prefix) - + Converter.byteToString(media.getSize())); - } else { - holder.lenSize.setText(getContext().getString( - R.string.length_prefix) - + Converter.getDurationStringLong(media - .getDuration())); - } - - holder.lenSize.setVisibility(View.VISIBLE); - if (((ItemAccess) itemAccess).isInQueue(item)) { - 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) itemAccess).getItemDownloadProgressPercent(item)); - } else if (!(state == FeedItem.State.IN_PROGRESS - || state == FeedItem.State.PLAYING)) { - holder.episodeProgress.setVisibility(View.GONE); - } - - TypedArray typeDrawables = getContext().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(getContext().getString(labels[0])); - holder.type.setVisibility(View.VISIBLE); - } else if (mediaType == MediaType.VIDEO) { - holder.type.setImageDrawable(typeDrawables.getDrawable(1)); - holder.type.setContentDescription(getContext().getString(labels[1])); - holder.type.setVisibility(View.VISIBLE); - } else { - holder.type.setImageBitmap(null); - holder.type.setVisibility(View.GONE); - } - } - - actionButtonUtils.configureActionButton(holder.butAction, item); - holder.butAction.setFocusable(false); - holder.butAction.setTag(item); - holder.butAction.setOnClickListener(butActionListener); - - } else { - convertView.setVisibility(View.GONE); - } - return convertView; - - } - - private final OnClickListener butActionListener = new OnClickListener() { - @Override - public void onClick(View v) { - FeedItem item = (FeedItem) v.getTag(); - callback.onActionButtonPressed(item); - } - }; - - static class Holder extends DefaultFeedItemlistAdapter.Holder { - ImageView inPlaylist; - ImageButton butAction; - View statusUnread; - ProgressBar episodeProgress; - } - - public int getSelectedItemIndex() { - return selectedItemIndex; - } - - public void setSelectedItemIndex(int selectedItemIndex) { - this.selectedItemIndex = selectedItemIndex; - notifyDataSetChanged(); - } - - public static interface ItemAccess extends DefaultFeedItemlistAdapter.ItemAccess { - public boolean isInQueue(FeedItem item); - - int getItemDownloadProgressPercent(FeedItem item); - } - -} |