X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2FDownloadFile.java;h=a35091fbab74e845bc894db237fa45e4410d923f;hp=4bdc879abb113e08064898a44e442799129925ad;hb=e8bcccda781e0aa65ee4cc11428f3e99dc400015;hpb=b36f8bd357e28072bd7c810bb3ae47e4e0b20acc diff --git a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java index 4bdc879a..a35091fb 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java +++ b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java @@ -23,6 +23,7 @@ import android.app.Activity; import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; +import android.net.Uri; import android.os.Bundle; // `android.support.v7.app.AlertDialog` uses more of the horizontal screen real estate versus `android.app.AlertDialog's` smaller width. import android.support.v7.app.AlertDialog; @@ -45,12 +46,11 @@ public class DownloadFile extends DialogFragment { // Create `argumentsBundle`. Bundle argumentsBundle = new Bundle(); - // If `contentDisposition` is empty, use Android's standard string of `downloadfile.bin`. String fileNameString; - if (contentDisposition.isEmpty()) { - fileNameString = "downloadfile.bin"; - } else { - // Extract `fileNameString` from `contentDisposition` using the substring beginning after `filename="` and ending one character before the end of `contentDisposition`. + if (contentDisposition.isEmpty()) { // If `contentDisposition` is empty, use the last path segment of the URL as the file name. + Uri downloadUri = Uri.parse(urlString); + fileNameString = downloadUri.getLastPathSegment(); + } else { // 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); } @@ -103,7 +103,7 @@ public class DownloadFile extends DialogFragment { // Use `AlertDialog.Builder` to create the `AlertDialog`. `R.style.lightAlertDialog` formats the color of the button text. AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); - dialogBuilder.setTitle(R.string.file_download); + dialogBuilder.setTitle(R.string.save_as); // The parent view is `null` because it will be assigned by `AlertDialog`. dialogBuilder.setView(layoutInflater.inflate(R.layout.download_file_dialog, null));