MERGE stash.

This commit is contained in:
Martin Fietz 2015-03-04 10:41:40 +01:00
parent dcada04621
commit 6c81f6c868
3 changed files with 110 additions and 29 deletions

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.adapter;
import android.content.Context;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -16,6 +17,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.Converter;
/**
* List adapter for the queue.
@ -64,12 +66,16 @@ public class QueueListAdapter extends BaseAdapter {
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.queue_listitem,
parent, false);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage);
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
holder.pubDate = (TextView) convertView.findViewById(R.id.txtvPubDate);
holder.progressLeft = (TextView) convertView.findViewById(R.id.txtvProgressLeft);
holder.progressRight = (TextView) convertView
.findViewById(R.id.txtvProgressRight);
holder.butSecondary = (ImageButton) convertView
.findViewById(R.id.butSecondaryAction);
holder.position = (TextView) convertView.findViewById(R.id.txtvPosition);
holder.progress = (ProgressBar) convertView
.findViewById(R.id.pbar_download_progress);
.findViewById(R.id.progressBar);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage);
convertView.setTag(holder);
} else {
@ -77,19 +83,39 @@ public class QueueListAdapter extends BaseAdapter {
}
holder.title.setText(item.getTitle());
AdapterUtils.updateEpisodePlaybackProgress(item, context.getResources(), holder.position, holder.progress);
FeedMedia media = item.getMedia();
holder.title.setText(item.getTitle());
String pubDate = DateUtils.formatDateTime(context, item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL);
holder.pubDate.setText(pubDate.replace(" ", "\n"));
if (media != null) {
final boolean isDownloadingMedia = DownloadRequester.getInstance().isDownloadingFile(media);
if (!media.isDownloaded()) {
if (isDownloadingMedia) {
// item is being downloaded
holder.progress.setVisibility(View.VISIBLE);
holder.progress.setProgress(itemAccess.getItemDownloadProgressPercent(item));
FeedItem.State state = item.getState();
if (isDownloadingMedia) {
holder.progressLeft.setText(Converter.byteToString(itemAccess.getItemDownloadedBytes(item)));
if(itemAccess.getItemDownloadSize(item) > 0) {
holder.progressRight.setText(Converter.byteToString(itemAccess.getItemDownloadSize(item)));
} else {
holder.progressRight.setText(Converter.byteToString(media.getSize()));
}
holder.progress.setProgress(itemAccess.getItemDownloadProgressPercent(item));
holder.progress.setVisibility(View.VISIBLE);
} else if (state == FeedItem.State.PLAYING
|| state == FeedItem.State.IN_PROGRESS) {
if (media.getDuration() > 0) {
int progress = (int) (100.0 * media.getPosition() / media.getDuration());
holder.progress.setProgress(progress);
holder.progress.setVisibility(View.VISIBLE);
holder.progressLeft.setText(Converter
.getDurationStringLong(media.getPosition()));
holder.progressRight.setText(Converter.getDurationStringLong(media.getDuration()));
}
} else {
holder.progressLeft.setText(Converter.byteToString(media.getSize()));
holder.progressRight.setText(Converter.getDurationStringLong(media.getDuration()));
holder.progress.setVisibility(View.GONE);
}
}
@ -116,18 +142,20 @@ public class QueueListAdapter extends BaseAdapter {
static class Holder {
TextView title;
ImageView imageView;
TextView position;
TextView title;
TextView pubDate;
TextView progressLeft;
TextView progressRight;
ProgressBar progress;
ImageButton butSecondary;
}
public interface ItemAccess {
int getCount();
FeedItem getItem(int position);
int getCount();
long getItemDownloadedBytes(FeedItem item);
long getItemDownloadSize(FeedItem item);
int getItemDownloadProgressPercent(FeedItem item);
}
}

View File

@ -366,6 +366,33 @@ public class QueueFragment extends Fragment {
return (itemsLoaded) ? queue.get(position) : null;
}
@Override
public long getItemDownloadedBytes(FeedItem item) {
if (downloaderList != null) {
for (Downloader downloader : downloaderList) {
if (downloader.getDownloadRequest().getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA
&& downloader.getDownloadRequest().getFeedfileId() == item.getMedia().getId()) {
Log.d(TAG, "downloaded bytes: " + downloader.getDownloadRequest().getSoFar());
return downloader.getDownloadRequest().getSoFar();
}
}
}
return 0;
}
@Override
public long getItemDownloadSize(FeedItem item) {
if (downloaderList != null) {
for (Downloader downloader : downloaderList) {
if (downloader.getDownloadRequest().getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA
&& downloader.getDownloadRequest().getFeedfileId() == item.getMedia().getId()) {
Log.d(TAG, "downloaded size: " + downloader.getDownloadRequest().getSize());
return downloader.getDownloadRequest().getSize();
}
}
}
return 0;
}
@Override
public int getItemDownloadProgressPercent(FeedItem item) {
if (downloaderList != null) {

View File

@ -32,7 +32,7 @@
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
android:layout_marginLeft="@dimen/listitem_threeline_textleftpadding"
android:layout_marginRight="@dimen/listitem_threeline_textrightpadding"
@ -40,46 +40,72 @@
android:layout_weight="1"
tools:background="@android:color/holo_red_dark">
<!-- order is important, pubDate first! -->
<TextView
android:id="@+id/txtvPubDate"
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="2"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:gravity="right|bottom"
android:text="Feb\n12"
tools:background="@android:color/holo_blue_light" />
<TextView
android:id="@+id/txtvTitle"
style="@style/AntennaPod.TextView.ListItemPrimaryTitle"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/txtvPubDate"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Queue item title"
android:ellipsize="end"
tools:background="@android:color/holo_blue_light" />
<RelativeLayout
android:id="@+id/bottom_bar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@id/txtvTitle"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="16dp">
android:layout_alignParentRight="true">
<TextView
android:id="@+id/txtvPosition"
android:id="@+id/txtvProgressLeft"
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="0dp"
android:text="00:42:23"
tools:background="@android:color/holo_blue_light" />
tools:background="@android:color/holo_blue_light"/>
<ProgressBar
android:id="@+id/pbar_download_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
<TextView
android:id="@+id/txtvProgressRight"
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="8dp"
android:layout_toRightOf="@id/txtvPosition"
android:layout_marginBottom="0dp"
tools:text="Jan 23"
tools:background="@android:color/holo_green_dark" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtvProgressLeft"
android:layout_marginTop="-2dp"
android:max="100"
tools:background="@android:color/holo_blue_light" />
</RelativeLayout>
</RelativeLayout>