X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2FDownloadFile.java;h=0a1d1dcab81a713c2a0b7f090f85f109453867e6;hb=015b8984ce72dc3c4c541d8caab6ef78d4fb6a17;hp=627335df711dc8c5528999c01b6091c5d7d10e01;hpb=bc6574b86391ed9c731835c18de7bd0a10de19f8;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java index 627335df..0a1d1dca 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java +++ b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java @@ -48,20 +48,17 @@ public class DownloadFile extends DialogFragment { Bundle argumentsBundle = new Bundle(); String fileNameString; - if (!contentDisposition.isEmpty()) { // Extract `fileNameString` from `contentDisposition` using the substring beginning after `filename="` and ending one character before the end of `contentDisposition`. - fileNameString = contentDisposition.substring(contentDisposition.indexOf("filename=\"") + 10, contentDisposition.length() - 1); + if (!contentDisposition.isEmpty()) { // Extract `fileNameString` from `contentDisposition` using the substring beginning after `filename="` and ending with the next `"`. + fileNameString = contentDisposition.substring(contentDisposition.indexOf("filename=\"") + 10, contentDisposition.indexOf("\"", contentDisposition.indexOf("filename=\"") + 10)); } else { // `contentDisposition` is empty, so use the last path segment of the URL as the file name. Uri downloadUri = Uri.parse(urlString); fileNameString = downloadUri.getLastPathSegment(); } - // Convert `contentLength` to MB and store it in `fileSizeString`. `%.3g` displays the three most significant digits. - String fileSizeString = String.format(Locale.getDefault(), "%.3g", (float) contentLength / 1048576) + " MB"; - // Store the variables in the `Bundle`. argumentsBundle.putString("URL", urlString); argumentsBundle.putString("File_Name", fileNameString); - argumentsBundle.putString("File_Size", fileSizeString); + argumentsBundle.putLong("File_Size", contentLength); // Add `argumentsBundle` to this instance of `DownloadFile`. DownloadFile thisDownloadFileDialog = new DownloadFile(); @@ -76,7 +73,16 @@ public class DownloadFile extends DialogFragment { // Store the strings in the local class variables. downloadUrl = getArguments().getString("URL"); downloadFileName = getArguments().getString("File_Name"); - fileSize = getArguments().getString("File_Size"); + + // Get the `File_Size`. + long fileSizeLong = getArguments().getLong("File_Size"); + + // Convert `fileSizeLong` to a String. + if (fileSizeLong == -1) { // We don't know the file size. + fileSize = getString(R.string.unknown_size); + } else { // Convert `fileSize` to MB and store it in `fileSizeString`. `%.3g` displays the three most significant digits. + fileSize = String.format(Locale.getDefault(), "%.3g", (float) fileSizeLong / 1048576) + " MB"; + } } // The public interface is used to send information back to the parent activity.