From: Soren Stoutner Date: Sat, 27 Mar 2021 00:43:04 +0000 (-0700) Subject: Update the download snackbars to be more descriptive. https://redmine.stoutner.com... X-Git-Tag: v3.7~1 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=7e0198f9aef9900b2c400b278e08f3e8273f2593;p=PrivacyBrowserAndroid.git Update the download snackbars to be more descriptive. https://redmine.stoutner.com/issues/676 --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java index de4ec477..1d000e38 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java @@ -47,11 +47,11 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.cardview.widget.CardView; import androidx.core.content.FileProvider; -import androidx.multidex.BuildConfig; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.textfield.TextInputLayout; +import com.stoutner.privacybrowser.BuildConfig; import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.helpers.ImportExportDatabaseHelper; diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveUrl.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveUrl.java index 8956296d..7d981c0f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveUrl.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveUrl.java @@ -53,6 +53,9 @@ public class SaveUrl extends AsyncTask { private final String userAgent; private final boolean cookiesEnabled; private Snackbar savingFileSnackbar; + private long fileSize; + private String formattedFileSize; + private String urlString = ""; // The public constructor. public SaveUrl(Context context, Activity activity, String filePathString, String userAgent, boolean cookiesEnabled) { @@ -81,7 +84,7 @@ public class SaveUrl extends AsyncTask { NoSwipeViewPager noSwipeViewPager = activity.findViewById(R.id.webviewpager); // Create a saving file snackbar. - savingFileSnackbar = Snackbar.make(noSwipeViewPager, activity.getString(R.string.saving_file) + " 0% - " + filePathString, Snackbar.LENGTH_INDEFINITE); + savingFileSnackbar = Snackbar.make(noSwipeViewPager, activity.getString(R.string.saving_file) + " 0% - " + urlString, Snackbar.LENGTH_INDEFINITE); // Display the saving file snackbar. savingFileSnackbar.show(); @@ -101,14 +104,17 @@ public class SaveUrl extends AsyncTask { // Define a save disposition string. String saveDisposition = SUCCESS; + // Get the URL string. + urlString = urlToSave[0]; + try { // Open an output stream. OutputStream outputStream = activity.getContentResolver().openOutputStream(Uri.parse(filePathString)); // Save the URL. - if (urlToSave[0].startsWith("data:")) { // The URL contains the entire data of an image. + if (urlString.startsWith("data:")) { // The URL contains the entire data of an image. // Get the Base64 data, which begins after a `,`. - String base64DataString = urlToSave[0].substring(urlToSave[0].indexOf(",") + 1); + String base64DataString = urlString.substring(urlString.indexOf(",") + 1); // Decode the Base64 string to a byte array. byte[] base64DecodedDataByteArray = Base64.decode(base64DataString, Base64.DEFAULT); @@ -117,7 +123,7 @@ public class SaveUrl extends AsyncTask { outputStream.write(base64DecodedDataByteArray); } else { // The URL points to the data location on the internet. // Get the URL from the calling activity. - URL url = new URL(urlToSave[0]); + URL url = new URL(urlString); // Instantiate the proxy helper. ProxyHelper proxyHelper = new ProxyHelper(); @@ -148,13 +154,13 @@ public class SaveUrl extends AsyncTask { // Get the content length header, which causes the connection to the server to be made. String contentLengthString = httpUrlConnection.getHeaderField("Content-Length"); - // Define the file size long. - long fileSize; - // Make sure the content length isn't null. if (contentLengthString != null) { // The content length isn't null. // Convert the content length to an long. fileSize = Long.parseLong(contentLengthString); + + // Format the file size for display. + formattedFileSize = NumberFormat.getInstance().format(fileSize); } else { // The content length is null. // Set the file size to be `-1`. fileSize = -1; @@ -177,22 +183,11 @@ public class SaveUrl extends AsyncTask { // Write the contents of the conversion buffer to the file output stream. outputStream.write(conversionBufferByteArray, 0, bufferLength); - // Update the file download progress snackbar. - if (fileSize == -1) { // The file size is unknown. - // Negatively update the downloaded kilobytes counter. - downloadedKilobytesCounter = downloadedKilobytesCounter - bufferLength; - - publishProgress(downloadedKilobytesCounter); - } else { // The file size is known. - // Update the downloaded kilobytes counter. - downloadedKilobytesCounter = downloadedKilobytesCounter + bufferLength; + // Update the downloaded kilobytes counter. + downloadedKilobytesCounter = downloadedKilobytesCounter + bufferLength; - // Calculate the download percentage. - long downloadPercentage = (downloadedKilobytesCounter * 100) / fileSize; - - // Update the download percentage. - publishProgress(downloadPercentage); - } + // Update the file download progress snackbar. + publishProgress(downloadedKilobytesCounter); } // Close the input stream. @@ -219,7 +214,7 @@ public class SaveUrl extends AsyncTask { // `onProgressUpdate()` operates on the UI thread. @Override - protected void onProgressUpdate(Long... downloadPercentage) { + protected void onProgressUpdate(Long... numberOfBytesDownloaded) { // Get a handle for the activity. Activity activity = activityWeakReference.get(); @@ -228,19 +223,20 @@ public class SaveUrl extends AsyncTask { 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. When the `downloadPercentage` is negative, it is actually the raw number of kilobytes downloaded. - long numberOfBytesDownloaded = - downloadPercentage[0]; - - // Format the number of bytes downloaded. - String formattedNumberOfBytesDownloaded = NumberFormat.getInstance().format(numberOfBytesDownloaded); + // Format the number of bytes downloaded. + String formattedNumberOfBytesDownloaded = NumberFormat.getInstance().format(numberOfBytesDownloaded[0]); + // Check to see if the file size is known. + if (fileSize == -1) { // The size of the download file is not known. // Update the snackbar. - savingFileSnackbar.setText(activity.getString(R.string.saving_file) + " " + formattedNumberOfBytesDownloaded + " " + activity.getString(R.string.bytes) + " - " + filePathString); - } else { // There is a download percentage. + savingFileSnackbar.setText(activity.getString(R.string.saving_file) + " " + formattedNumberOfBytesDownloaded + " " + activity.getString(R.string.bytes) + " - " + urlString); + } else { // The size of the download file is known. + // Calculate the download percentage. + long downloadPercentage = (numberOfBytesDownloaded[0] * 100) / fileSize; + // Update the snackbar. - savingFileSnackbar.setText(activity.getString(R.string.saving_file) + " " + downloadPercentage[0] + "% - " + filePathString); + savingFileSnackbar.setText(activity.getString(R.string.saving_file) + " " + downloadPercentage + "% - " + formattedNumberOfBytesDownloaded + " " + activity.getString(R.string.bytes) + " / " + formattedFileSize + " " + + activity.getString(R.string.bytes) + " - " + urlString); } } @@ -264,7 +260,7 @@ public class SaveUrl extends AsyncTask { // Display a save disposition snackbar. if (saveDisposition.equals(SUCCESS)) { // Display the file saved snackbar. - Snackbar.make(noSwipeViewPager, activity.getString(R.string.file_saved) + " " + filePathString, Snackbar.LENGTH_LONG).show(); + Snackbar.make(noSwipeViewPager, activity.getString(R.string.file_saved) + " " + urlString, Snackbar.LENGTH_LONG).show(); } else { // Display the file saving error. Snackbar.make(noSwipeViewPager, activity.getString(R.string.error_saving_file) + " " + saveDisposition, Snackbar.LENGTH_INDEFINITE).show(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveWebpageImage.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveWebpageImage.java index 27acbc5c..e44f5e6d 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveWebpageImage.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveWebpageImage.java @@ -70,7 +70,7 @@ public class SaveWebpageImage extends AsyncTask { } // Create a saving image snackbar. - savingImageSnackbar = Snackbar.make(nestedScrollWebView, activity.getString(R.string.processing_image) + " " + filePathString, Snackbar.LENGTH_INDEFINITE); + savingImageSnackbar = Snackbar.make(nestedScrollWebView, activity.getString(R.string.processing_image) + " " + nestedScrollWebView.getCurrentUrl(), Snackbar.LENGTH_INDEFINITE); // Display the saving image snackbar. savingImageSnackbar.show(); @@ -136,8 +136,8 @@ public class SaveWebpageImage extends AsyncTask { // Display a file creation disposition snackbar. if (fileCreationDisposition.equals(SUCCESS)) { - // Display the file saved snackbar. - Snackbar.make(nestedScrollWebView, activity.getString(R.string.file_saved) + " " + filePathString, Snackbar.LENGTH_SHORT).show(); + // Display the image saved snackbar. + Snackbar.make(nestedScrollWebView, activity.getString(R.string.image_saved) + " " + nestedScrollWebView.getCurrentUrl(), Snackbar.LENGTH_SHORT).show(); } else { // Display the file saving error. Snackbar.make(nestedScrollWebView, activity.getString(R.string.error_saving_file) + " " + fileCreationDisposition, Snackbar.LENGTH_INDEFINITE).show(); diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 1d46306e..e55fb9f1 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -204,8 +204,8 @@ Unbekannte Größe Ungültige URL Speichere Datei: - Bild wird bearbeitet… : Datei gespeichert: + Bild wird bearbeitet… : Fehler beim Speichern der Datei: diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index f7d81ad6..eb52a899 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -200,8 +200,8 @@ Tamaño desconocido URL inválida Guardando archivo: - Procesando imagen… : Archivo guardado: + Procesando imagen… : Error guardando archivo: diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 00fe33f6..662b2f7d 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -201,8 +201,8 @@ taille inconnue URL invalide Enregistrement du fichier: - Traitement de l\'image… : Fichier enregistré: + Traitement de l\'image… : Erreur lors de l\'enregistrement du fichier: diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 9e8a8cf0..72be41e9 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -200,8 +200,8 @@ Dimensione sconosciuta URL non valida Salvataggio file: - Creazione immagine… : File salvato: + Creazione immagine… : Errore salvataggio file: diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 6660cdd9..378d0857 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -199,8 +199,8 @@ tamanho desconhecido URL inválida Salvando file: - Processando imagem… : Arquivo Salvo: + Processando imagem… : Erro ao salvar o arquivo: diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 2c993d30..dbf51be9 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -197,8 +197,8 @@ неизвестный размер неправильный URL Сохранение файла: - Обработка изображения… : Файл сохранен: + Обработка изображения… : Ошибка сохранения файла: diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c92e65f4..4ff16289 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -206,8 +206,9 @@ unknown size invalid URL Saving file: - Processing image… : File saved: + Processing image… : + Image saved: Error saving file: