X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FSslCertificateErrorDialog.kt;h=d146de5300c77c364ce7695e148d18e087561f54;hp=e44e8026bf29e325985d5f55047f8f63eda8ccfa;hb=1b27ac6f2b7c046945fc97e2aff9adbde8a152ce;hpb=aa121d6d6df14a0425ac3b5603765dbae7e8d156 diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateErrorDialog.kt b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateErrorDialog.kt index e44e8026..d146de53 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateErrorDialog.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SslCertificateErrorDialog.kt @@ -1,29 +1,27 @@ /* - * Copyright © 2016-2021 Soren Stoutner . + * Copyright © 2016-2022 Soren Stoutner . * - * This file is part of Privacy Browser . + * This file is part of Privacy Browser Android . * - * Privacy Browser is free software: you can redistribute it and/or modify + * Privacy Browser Android is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * Privacy Browser is distributed in the hope that it will be useful, + * Privacy Browser Android is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser. If not, see . + * along with Privacy Browser Android. If not, see . */ package com.stoutner.privacybrowser.dialogs -import android.annotation.SuppressLint import android.app.Activity import android.app.Dialog import android.content.DialogInterface -import android.content.res.Configuration import android.net.Uri import android.net.http.SslError import android.os.AsyncTask @@ -105,8 +103,6 @@ class SslCertificateErrorDialog : DialogFragment() { } } - // `@SuppressLint("InflateParams")` removes the warning about using `null` as the parent view group when inflating the alert dialog. - @SuppressLint("InflateParams") override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { // Get the variables from the bundle. val primaryErrorInt = requireArguments().getInt(PRIMARY_ERROR_INT) @@ -139,17 +135,14 @@ class SslCertificateErrorDialog : DialogFragment() { // Use an alert dialog builder to create the alert dialog. val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.PrivacyBrowserAlertDialog) - // Get the current theme status. - val currentThemeStatus = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - - // Set the icon according to the theme. - dialogBuilder.setIconAttribute(R.attr.sslCertificateBlueIcon) + // Set the icon. + dialogBuilder.setIcon(R.drawable.ssl_certificate_enabled) // Set the title. dialogBuilder.setTitle(R.string.ssl_certificate_error) - // Set the view. The parent view is null because it will be assigned by the alert dialog. - dialogBuilder.setView(layoutInflater.inflate(R.layout.ssl_certificate_error, null)) + // Set the view. + dialogBuilder.setView(R.layout.ssl_certificate_error) // Set the cancel button listener. dialogBuilder.setNegativeButton(R.string.cancel) { _: DialogInterface?, _: Int -> @@ -179,7 +172,7 @@ class SslCertificateErrorDialog : DialogFragment() { val alertDialog = dialogBuilder.create() // Get a handle for the shared preferences. - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) // Get the screenshot preference. val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false) @@ -233,21 +226,8 @@ class SslCertificateErrorDialog : DialogFragment() { val endDateStringBuilder = SpannableStringBuilder(endDateLabel + endDate) // Define the color spans. - val blueColorSpan: ForegroundColorSpan - val redColorSpan: ForegroundColorSpan - - // Set the color spans according to the theme. The deprecated `getColor()` must be used until the minimum API >= 23. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - @Suppress("DEPRECATION") - blueColorSpan = ForegroundColorSpan(resources.getColor(R.color.blue_700)) - @Suppress("DEPRECATION") - redColorSpan = ForegroundColorSpan(resources.getColor(R.color.red_a700)) - } else { - @Suppress("DEPRECATION") - blueColorSpan = ForegroundColorSpan(resources.getColor(R.color.violet_700)) - @Suppress("DEPRECATION") - redColorSpan = ForegroundColorSpan(resources.getColor(R.color.red_900)) - } + val blueColorSpan = ForegroundColorSpan(requireContext().getColor(R.color.blue_text)) + val redColorSpan = ForegroundColorSpan(requireContext().getColor(R.color.red_text)) // Setup the spans to display the certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction. urlStringBuilder.setSpan(blueColorSpan, urlLabel.length, urlStringBuilder.length, Spanned.SPAN_INCLUSIVE_INCLUSIVE) @@ -275,14 +255,8 @@ class SslCertificateErrorDialog : DialogFragment() { } SslError.SSL_UNTRUSTED -> { - // Change the issued by text view text to red. The deprecated `getColor()` must be used until the minimum API >= 23. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - @Suppress("DEPRECATION") - issuedByTextView.setTextColor(resources.getColor(R.color.red_a700)) - } else { - @Suppress("DEPRECATION") - issuedByTextView.setTextColor(resources.getColor(R.color.red_900)) - } + // Change the issued by text view text to red. + issuedByTextView.setTextColor(requireContext().getColor(R.color.red_text)) // Change the issued by span color to red. issuedByCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length, issuedByCNameStringBuilder.length, Spanned.SPAN_INCLUSIVE_INCLUSIVE) @@ -294,14 +268,8 @@ class SslCertificateErrorDialog : DialogFragment() { } SslError.SSL_DATE_INVALID -> { - // Change the valid dates text view text to red. The deprecated `getColor()` must be used until the minimum API >= 23. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - @Suppress("DEPRECATION") - validDatesTextView.setTextColor(resources.getColor(R.color.red_a700)) - } else { - @Suppress("DEPRECATION") - validDatesTextView.setTextColor(resources.getColor(R.color.red_900)) - } + // Change the valid dates text view text to red. + validDatesTextView.setTextColor(requireContext().getColor(R.color.red_text)) // Change the date span colors to red. startDateStringBuilder.setSpan(redColorSpan, startDateLabel.length, startDateStringBuilder.length, Spanned.SPAN_INCLUSIVE_INCLUSIVE) @@ -393,20 +361,8 @@ class SslCertificateErrorDialog : DialogFragment() { // Create a spannable string builder. val ipAddressesStringBuilder = SpannableStringBuilder(ipAddressesLabel + ipAddresses) - // Create a blue foreground color span. - val blueColorSpan: ForegroundColorSpan - - // Get the current theme status. - val currentThemeStatus = activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - - // Set the blue color span according to the theme. The deprecated `getColor()` must be used until the minimum API >= 23. - blueColorSpan = if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - @Suppress("DEPRECATION") - ForegroundColorSpan(activity.resources.getColor(R.color.blue_700)) - } else { - @Suppress("DEPRECATION") - ForegroundColorSpan(activity.resources.getColor(R.color.violet_500)) - } + // Create a blue color span according to the theme. + val blueColorSpan = ForegroundColorSpan(activity.getColor(R.color.blue_text)) // Set the string builder to display the certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction. ipAddressesStringBuilder.setSpan(blueColorSpan, ipAddressesLabel.length, ipAddressesStringBuilder.length, Spanned.SPAN_INCLUSIVE_INCLUSIVE)