diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-03-07 18:52:47 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-03-07 18:52:47 +0100 |
commit | 98dec67b72005ea346fe9ac152fc3500b28e4795 (patch) | |
tree | a01068143c2e7b4913e09bbca96c9284e3cf85e9 /src/de | |
parent | ba0f294850ea0b1a4ec6417c7185019db97f7bcd (diff) | |
download | AntennaPod-98dec67b72005ea346fe9ac152fc3500b28e4795.zip |
Use progressbar for showing the listening progress of an episode
Diffstat (limited to 'src/de')
-rw-r--r-- | src/de/danoeh/antennapod/adapter/ExternalEpisodesListAdapter.java | 49 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/adapter/InternalFeedItemlistAdapter.java | 52 |
2 files changed, 64 insertions, 37 deletions
diff --git a/src/de/danoeh/antennapod/adapter/ExternalEpisodesListAdapter.java b/src/de/danoeh/antennapod/adapter/ExternalEpisodesListAdapter.java index 64eec8a38..30fcc2fd8 100644 --- a/src/de/danoeh/antennapod/adapter/ExternalEpisodesListAdapter.java +++ b/src/de/danoeh/antennapod/adapter/ExternalEpisodesListAdapter.java @@ -9,6 +9,7 @@ import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.ProgressBar; import android.widget.TextView; import de.danoeh.antennapod.R; import de.danoeh.antennapod.asynctask.ImageLoader; @@ -89,8 +90,8 @@ public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter { .findViewById(R.id.butAction); holder.statusPlaying = (View) convertView .findViewById(R.id.statusPlaying); - holder.statusInProgress = (TextView) convertView - .findViewById(R.id.statusInProgress); + holder.episodeProgress = (ProgressBar) convertView + .findViewById(R.id.pbar_episode_progress); convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); @@ -98,36 +99,53 @@ public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter { holder.title.setText(item.getTitle()); holder.feedTitle.setText(item.getFeed().getTitle()); + FeedItem.State state = item.getState(); if (groupPosition == GROUP_POS_QUEUE) { - FeedItem.State state = item.getState(); switch (state) { case PLAYING: holder.statusPlaying.setVisibility(View.VISIBLE); - holder.statusInProgress.setVisibility(View.GONE); + holder.episodeProgress.setVisibility(View.VISIBLE); break; case IN_PROGRESS: holder.statusPlaying.setVisibility(View.GONE); - holder.statusInProgress.setVisibility(View.VISIBLE); - holder.statusInProgress.setText(Converter - .getDurationStringLong(item.getMedia().getPosition())); + holder.episodeProgress.setVisibility(View.VISIBLE); break; case NEW: holder.statusPlaying.setVisibility(View.GONE); - holder.statusInProgress.setVisibility(View.GONE); + holder.episodeProgress.setVisibility(View.GONE); break; default: holder.statusPlaying.setVisibility(View.GONE); - holder.statusInProgress.setVisibility(View.GONE); + holder.episodeProgress.setVisibility(View.GONE); break; } } else { holder.statusPlaying.setVisibility(View.GONE); - holder.statusInProgress.setVisibility(View.GONE); + holder.episodeProgress.setVisibility(View.GONE); } FeedMedia media = item.getMedia(); if (media != null) { + + 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())); + } + TypedArray drawables = context.obtainStyledAttributes(new int[] { R.attr.av_download, R.attr.navigation_refresh }); holder.lenSize.setVisibility(View.VISIBLE); @@ -137,20 +155,15 @@ public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter { holder.downloadStatus.setImageDrawable(drawables .getDrawable(1)); } else { - holder.downloadStatus.setVisibility(View.GONE); + holder.downloadStatus.setVisibility(View.INVISIBLE); } - holder.lenSize.setText(context.getString(R.string.size_prefix) - + Converter.byteToString(media.getSize())); } else { holder.downloadStatus.setVisibility(View.VISIBLE); holder.downloadStatus .setImageDrawable(drawables.getDrawable(0)); - holder.lenSize.setText(context - .getString(R.string.length_prefix) - + Converter.getDurationStringLong(media.getDuration())); } } else { - holder.downloadStatus.setVisibility(View.GONE); + holder.downloadStatus.setVisibility(View.INVISIBLE); holder.lenSize.setVisibility(View.INVISIBLE); } @@ -182,7 +195,7 @@ public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter { ImageView feedImage; ImageButton butAction; View statusPlaying; - TextView statusInProgress; + ProgressBar episodeProgress; } @Override diff --git a/src/de/danoeh/antennapod/adapter/InternalFeedItemlistAdapter.java b/src/de/danoeh/antennapod/adapter/InternalFeedItemlistAdapter.java index c8d41b10e..7b898385e 100644 --- a/src/de/danoeh/antennapod/adapter/InternalFeedItemlistAdapter.java +++ b/src/de/danoeh/antennapod/adapter/InternalFeedItemlistAdapter.java @@ -12,10 +12,12 @@ import android.view.ViewGroup; import android.widget.Adapter; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.ProgressBar; import android.widget.TextView; import de.danoeh.antennapod.R; import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedManager; +import de.danoeh.antennapod.feed.FeedMedia; import de.danoeh.antennapod.feed.MediaType; import de.danoeh.antennapod.storage.DownloadRequester; import de.danoeh.antennapod.util.Converter; @@ -72,8 +74,8 @@ public class InternalFeedItemlistAdapter extends DefaultFeedItemlistAdapter { .findViewById(R.id.statusPlaying); holder.statusUnread = (View) convertView .findViewById(R.id.statusUnread); - holder.statusInProgress = (TextView) convertView - .findViewById(R.id.statusInProgress); + holder.episodeProgress = (ProgressBar) convertView + .findViewById(R.id.pbar_episode_progress); convertView.setTag(holder); } else { @@ -99,24 +101,22 @@ public class InternalFeedItemlistAdapter extends DefaultFeedItemlistAdapter { case PLAYING: holder.statusPlaying.setVisibility(View.VISIBLE); holder.statusUnread.setVisibility(View.GONE); - holder.statusInProgress.setVisibility(View.GONE); + holder.episodeProgress.setVisibility(View.VISIBLE); break; case IN_PROGRESS: holder.statusPlaying.setVisibility(View.GONE); holder.statusUnread.setVisibility(View.GONE); - holder.statusInProgress.setVisibility(View.VISIBLE); - holder.statusInProgress.setText(Converter - .getDurationStringLong(item.getMedia().getPosition())); + holder.episodeProgress.setVisibility(View.VISIBLE); break; case NEW: holder.statusPlaying.setVisibility(View.GONE); holder.statusUnread.setVisibility(View.VISIBLE); - holder.statusInProgress.setVisibility(View.GONE); + holder.episodeProgress.setVisibility(View.GONE); break; default: holder.statusPlaying.setVisibility(View.GONE); holder.statusUnread.setVisibility(View.GONE); - holder.statusInProgress.setVisibility(View.GONE); + holder.episodeProgress.setVisibility(View.GONE); break; } @@ -126,13 +126,36 @@ public class InternalFeedItemlistAdapter extends DefaultFeedItemlistAdapter { System.currentTimeMillis(), DateFormat.MEDIUM, DateFormat.SHORT)); - if (item.getMedia() == null) { + FeedMedia media = item.getMedia(); + if (media == null) { holder.downloaded.setVisibility(View.GONE); holder.downloading.setVisibility(View.GONE); holder.inPlaylist.setVisibility(View.GONE); holder.type.setVisibility(View.GONE); holder.lenSize.setVisibility(View.GONE); } 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 (FeedManager.getInstance().isInQueue(item)) { holder.inPlaylist.setVisibility(View.VISIBLE); @@ -140,17 +163,8 @@ public class InternalFeedItemlistAdapter extends DefaultFeedItemlistAdapter { holder.inPlaylist.setVisibility(View.GONE); } if (item.getMedia().isDownloaded()) { - holder.lenSize.setText(convertView.getResources() - .getString(R.string.length_prefix) - + Converter.getDurationStringLong(item.getMedia() - .getDuration())); holder.downloaded.setVisibility(View.VISIBLE); } else { - holder.lenSize - .setText(convertView.getResources().getString( - R.string.size_prefix) - + Converter.byteToString(item.getMedia() - .getSize())); holder.downloaded.setVisibility(View.GONE); } @@ -200,7 +214,7 @@ public class InternalFeedItemlistAdapter extends DefaultFeedItemlistAdapter { ImageButton butAction; View statusUnread; View statusPlaying; - TextView statusInProgress; + ProgressBar episodeProgress; } public int getSelectedItemIndex() { |