From ff3641c1e0edbe729f4e09b804081d35185976e3 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 10 Nov 2022 11:51:01 -0700 Subject: [PATCH] Update Download with External App summary. https://redmine.stoutner.com/issues/921 --- .../activities/MainWebViewActivity.java | 49 ++++++++++--------- .../asynctasks/SaveAboutVersionImage.java | 4 +- .../privacybrowser/asynctasks/SaveUrl.java | 4 +- .../asynctasks/SaveWebpageImage.java | 8 +-- .../fragments/AboutVersionFragment.kt | 38 +++++++------- app/src/main/res/values-de/strings.xml | 4 -- app/src/main/res/values-es/strings.xml | 4 -- app/src/main/res/values-fr/strings.xml | 4 -- app/src/main/res/values-it/strings.xml | 4 -- app/src/main/res/values-pt-rBR/strings.xml | 4 -- app/src/main/res/values-ru/strings.xml | 4 -- app/src/main/res/values/strings.xml | 10 ++-- 12 files changed, 57 insertions(+), 80 deletions(-) diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index e1a8ca78..1ee31db4 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -391,11 +391,30 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook public void onActivityResult(Uri fileUri) { // Only save the webpage archive if the file URI is not null, which happens if the user exited the file picker by pressing back. if (fileUri != null) { + // Initialize the file name string from the file URI last path segment. + String temporaryFileNameString = fileUri.getLastPathSegment(); + + // Query the exact file name if the API >= 26. + if (Build.VERSION.SDK_INT >= 26) { + // Get a cursor from the content resolver. + Cursor contentResolverCursor = resultLauncherActivityHandle.getContentResolver().query(fileUri, null, null, null); + + // Move to the fist row. + contentResolverCursor.moveToFirst(); + + // Get the file name from the cursor. + temporaryFileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)); + + // Close the cursor. + contentResolverCursor.close(); + } + + // Save the final file name string so it can be used inside the lambdas. This will no longer be needed once this activity has transitioned to Kotlin. + String finalFileNameString = temporaryFileNameString; + try { // Create a temporary MHT file. File temporaryMhtFile = File.createTempFile("temporary_mht_file", ".mht", getCacheDir()); - - // Save the temporary MHT file. currentWebView.saveWebArchive(temporaryMhtFile.toString(), false, callbackValue -> { if (callbackValue != null) { // The temporary MHT file was saved successfully. try { @@ -420,29 +439,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook mhtOutputStream.close(); temporaryMhtFileInputStream.close(); - // Initialize the file name string from the file URI last path segment. - String fileNameString = fileUri.getLastPathSegment(); - - // Query the exact file name if the API >= 26. - if (Build.VERSION.SDK_INT >= 26) { - // Get a cursor from the content resolver. - Cursor contentResolverCursor = resultLauncherActivityHandle.getContentResolver().query(fileUri, null, null, null); - - // Move to the fist row. - contentResolverCursor.moveToFirst(); - - // Get the file name from the cursor. - fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)); - - // Close the cursor. - contentResolverCursor.close(); - } - // Display a snackbar. - Snackbar.make(currentWebView, getString(R.string.file_saved) + " " + fileNameString, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(currentWebView, getString(R.string.saved, finalFileNameString), Snackbar.LENGTH_SHORT).show(); } catch (Exception exception) { // Display a snackbar with the exception. - Snackbar.make(currentWebView, getString(R.string.error_saving_file) + " " + exception, Snackbar.LENGTH_INDEFINITE).show(); + Snackbar.make(currentWebView, getString(R.string.error_saving_file, finalFileNameString, exception), Snackbar.LENGTH_INDEFINITE).show(); } finally { // Delete the temporary MHT file. //noinspection ResultOfMethodCallIgnored @@ -450,12 +451,12 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } } else { // There was an unspecified error while saving the temporary MHT file. // Display an error snackbar. - Snackbar.make(currentWebView, getString(R.string.error_saving_file), Snackbar.LENGTH_INDEFINITE).show(); + Snackbar.make(currentWebView, getString(R.string.error_saving_file, finalFileNameString, getString(R.string.unknown_error)), Snackbar.LENGTH_INDEFINITE).show(); } }); } catch (IOException ioException) { // Display a snackbar with the IO exception. - Snackbar.make(currentWebView, getString(R.string.error_saving_file) + " " + ioException, Snackbar.LENGTH_INDEFINITE).show(); + Snackbar.make(currentWebView, getString(R.string.error_saving_file, finalFileNameString, ioException), Snackbar.LENGTH_INDEFINITE).show(); } } } diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveAboutVersionImage.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveAboutVersionImage.java index 72be3512..49ae1d9f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveAboutVersionImage.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveAboutVersionImage.java @@ -163,9 +163,9 @@ public class SaveAboutVersionImage extends AsyncTask { // Display a file creation disposition snackbar. if (fileCreationDisposition.equals(SUCCESS)) { // Create a file saved snackbar. - Snackbar.make(aboutVersionLinearLayout, activity.getString(R.string.file_saved) + " " + fileNameString, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(aboutVersionLinearLayout, activity.getString(R.string.saved, fileNameString), Snackbar.LENGTH_SHORT).show(); } else { - Snackbar.make(aboutVersionLinearLayout, activity.getString(R.string.error_saving_file) + " " + fileCreationDisposition, Snackbar.LENGTH_INDEFINITE).show(); + Snackbar.make(aboutVersionLinearLayout, activity.getString(R.string.error_saving_file, fileNameString, fileCreationDisposition), Snackbar.LENGTH_INDEFINITE).show(); } } } 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 34fefc47..029929dd 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveUrl.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveUrl.java @@ -279,10 +279,10 @@ 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) + " " + fileNameString, Snackbar.LENGTH_LONG).show(); + Snackbar.make(noSwipeViewPager, activity.getString(R.string.saved, fileNameString), 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(); + Snackbar.make(noSwipeViewPager, activity.getString(R.string.error_saving_file, fileNameString, 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 e18fbd9c..5a92123a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveWebpageImage.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/SaveWebpageImage.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019-2022 Soren Stoutner . + * Copyright0 2019-2022 Soren Stoutner . * * This file is part of Privacy Browser Android . * @@ -159,10 +159,10 @@ public class SaveWebpageImage extends AsyncTask { // Display a file creation disposition snackbar. if (fileCreationDisposition.equals(SUCCESS)) { // Display the image saved snackbar. - Snackbar.make(nestedScrollWebView, activity.getString(R.string.image_saved) + " " + fileNameString, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(nestedScrollWebView, activity.getString(R.string.saved, fileNameString), 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(); + Snackbar.make(nestedScrollWebView, activity.getString(R.string.error_saving_file, fileNameString, fileCreationDisposition), Snackbar.LENGTH_INDEFINITE).show(); } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt index e5d0c543..f4b673ea 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt @@ -163,6 +163,24 @@ class AboutVersionFragment : Fragment() { private val saveAboutVersionTextActivityResultLauncher = registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) { fileUri: Uri? -> // Only save the file if the URI is not null, which happens if the user exited the file picker by pressing back. if (fileUri != null) { + // Initialize the file name string from the file URI last path segment. + var fileNameString = fileUri.lastPathSegment + + // Query the exact file name if the API >= 26. + if (Build.VERSION.SDK_INT >= 26) { + // Get a cursor from the content resolver. + val contentResolverCursor = requireActivity().contentResolver.query(fileUri, null, null, null)!! + + // Move to the first row. + contentResolverCursor.moveToFirst() + + // Get the file name from the cursor. + fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)) + + // Close the cursor. + contentResolverCursor.close() + } + try { // Get the about version string. val aboutVersionString = getAboutVersionString() @@ -181,29 +199,11 @@ class AboutVersionFragment : Fragment() { } } - // Initialize the file name string from the file URI last path segment. - var fileNameString = fileUri.lastPathSegment - - // Query the exact file name if the API >= 26. - if (Build.VERSION.SDK_INT >= 26) { - // Get a cursor from the content resolver. - val contentResolverCursor = requireActivity().contentResolver.query(fileUri, null, null, null)!! - - // Move to the first row. - contentResolverCursor.moveToFirst() - - // Get the file name from the cursor. - fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)) - - // Close the cursor. - contentResolverCursor.close() - } - // Display a snackbar with the saved logcat information. Snackbar.make(aboutVersionLayout, getString(R.string.saved, fileNameString), Snackbar.LENGTH_SHORT).show() } catch (exception: Exception) { // Display a snackbar with the error message. - Snackbar.make(aboutVersionLayout, getString(R.string.error_saving_file, exception.toString()), Snackbar.LENGTH_INDEFINITE).show() + Snackbar.make(aboutVersionLayout, getString(R.string.error_saving_file, fileNameString, exception.toString()), 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 d331954c..f0e0c5eb 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -204,10 +204,7 @@ Unbekannte Größe Ungültige URL Speichere Datei: - Datei gespeichert: Bild wird bearbeitet… : - Bild gespeichert: - Fehler beim Speichern der Datei: \u0020 %1$sFf Anfragekopfzeilen @@ -569,7 +566,6 @@ Herunterziehen zum Aktualisieren Einige Websites funktionieren nicht, wenn "Herunterziehen zum Aktualisieren" eingeschaltet ist. Mit einer externen App herunterladen - Eine externe App verwenden, um Dateien herunterzuladen. App-Leiste scrollen Scrollt die App-Leiste mit der URL nach oben, wenn die Webseite gescrollt wird. Untere Anwendungs-Leiste diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index df943b88..a304733f 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -200,10 +200,7 @@ Tamaño desconocido URL inválida Guardando archivo: - Archivo guardado: Procesando imagen… : - Imagen guardada: - Error guardando archivo: \u0020 %1$s Cabeceras de solicitud @@ -568,7 +565,6 @@ Deslizar para actualizar Algunas webs no funcionan bien si la opción deslizar para actualizar está habilitada. Descargar con una app externa - Use una app externa para descargar archivos. Desplazar la barra de aplicaciones Desplazar la barra de aplicaciones desde la parte superior de la pantalla cuando el WebView se desplaza hacia abajo. Barra inferior de la app diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 45b1f334..5f9cdc6f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -201,10 +201,7 @@ taille inconnue URL invalide Enregistrement du fichier : - Fichier enregistré : Traitement de l\'image… : - Image sauvegardée : - Erreur lors de l\'enregistrement du fichier : \u0020 %1$s En-tête de la requête @@ -565,7 +562,6 @@ Glisser pour rafraîchir Certains sites Web ne fonctionnent pas bien lorsque "Glisser pour rafraîchir" est activé. Téléchargement avec une app externe - Utiliser une application externe pour télécharger des fichiers. Barre d\'application en bas Déplacer la barre d\'application vers le bas de l\'écran. La modification de ce paramètre entraîne le redémarrage de Privacy Browser. Défilement barre d\'applications diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index f89a1962..d601ddbf 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -200,10 +200,7 @@ Dimensione sconosciuta URL non valida Salvataggio file: - File salvato: Creazione immagine… : - Immagine salvata: - Errore salvataggio file: \u0020 %1$s Richiesta Intestazioni @@ -567,7 +564,6 @@ Swipe per aggiornare Alcuni siti non funzionano correttamente se questa opzione è abilitata. Scarica con una applicazione esterna - Utilizza una applicazione esterna per scaricare i file. Permetti lo scrolling della barra dell\'applicazione Permette lo scorrere della barra dell\'applicazione dalla parte alta dello schermo quando si effettua lo scrolling. Barra dell\'app in basso diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 387aed8e..4dac8dc4 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -198,10 +198,7 @@ tamanho desconhecido URL inválida Salvando file: - Arquivo Salvo: Processando imagem… : - Image saved: - Erro ao salvar o arquivo: \u0020 %1$s Solicitar cabeçalhos @@ -558,7 +555,6 @@ Deslize para atualizar Alguns sites não funcionam bem se deslizar para atualizar estiver habilitado. Download com aplicativo externo - Usar um aplicativo externo para baixar arquivos. Role a barra de aplicativos Role a barra de aplicativos para fora da parte superior da tela quando o WebView rola para baixo. Barra de aplicativos inferior diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 1cfa2fbf..3afebf9e 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -197,10 +197,7 @@ неизвестный размер неправильный URL Сохранение файла: - Файл сохранен: Обработка изображения… : - Изображение сохранено: - Ошибка сохранения файла: \u0020 %1$s Заголовки запроса @@ -563,7 +560,6 @@ Потянуть для обновления Некоторые веб-сайты могут работать некорректно при включении данной опции. Загрузка во внешнем приложении - Использовать внешнее приложение для загрузки файлов. Прокручивать панель приложения Прокручивает панель приложения вверху экрана при прокрутке WebView вниз. Нижняя панель приложения diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 14d73897..1e30a7a8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -207,10 +207,10 @@ unknown size invalid URL Saving file: - File saved: + %1$s saved. Processing image… : - Image saved: - Error saving file: \u0020 %1$s + Error saving %1$s: \u0020 %2$s --> + Unknown error Request Headers @@ -380,7 +380,6 @@ Clear Logcat copied. Privacy Browser %1$s Logcat.txt - %1$s saved. Error saving logcat: \u0020 %1$s @@ -619,7 +618,8 @@ Swipe to refresh Some websites don’t work well if swipe to refresh is enabled. Download with external app - Use an external app to download files. + External apps will not honor Privacy Browser’s proxy settings and will not have access to cookies + (meaning that it is unlikely that files downloaded from sites that require a login will work). Scroll the app bar Scroll the app bar off the top of the screen when the WebView scrolls down. Bottom app bar -- 2.45.2