Hide download progress in percent if download size is unknown

This commit is contained in:
daniel oeh 2012-09-14 15:53:29 +02:00
parent 858cdc6233
commit 35d083e463
3 changed files with 23 additions and 7 deletions

View File

@ -81,10 +81,18 @@ public class DownloadlistAdapter extends ArrayAdapter<Downloader> {
if (status.getStatusMsg() != 0) {
holder.message.setText(status.getStatusMsg());
}
holder.downloaded.setText(Converter.byteToString(status.getSoFar())
+ " / " + Converter.byteToString(status.getSize()));
holder.percent.setText(status.getProgressPercent() + "%");
holder.progbar.setProgress(status.getProgressPercent());
String strDownloaded = Converter.byteToString(status.getSoFar());
if (status.getSize() != DownloadStatus.SIZE_UNKNOWN) {
strDownloaded += " / " + Converter.byteToString(status.getSize());
holder.percent.setText(status.getProgressPercent() + "%");
holder.progbar.setProgress(status.getProgressPercent());
holder.percent.setVisibility(View.VISIBLE);
} else {
holder.progbar.setProgress(0);
holder.percent.setVisibility(View.INVISIBLE);
}
holder.downloaded.setText(strDownloaded);
return convertView;
}

View File

@ -6,6 +6,11 @@ import de.danoeh.antennapod.feed.FeedFile;
/** Contains status attributes for one download */
public class DownloadStatus {
/**
* Downloaders should use this constant for the size attribute if necessary
* so that the listadapters etc. can react properly.
*/
public static final int SIZE_UNKNOWN = -1;
public Date getCompletionDate() {
return completionDate;

View File

@ -57,12 +57,15 @@ public class HttpDownloader extends Downloader {
status.setSize(connection.getContentLength());
if (AppConfig.DEBUG)
Log.d(TAG, "Size is " + status.getSize());
if (status.getSize() == -1) {
status.setSize(DownloadStatus.SIZE_UNKNOWN);
}
long freeSpace = StorageUtils.getFreeSpaceAvailable();
if (AppConfig.DEBUG)
Log.d(TAG, "Free space is " + freeSpace);
if (status.getSize() == -1 || status.getSize() <= freeSpace) {
if (AppConfig.DEBUG)
Log.d(TAG, "Size is " + status.getSize());
if (status.getSize() == DownloadStatus.SIZE_UNKNOWN
|| status.getSize() <= freeSpace) {
publishProgress();
if (AppConfig.DEBUG)
Log.d(TAG, "Starting download");