diff --git a/F-Droid/src/org/fdroid/fdroid/AppDetails.java b/F-Droid/src/org/fdroid/fdroid/AppDetails.java index ecf187e8b..984e5420a 100644 --- a/F-Droid/src/org/fdroid/fdroid/AppDetails.java +++ b/F-Droid/src/org/fdroid/fdroid/AppDetails.java @@ -464,11 +464,10 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A new IntentFilter(Downloader.LOCAL_ACTION_PROGRESS)); downloadHandler.setProgressListener(this); - if (downloadHandler.getTotalSize() == 0) + if (downloadHandler.getTotalBytes() == 0) mHeaderFragment.startProgress(); else - mHeaderFragment.updateProgress(downloadHandler.getProgress(), - downloadHandler.getTotalSize()); + mHeaderFragment.updateProgress(downloadHandler.getBytesRead(), downloadHandler.getTotalBytes()); } } } diff --git a/F-Droid/src/org/fdroid/fdroid/net/ApkDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/ApkDownloader.java index cb4106e7b..98e76f0ba 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/ApkDownloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/ApkDownloader.java @@ -52,7 +52,6 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener { public static final int ERROR_HASH_MISMATCH = 101; public static final int ERROR_DOWNLOAD_FAILED = 102; - public static final int ERROR_UNKNOWN = 103; private static final String EVENT_SOURCE_ID = "sourceId"; private static long downloadIdCounter = 0; @@ -70,8 +69,6 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener { private ProgressListener listener; private AsyncDownloadWrapper dlWrapper = null; - private int progress = 0; - private int totalSize = 0; private boolean isComplete = false; private final long id = ++downloadIdCounter; @@ -274,7 +271,7 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener { public Apk getApk() { return curApk; } - public int getProgress() { return progress; } + public int getBytesRead() { return dlWrapper != null ? dlWrapper.getBytesRead() : 0; } - public int getTotalSize() { return totalSize; } + public int getTotalBytes() { return dlWrapper != null ? dlWrapper.getTotalBytes() : 0; } } diff --git a/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloadWrapper.java b/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloadWrapper.java index dc7ac055c..3588343b8 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloadWrapper.java +++ b/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloadWrapper.java @@ -72,6 +72,14 @@ public class AsyncDownloadWrapper extends Handler { } } + public int getBytesRead() { + return downloader.getBytesRead(); + } + + public int getTotalBytes() { + return downloader.getTotalBytes(); + } + public interface Listener extends ProgressListener { void onErrorDownloading(String localisedExceptionDetails); void onDownloadComplete(); diff --git a/F-Droid/src/org/fdroid/fdroid/net/Downloader.java b/F-Droid/src/org/fdroid/fdroid/net/Downloader.java index 000e26576..4802f39f2 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/Downloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/Downloader.java @@ -33,6 +33,8 @@ public abstract class Downloader { protected final URL sourceUrl; protected String cacheTag = null; + protected int bytesRead = 0; + protected int totalBytes = 0; public abstract InputStream getInputStream() throws IOException; @@ -145,7 +147,7 @@ public abstract class Downloader { byte[] buffer = new byte[Utils.BUFFER_SIZE]; int bytesRead = 0; - int totalBytes = totalDownloadSize(); + this.totalBytes = totalDownloadSize(); // Getting the total download size could potentially take time, depending on how // it is implemented, so we may as well check this before we proceed. @@ -169,6 +171,7 @@ public abstract class Downloader { } protected void sendProgress(int bytesRead, int totalBytes) { + this.bytesRead = bytesRead; Intent intent = new Intent(LOCAL_ACTION_PROGRESS); intent.putExtra(EXTRA_ADDRESS, sourceUrl.toString()); intent.putExtra(EXTRA_BYTES_READ, bytesRead); @@ -176,4 +179,11 @@ public abstract class Downloader { localBroadcastManager.sendBroadcast(intent); } + public int getBytesRead() { + return bytesRead; + } + + public int getTotalBytes() { + return totalBytes; + } }