val httpAuthHandler = nestedScrollWebView.httpAuthHandler
// Use an alert dialog builder to create the alert dialog.
- val dialogBuilder = AlertDialog.Builder(requireActivity(), R.style.PrivacyBrowserAlertDialog)
+ val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.PrivacyBrowserAlertDialog)
// Set the icon according to the theme.
dialogBuilder.setIconAttribute(R.attr.lockBlueIcon)
// 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.
// Get the current theme status.
val currentThemeStatus = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
- // Create a blue foreground color span.
- val blueColorSpan: ForegroundColorSpan
-
// Set the blue color span according to the theme. The deprecated `getColor()` must be used until API >= 23.
- blueColorSpan = if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ val blueColorSpan = if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
@Suppress("DEPRECATION")
ForegroundColorSpan(resources.getColor(R.color.blue_700))
} else {
// 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()
// 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()
return alertDialog
} catch (exception: Exception) { // Privacy Browser was restarted and the HTTP auth handler no longer exists.
// Use an alert dialog builder to create an empty alert dialog.
- val dialogBuilder = AlertDialog.Builder(requireActivity(), R.style.PrivacyBrowserAlertDialog)
+ val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.PrivacyBrowserAlertDialog)
// Create an empty alert dialog from the alert dialog builder.
val alertDialog = dialogBuilder.create()
}
override fun onResume() {
- // Run the default command.
+ // Run the default commands.
super.onResume()
// Dismiss the alert dialog if the activity was restarted and the HTTP auth handler no longer exists.
}
}
- 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