]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/dialogs/HttpAuthenticationDialog.kt
Fix a crash when opening a drawer while restarting. https://redmine.stoutner.com...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / HttpAuthenticationDialog.kt
index 0e8a08db715a5dd60ae8c71593a5527434b4fc57..c53c92fab5bc3d3fbb8056a51cb0c494d90402dd 100644 (file)
@@ -19,7 +19,6 @@
 
 package com.stoutner.privacybrowser.dialogs
 
-import android.annotation.SuppressLint
 import android.app.Dialog
 import android.content.DialogInterface
 import android.content.res.Configuration
@@ -78,8 +77,6 @@ class HttpAuthenticationDialog : DialogFragment() {
         }
     }
 
-    // `@SuppressLint("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
-    @SuppressLint("InflateParams")
     override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
         // Get a handle for the arguments.
         val arguments = requireArguments()
@@ -115,23 +112,24 @@ class HttpAuthenticationDialog : DialogFragment() {
             // Set the title.
             dialogBuilder.setTitle(R.string.http_authentication)
 
-            // Set the view.  The parent view is `null` because it will be assigned by the alert dialog.
-            dialogBuilder.setView(layoutInflater.inflate(R.layout.http_authentication_dialog, null))
+            // Set the view.
+            dialogBuilder.setView(R.layout.http_authentication_dialog)
 
             // Set the close button listener.
             dialogBuilder.setNegativeButton(R.string.close) { _: DialogInterface?, _: Int ->
-                // Cancel the HTTP authentication request.
-                httpAuthHandler.cancel()
+                if (httpAuthHandler != null) {
+                    // Cancel the HTTP authentication request.
+                    httpAuthHandler.cancel()
 
-                // Reset the HTTP authentication handler.
-                nestedScrollWebView.resetHttpAuthHandler()
-            }// Set the proceed button listener.
+                    // Reset the HTTP authentication handler.
+                    nestedScrollWebView.resetHttpAuthHandler()
+                }
+            }
+
+            // Set the proceed button listener.
             dialogBuilder.setPositiveButton(R.string.proceed) { _: DialogInterface?, _: Int ->
                 // Send the login information
-                login(httpAuthHandler)
-
-                // Reset the HTTP authentication handler.
-                nestedScrollWebView.resetHttpAuthHandler()
+                login(httpAuthHandler, nestedScrollWebView)
             }
 
             // Create an alert dialog from the alert dialog builder.
@@ -193,7 +191,7 @@ class HttpAuthenticationDialog : DialogFragment() {
                 // Check the key code and event.
                 if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN) {  // The enter key was pressed.
                     // Send the login information.
-                    login(httpAuthHandler)
+                    login(httpAuthHandler, nestedScrollWebView)
 
                     // Manually dismiss the alert dialog.
                     alertDialog.dismiss()
@@ -210,7 +208,7 @@ class HttpAuthenticationDialog : DialogFragment() {
                 // Check the key code and event.
                 if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN) {  // The enter key was pressed.
                     // Send the login information.
-                    login(httpAuthHandler)
+                    login(httpAuthHandler, nestedScrollWebView)
 
                     // Manually dismiss the alert dialog.
                     alertDialog.dismiss()
@@ -249,8 +247,13 @@ class HttpAuthenticationDialog : DialogFragment() {
         }
     }
 
-    private fun login(httpAuthHandler: HttpAuthHandler) {
-        // Send the login information.
-        httpAuthHandler.proceed(usernameEditText.text.toString(), passwordEditText.text.toString())
+    private fun login(httpAuthHandler: HttpAuthHandler?, nestedScrollWebView: NestedScrollWebView) {
+        if (httpAuthHandler != null) {
+            // Send the login information.
+            httpAuthHandler.proceed(usernameEditText.text.toString(), passwordEditText.text.toString())
+
+            // Reset the HTTP authentication handler.
+            nestedScrollWebView.resetHttpAuthHandler()
+        }
     }
 }
\ No newline at end of file