diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2015-03-04 10:41:40 +0100 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-03-04 14:42:35 +0100 |
commit | 6c81f6c868971fc343cfa49d54927dd845a39ede (patch) | |
tree | ddd091b149a10d09d1179cda2fe3ae809eb7d8cd /app | |
parent | dcada04621fb79c3c236152629fab9f0e90d5712 (diff) | |
download | AntennaPod-6c81f6c868971fc343cfa49d54927dd845a39ede.zip |
MERGE stash.
Diffstat (limited to 'app')
3 files changed, 107 insertions, 26 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java index d5b85575b..77b2b4d49 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java @@ -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()); + FeedMedia media = item.getMedia(); - 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 + 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.progress.setProgress(itemAccess.getItemDownloadProgressPercent(item)); + 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); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 49129c999..30238ff51 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -367,6 +367,33 @@ public class QueueFragment extends Fragment { } @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) { for (Downloader downloader : downloaderList) { diff --git a/app/src/main/res/layout/queue_listitem.xml b/app/src/main/res/layout/queue_listitem.xml index 74c6ed785..5d41c52cd 100644 --- a/app/src/main/res/layout/queue_listitem.xml +++ b/app/src/main/res/layout/queue_listitem.xml @@ -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"/> + + <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_marginBottom="0dp" + tools:text="Jan 23" + tools:background="@android:color/holo_green_dark" /> <ProgressBar - android:id="@+id/pbar_download_progress" + android:id="@+id/progressBar" style="?android:attr/progressBarStyleHorizontal" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_alignParentRight="true" - android:layout_marginLeft="8dp" - android:layout_toRightOf="@id/txtvPosition" + android:layout_below="@id/txtvProgressLeft" + android:layout_marginTop="-2dp" android:max="100" tools:background="@android:color/holo_blue_light" /> + </RelativeLayout> </RelativeLayout> |