From 4cff926bd655bc2e8b81eab9c6cf1b193cf45a1a Mon Sep 17 00:00:00 2001 From: Nikita Date: Mon, 30 May 2016 18:33:48 +0300 Subject: [PATCH] Emit every 10% of downloading progress --- android/src/main/java/com/rnfs/Downloader.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/rnfs/Downloader.java b/android/src/main/java/com/rnfs/Downloader.java index 3c36736..e29255c 100644 --- a/android/src/main/java/com/rnfs/Downloader.java +++ b/android/src/main/java/com/rnfs/Downloader.java @@ -71,6 +71,7 @@ public class Downloader extends AsyncTask 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 } 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); }