Emit every 10% of downloading progress
This commit is contained in:
parent
e5bdf7a4dc
commit
4cff926bd6
|
@ -71,6 +71,7 @@ public class Downloader extends AsyncTask<DownloadParams, int[], DownloadResult>
|
|||
byte data[] = new byte[8 * 1024];
|
||||
int total = 0;
|
||||
int count;
|
||||
double lastProgressValue = 0;
|
||||
|
||||
while ((count = input.read(data)) != -1) {
|
||||
if (mAbort.get()) {
|
||||
|
@ -78,7 +79,14 @@ public class Downloader extends AsyncTask<DownloadParams, int[], DownloadResult>
|
|||
}
|
||||
|
||||
total += count;
|
||||
publishProgress(new int[] { lengthOfFile, total });
|
||||
double progress = Math.round(((double) total * 100) / lengthOfFile);
|
||||
if (progress % 10 == 0) {
|
||||
if ((progress != lastProgressValue) || (total == lengthOfFile)) {
|
||||
Log.d("Downloader", "EMIT: " + String.valueOf(progress) + ", TOTAL:" + String.valueOf(total));
|
||||
lastProgressValue = progress;
|
||||
publishProgress(new int[]{lengthOfFile, total});
|
||||
}
|
||||
}
|
||||
output.write(data, 0, count);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue