+ // `onProgressUpdate()` operates on the UI thread.
+ @Override
+ protected void onProgressUpdate(Long... downloadPercentage) {
+ // Get a handle for the activity.
+ Activity activity = activityWeakReference.get();
+
+ // Abort if the activity is gone.
+ if ((activity == null) || activity.isFinishing()) {
+ return;
+ }
+
+ // Check to see if a download percentage has been calculated.
+ if (downloadPercentage[0] < 0) { // There is no download percentage. The negative number represents the raw downloaded kilobytes.
+ // Calculate the number of bytes downloaded.
+ long numberOfBytesDownloaded = (0 - downloadPercentage[0]) * 1024;
+
+ // Format the number of bytes downloaded.
+ String formattedNumberOfBytesDownloaded = NumberFormat.getInstance().format(numberOfBytesDownloaded);
+
+ // Update the snackbar.
+ savingFileSnackbar.setText(activity.getString(R.string.saving_file) + ": " + formattedNumberOfBytesDownloaded + " " + activity.getString(R.string.bytes) + " - " + filePathString);
+ } else { // There is a download percentage.
+ // Update the snackbar.
+ savingFileSnackbar.setText(activity.getString(R.string.saving_file) + ": " + downloadPercentage[0] + "% - " + filePathString);
+ }
+ }
+