From 74e8a8368db991ee511c216a298c4ff5201f41de Mon Sep 17 00:00:00 2001
From: Soren Stoutner <soren@stoutner.com>
Date: Wed, 27 Mar 2024 16:10:48 -0700
Subject: [PATCH] Fix displaying HTTP Authentication dialogs crashing when the
 app has been stopped.  https://redmine.stoutner.com/issues/1178

---
 .../activities/MainWebViewActivity.kt         | 12 +++++++---
 app/src/main/res/values-de/strings.xml        |  1 -
 app/src/main/res/values-es/strings.xml        | 22 ++++++++++++++++++-
 app/src/main/res/values-fr/strings.xml        |  1 -
 app/src/main/res/values-it/strings.xml        | 22 ++++++++++++++++++-
 app/src/main/res/values-pt-rBR/strings.xml    |  1 -
 app/src/main/res/values-ru/strings.xml        | 22 ++++++++++++++++++-
 app/src/main/res/values-zh-rCN/strings.xml    |  1 -
 8 files changed, 72 insertions(+), 10 deletions(-)

diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt
index b56a02f0..75aa38be 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt
+++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt
@@ -5455,8 +5455,14 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                 // Instantiate an HTTP authentication dialog.
                 val httpAuthenticationDialogFragment = HttpAuthenticationDialog.displayDialog(host, realm, nestedScrollWebView.webViewFragmentId)
 
-                // Show the HTTP authentication dialog.
-                httpAuthenticationDialogFragment.show(supportFragmentManager, getString(R.string.http_authentication))
+                // Try to show the dialog.  WebView can receive an HTTP authentication request even after the app has been paused.  Attempting to display a dialog in that state leads to a crash.
+                try {
+                    // Show the HTTP authentication dialog.
+                    httpAuthenticationDialogFragment.show(supportFragmentManager, getString(R.string.http_authentication))
+                } catch (exception: Exception) {  // The dialog could not be shown.
+                    // Add the dialog to the pending dialog array list.  It will be displayed in `onStart()`.
+                    pendingDialogsArrayList.add(PendingDialogDataClass(httpAuthenticationDialogFragment, getString(R.string.http_authentication)))
+                }
             }
 
             override fun onPageStarted(webView: WebView, url: String, favicon: Bitmap?) {
@@ -5694,7 +5700,7 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                     // Instantiate an SSL certificate error alert dialog.
                     val sslCertificateErrorDialogFragment = SslCertificateErrorDialog.displayDialog(error, nestedScrollWebView.webViewFragmentId)
 
-                    // Try to show the dialog.  The SSL error handler continues to function even when the WebView is paused.  Attempting to display a dialog in that state leads to a crash.
+                    // Try to show the dialog.  The SSL error handler continues to function even when the app has been stopped.  Attempting to display a dialog in that state leads to a crash.
                     try {
                         // Show the SSL certificate error dialog.
                         sslCertificateErrorDialogFragment.show(supportFragmentManager, getString(R.string.ssl_certificate_error))
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 0830c64b..614b620b 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -643,7 +643,6 @@
         <string name="open_intents_in_new_tab_summary">Intents sind Links, die von anderen Apps übergeben werden.</string>
         <string name="swipe_to_refresh">Herunterziehen zum Aktualisieren</string>
         <string name="swipe_to_refresh_summary">Einige Websites funktionieren nicht, wenn "Herunterziehen zum Aktualisieren" eingeschaltet ist.</string>
-        <string name="download_with_external_app">Mit einer externen App herunterladen</string>
         <string name="scroll_app_bar">App-Leiste scrollen</string>
         <string name="scroll_app_bar_summary">Scrollt die App-Leiste mit der URL nach oben, wenn die Webseite gescrollt wird.</string>
         <string name="bottom_app_bar">Untere Anwendungs-Leiste</string>
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index c8dec3c7..98c7c554 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -203,6 +203,12 @@
     <string name="bytes">bytes</string>
     <string name="unknown_size">Tamaño desconocido</string>
     <string name="invalid_url">URL inválida</string>
+    <string name="blob_url_warning">Actualmente Navegador privado no puede descargar URLs de blobs.</string>
+    <string name="data_url_warning">El gestor de descargas de Android no puede gestionar las URLs de datos.</string>
+    <string name="download_directory">Directorio de descargas</string>
+    <string name="documents">Documentos</string>
+    <string name="pictures">Imágenes</string>
+    <string name="music">Música</string>
     <string name="saving_file">Guardando archivo:\u0020 %1$d%% - %2$s</string>
     <string name="saving_file_progress">Guardando archivo:\u0020 %1$s bytes - %2$s</string>
     <string name="saving_file_percentage_progress">Guardando archivo:\u0020 %1$d%% - %2$s bytes / %3$s bytes - %4$s</string>
@@ -254,6 +260,8 @@
     <string name="create_folder">Crear carpeta</string>
     <string name="current_bookmark_icon">Icono de favorito actual</string>
     <string name="current_folder_icon">Icono de carpeta actual</string>
+    <string name="custom_bookmark_icon">Icono de favorito personalizado</string>
+    <string name="custom_folder_icon">Icono de carpeta personalizado</string>
     <string name="default_folder_icon">Icono de carpeta por defecto</string>
     <string name="webpage_favorite_icon">Icono favorito de página Web</string>
     <string name="bookmark_name">Nombre de favorito</string>
@@ -263,6 +271,7 @@
     <string name="edit_folder">Editar carpeta</string>
     <string name="move_to_folder">Mover a carpeta</string>
     <string name="move">Mover</string>
+    <string name="cannot_use_svg">Actualmente no puede usarse un SVG como icono preferido de un favorito.</string>
 
     <!-- Bookmarks Contextual App Bar.  Android removes double spaces, but extra spaces can be manually specified with the Unicode `\u0020` formatting.
         The `%1$d` code inserts variables into the displayed text and should be preserved in translation.  <https://developer.android.com/reference/kotlin/java/util/Formatter> -->
@@ -646,7 +655,18 @@
         <string name="open_intents_in_new_tab_summary">Los contenidos son enlaces enviados desde otras apps.</string>
         <string name="swipe_to_refresh">Deslizar para actualizar</string>
         <string name="swipe_to_refresh_summary">Algunas webs no funcionan bien si la opción deslizar para actualizar está habilitada.</string>
-        <string name="download_with_external_app">Descargar con una app externa</string>
+        <string name="download_provider">Proveedor de descargas</string>
+        <string-array name="download_provider_entries">
+            <item>Navegador Privado</item>
+            <item>Gestor de descargas de Android</item>
+            <item>Aplicación externa</item>
+        </string-array>
+        <string name="download_with_privacy_browser">Navegador Privado - El descargador integrado de Navegador Privado es sencillo, pero tiene la ventaja de respetar el proxy y usar cookies (si están habilitadas),
+            así como la posibilidad de guardar datos: URLs.</string>
+        <string name="download_with_android_download_manager">Gestor de descargas de Android  - El gestor de descargas de Android no respeta la configuración proxy de Navegador Privado,
+            pero sí tiene acceso a las cookies (lo que significa que los archivos descargados de sitios que requieren hacer login probablemente funcionarán).</string>
+        <string name="download_with_external_app">Aplicación externa - Las aplicaciones externas no respetan  la configuración proxy de Navegador Privado y no tienen acceso a las cookies
+            (lo que significa que es poco probable que funcionen los archivos descargados de sitios que requieren hacer login).</string>
         <string name="scroll_app_bar">Desplazar la barra de aplicaciones</string>
         <string name="scroll_app_bar_summary">Desplazar la barra de aplicaciones desde la parte superior de la pantalla cuando el WebView se desplaza hacia abajo.</string>
         <string name="bottom_app_bar">Barra inferior de la app</string>
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index d9bd0976..ae6d75c1 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -643,7 +643,6 @@
         <string name="open_intents_in_new_tab_summary">Les intentions sont des liens envoyés à partir d\'autres applications.</string>
         <string name="swipe_to_refresh">Glisser pour rafraîchir</string>
         <string name="swipe_to_refresh_summary">Certains sites Web ne fonctionnent pas bien lorsque "Glisser pour rafraîchir" est activé.</string>
-        <string name="download_with_external_app">Téléchargement avec une app externe</string>
         <string name="scroll_app_bar">Défilement barre d\'applications</string>
         <string name="scroll_app_bar_summary">Faites défiler la barre d\'applications en haut de l\'écran lorsque WebView défile vers le bas.</string>
         <string name="bottom_app_bar">Barre d\'application en bas</string>
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index e1bcff0f..07d8d8d3 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -203,6 +203,12 @@
     <string name="bytes">byte</string>
     <string name="unknown_size">Dimensione sconosciuta</string>
     <string name="invalid_url">URL non valida</string>
+    <string name="blob_url_warning">In questo momento Privacy Browser non può scaricare blob URL.</string>
+    <string name="data_url_warning">Il gestore dei download di Android non può gestire le URL dati.</string>
+    <string name="download_directory">Cartella dei Download</string>
+    <string name="documents">Documenti</string>
+    <string name="pictures">Immagini</string>
+    <string name="music">Musica</string>
     <string name="saving_file">Salvataggio file:\u0020 %1$d%% - %2$s</string>
     <string name="saving_file_progress">Salvataggio file:\u0020 %1$s byte - %2$s</string>
     <string name="saving_file_percentage_progress">Salvataggio file:\u0020 %1$d%% - %2$s byte / %3$s byte - %4$s</string>
@@ -253,6 +259,8 @@
     <string name="create_folder">Crea Cartella</string>
     <string name="current_bookmark_icon">Icona Segnalibro</string>
     <string name="current_folder_icon">Icona Cartella</string>
+    <string name="custom_bookmark_icon">Icona segnalibro personalizzata</string>
+    <string name="custom_folder_icon">Icona cartella personalizzata</string>
     <string name="default_folder_icon">Icona predefinita cartella</string>
     <string name="webpage_favorite_icon">Icona preferita pagina web</string>
     <string name="bookmark_name">Nome Segnalibro</string>
@@ -262,6 +270,7 @@
     <string name="edit_folder">Modifica Cartella</string>
     <string name="move_to_folder">Sposta nella Cartella</string>
     <string name="move">Sposta</string>
+    <string name="cannot_use_svg">Al momento i file SVG non possono essere utilizzati come icona dei segnalibri.</string>
 
     <!-- Bookmarks Contextual App Bar.  Android removes double spaces, but extra spaces can be manually specified with the Unicode `\u0020` formatting.
         The `%1$d` code inserts variables into the displayed text and should be preserved in translation.  <https://developer.android.com/reference/kotlin/java/util/Formatter> -->
@@ -646,7 +655,18 @@
         <string name="open_intents_in_new_tab_summary">Gli intenti sono link inviati da altre app.</string>
         <string name="swipe_to_refresh">Swipe per aggiornare</string>
         <string name="swipe_to_refresh_summary">Alcuni siti non funzionano correttamente se questa opzione è abilitata.</string>
-        <string name="download_with_external_app">Scarica con una applicazione esterna</string>
+        <string name="download_provider">Provider dei Download</string>
+        <string-array name="download_provider_entries">
+            <item>Privacy Browser</item>
+            <item>Download manager di Android</item>
+            <item>Applicazione esterna</item>
+        </string-array>
+        <string name="download_with_privacy_browser">Privacy Browser - Il gestore dei download incluso in Privacy Browser è semplice ma ha il vantaggio di rispettare i proxy e di utilizzare i cookie (se abilitati),
+            oltre che la capacità di salvare le URL dati.</string>
+        <string name="download_with_android_download_manager">Gestore dei download di Android - Il gestore dei download di Android non rispetta le impostazioni dei proxy di Privacy Browser ma ha accesso ai cookies
+            (per cui i lo scaricamento di file da siti che richiedono il login probabilmente dovrebbe funzionare).</string>
+        <string name="download_with_external_app">Applicazione esterna - Le applicazioni esterne non rispettano le impostazioni dei proxy di Privacy Browser e non hanno accesso ai cookie
+            (per cui i lo scaricamento di file da siti che richiedono il login difficilmente funzionerà).</string>
         <string name="scroll_app_bar">Permetti lo scrolling della barra dell\'applicazione</string>
         <string name="scroll_app_bar_summary">Permette lo scorrere della barra dell\'applicazione dalla parte alta dello schermo quando si effettua lo scrolling.</string>
         <string name="bottom_app_bar">Barra dell\'app in basso</string>
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index d50014b7..cf80c4f4 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -529,7 +529,6 @@
         <string name="open_intents_in_new_tab_summary">Conteúdos são links enviados de outros aplicativos.</string>
         <string name="swipe_to_refresh">Deslize para atualizar</string>
         <string name="swipe_to_refresh_summary">Alguns sites não funcionam bem se deslizar para atualizar estiver habilitado.</string>
-        <string name="download_with_external_app">Download com aplicativo externo</string>
         <string name="scroll_app_bar">Role a barra de aplicativos</string>
         <string name="scroll_app_bar_summary">Role a barra de aplicativos para fora da parte superior da tela quando o WebView rola para baixo.</string>
         <string name="bottom_app_bar">Barra de aplicativos inferior</string>
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index 19b25cc6..ece18585 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -200,6 +200,12 @@
     <string name="bytes">байтов</string>
     <string name="unknown_size">неизвестный размер</string>
     <string name="invalid_url">неправильный URL</string>
+    <string name="blob_url_warning">В настоящее время Privacy Browser не может загружать blob URL.</string>
+    <string name="data_url_warning">Менеджер загрузок Android не может обрабатывать URL данных.</string>
+    <string name="download_directory">Каталог загрузки</string>
+    <string name="documents">Документы</string>
+    <string name="pictures">Изображения</string>
+    <string name="music">Музыка</string>
     <string name="saving_file">Сохранение файла:\u0020 %1$d%% - %2$s</string>
     <string name="saving_file_progress">Сохранение файла:\u0020 %1$s байтов - %2$s</string>
     <string name="saving_file_percentage_progress">Сохранение файла:\u0020 %1$d%% - %2$s байтов / %3$s байтов - %4$s</string>
@@ -250,6 +256,8 @@
     <string name="create_folder">Создание папки</string>
     <string name="current_bookmark_icon">Текущий значок закладки</string>
     <string name="current_folder_icon">Текущий значок папки</string>
+    <string name="custom_bookmark_icon">Настраиваемый значок закладки</string>
+    <string name="custom_folder_icon">Настраиваемый значок папки</string>
     <string name="default_folder_icon">Значок папки по умолчанию</string>
     <string name="webpage_favorite_icon">Значок избранной веб-страницы</string>
     <string name="bookmark_name">Имя закладки</string>
@@ -259,6 +267,7 @@
     <string name="edit_folder">Изменить папку</string>
     <string name="move_to_folder">Переместить в папку</string>
     <string name="move">Переместить</string>
+    <string name="cannot_use_svg">В настоящее время SVG нельзя использовать в качестве значка избранных закладок.</string>
 
     <!-- Bookmarks Contextual App Bar.  Android removes double spaces, but extra spaces can be manually specified with the Unicode `\u0020` formatting.
         The `%1$d` code inserts variables into the displayed text and should be preserved in translation.  <https://developer.android.com/reference/kotlin/java/util/Formatter> -->
@@ -642,7 +651,18 @@
         <string name="open_intents_in_new_tab_summary">Цели - это ссылки, отправленные из других приложений.</string>
         <string name="swipe_to_refresh">Потянуть для обновления</string>
         <string name="swipe_to_refresh_summary">Некоторые веб-сайты могут работать некорректно при включении данной опции.</string>
-        <string name="download_with_external_app">Загрузка во внешнем приложении</string>
+        <string name="download_provider">Провайдер загрузки</string>
+        <string-array name="download_provider_entries">
+            <item>Privacy Browser</item>
+            <item>Менеджер загрузок Android</item>
+            <item>Внешнее приложение</item>
+        </string-array>
+        <string name="download_with_privacy_browser">Privacy Browser - Встроенный загрузчик Privacy Browser прост, но его преимущество в том,
+            что он поддерживает прокси и использует cookie (если они включены), а также позволяет сохранять данные: URL.</string>
+        <string name="download_with_android_download_manager">Менеджер загрузки Android - менеджер загрузки Android не поддерживает настройки прокси Privacy Browser,
+            но у него есть доступ к файлам cookie (это означает, что файлы, загруженные с сайтов, требующих авторизации, будут работать).</string>
+        <string name="download_with_external_app">Внешнее приложение - внешние приложения не поддерживают настройки прокси Privacy Browser и не имеют доступа к файлам cookie
+            (это означает, что файлы, загруженные с сайтов, требующих авторизации, вряд ли будут работать).</string>
         <string name="scroll_app_bar">Прокручивать панель приложения</string>
         <string name="scroll_app_bar_summary">Прокручивает панель приложения вверху экрана при прокрутке WebView вниз.</string>
         <string name="bottom_app_bar">Нижняя панель приложения</string>
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 47c69780..441a17b3 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -531,7 +531,6 @@
         <string name="open_intents_in_new_tab_summary">把目标链接发送到其他应用</string>
         <string name="swipe_to_refresh">下拉刷新</string>
         <string name="swipe_to_refresh_summary">下拉刷新开启时部分网页不会工作</string>
-        <string name="download_with_external_app">由外部应用下载</string>
         <string name="scroll_app_bar">滚动应用栏</string>
         <string name="scroll_app_bar_summary">向下滚动网页时,隐藏顶部状态栏</string>
         <string name="bottom_app_bar">底部状态栏</string>
-- 
2.47.2