Added progress bar to queue items
This commit is contained in:
parent
d058b47460
commit
998d3f1628
|
@ -15,30 +15,27 @@
|
|||
android:layout_margin="8dp"
|
||||
android:contentDescription="@string/drag_handle_content_description"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginRight="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imgvImage"
|
||||
android:contentDescription="@string/cover_label"
|
||||
android:layout_width="@dimen/thumbnail_length_queue_item"
|
||||
android:layout_height="@dimen/thumbnail_length_queue_item"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_toRightOf="@id/imgvImage"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:ellipsize="end"
|
||||
android:lines="2"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
|
@ -49,7 +46,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_toRightOf="@id/imgvImage"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
|
@ -57,6 +54,14 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvPosition"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="@dimen/text_size_micro"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pbar_download_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
|
@ -65,8 +70,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_alignParentLeft="true"/>
|
||||
android:layout_toRightOf="@id/txtvPosition"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package de.danoeh.antennapod.adapter;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.feed.FeedItem;
|
||||
import de.danoeh.antennapod.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.util.Converter;
|
||||
|
||||
/**
|
||||
* Utility methods for adapters
|
||||
*/
|
||||
public class AdapterUtils {
|
||||
|
||||
private AdapterUtils() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the contents of the TextView that shows the current playback position and the ProgressBar.
|
||||
*/
|
||||
public static void updateEpisodePlaybackProgress(FeedItem item, Resources res, TextView txtvPos, ProgressBar episodeProgress) {
|
||||
FeedMedia media = item.getMedia();
|
||||
episodeProgress.setVisibility(View.GONE);
|
||||
if (media == null) {
|
||||
txtvPos.setVisibility(View.GONE);
|
||||
return;
|
||||
} else {
|
||||
txtvPos.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
FeedItem.State state = item.getState();
|
||||
if (state == FeedItem.State.PLAYING
|
||||
|| state == FeedItem.State.IN_PROGRESS) {
|
||||
if (media.getDuration() > 0) {
|
||||
episodeProgress.setVisibility(View.VISIBLE);
|
||||
episodeProgress
|
||||
.setProgress((int) (((double) media
|
||||
.getPosition()) / media.getDuration() * 100));
|
||||
txtvPos.setText(Converter
|
||||
.getDurationStringLong(media.getDuration()
|
||||
- media.getPosition()));
|
||||
}
|
||||
} else if (!media.isDownloaded()) {
|
||||
txtvPos.setText(res.getString(
|
||||
R.string.size_prefix)
|
||||
+ Converter.byteToString(media.getSize()));
|
||||
} else {
|
||||
txtvPos.setText(res.getString(
|
||||
R.string.length_prefix)
|
||||
+ Converter.getDurationStringLong(media
|
||||
.getDuration()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -134,28 +134,8 @@ public class FeedItemlistAdapter extends BaseAdapter {
|
|||
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()));
|
||||
}
|
||||
AdapterUtils.updateEpisodePlaybackProgress(item, context.getResources(), holder.lenSize, holder.episodeProgress);
|
||||
|
||||
holder.lenSize.setVisibility(View.VISIBLE);
|
||||
if (((ItemAccess) itemAccess).isInQueue(item)) {
|
||||
holder.inPlaylist.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
|
@ -166,9 +146,6 @@ public class FeedItemlistAdapter extends BaseAdapter {
|
|||
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(
|
||||
|
|
|
@ -61,7 +61,8 @@ public class QueueListAdapter extends BaseAdapter {
|
|||
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
|
||||
holder.butSecondary = (ImageButton) convertView
|
||||
.findViewById(R.id.butSecondaryAction);
|
||||
holder.downloadProgress = (ProgressBar) convertView
|
||||
holder.position = (TextView) convertView.findViewById(R.id.txtvPosition);
|
||||
holder.progress = (ProgressBar) convertView
|
||||
.findViewById(R.id.pbar_download_progress);
|
||||
holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage);
|
||||
convertView.setTag(holder);
|
||||
|
@ -71,20 +72,17 @@ public class QueueListAdapter extends BaseAdapter {
|
|||
|
||||
holder.title.setText(item.getTitle());
|
||||
|
||||
AdapterUtils.updateEpisodePlaybackProgress(item, context.getResources(), holder.position, holder.progress);
|
||||
|
||||
FeedMedia media = item.getMedia();
|
||||
if (media != null) {
|
||||
final boolean isDownloadingMedia = DownloadRequester.getInstance().isDownloadingFile(media);
|
||||
|
||||
|
||||
if (isDownloadingMedia) {
|
||||
holder.downloadProgress.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.downloadProgress.setVisibility(View.GONE);
|
||||
}
|
||||
if (!media.isDownloaded()) {
|
||||
if (isDownloadingMedia) {
|
||||
// item is being downloaded
|
||||
holder.downloadProgress.setProgress(itemAccess.getItemDownloadProgressPercent(item));
|
||||
holder.progress.setVisibility(View.VISIBLE);
|
||||
holder.progress.setProgress(itemAccess.getItemDownloadProgressPercent(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +114,8 @@ public class QueueListAdapter extends BaseAdapter {
|
|||
static class Holder {
|
||||
TextView title;
|
||||
ImageView imageView;
|
||||
ProgressBar downloadProgress;
|
||||
TextView position;
|
||||
ProgressBar progress;
|
||||
ImageButton butSecondary;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue