]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/dialogs/PinnedMismatchDialog.java
Fix applying domain settings when navigating history. https://redmine.stoutner.com...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / PinnedMismatchDialog.java
index fbc3293d5d072058c25de616e266aa8f10ec08c6..9694c0ac4d9db578ee0e122eeb5775071339bc83 100644 (file)
@@ -59,6 +59,11 @@ import androidx.fragment.app.DialogFragment;  // The AndroidX dialog fragment mu
 import androidx.viewpager.widget.PagerAdapter;
 
 public class PinnedMismatchDialog extends DialogFragment {
+    // The public interface is used to send information back to the parent activity.
+    public interface PinnedMismatchListener {
+        void pinnedErrorGoBack();
+    }
+
     // Declare the class variables.
     private PinnedMismatchListener pinnedMismatchListener;
     private NestedScrollWebView nestedScrollWebView;
@@ -71,19 +76,12 @@ public class PinnedMismatchDialog extends DialogFragment {
     private Date currentSslStartDate;
     private Date currentSslEndDate;
 
-    // The public interface is used to send information back to the parent activity.
-    public interface PinnedMismatchListener {
-        void onPinnedMismatchBack();
-
-        void onPinnedMismatchProceed();
-    }
-
-    // Check to make sure that the parent activity implements the listener.
+    @Override
     public void onAttach(Context context) {
         // Run the default commands.
         super.onAttach(context);
 
-        // Get a handle for `PinnedSslCertificateMismatchListener` from the launching context.
+        // Get a handle for the listener from the launching context.
         pinnedMismatchListener = (PinnedMismatchListener) context;
     }
 
@@ -225,16 +223,21 @@ public class PinnedMismatchDialog extends DialogFragment {
             }
         });
 
-        // Setup the negative button.
+        // Setup the back button.
         dialogBuilder.setNegativeButton(R.string.back, (DialogInterface dialog, int which) -> {
-            // Call the `onSslMismatchBack` public interface to send the `WebView` back one page.
-            pinnedMismatchListener.onPinnedMismatchBack();
+            if (nestedScrollWebView.canGoBack()) {  // There is a back page in the history.
+                // Invoke the navigate history listener in the calling activity.  These commands cannot be run here because they need access to `applyDomainSettings()`.
+                pinnedMismatchListener.pinnedErrorGoBack();
+            } else {  // There are no pages to go back to.
+                // Load a blank page
+                nestedScrollWebView.loadUrl("");
+            }
         });
 
-        // Setup the positive button.
+        // Setup the proceed button.
         dialogBuilder.setPositiveButton(R.string.proceed, (DialogInterface dialog, int which) -> {
-            // Call the `onSslMismatchProceed` public interface.
-            pinnedMismatchListener.onPinnedMismatchProceed();
+            // Do not check the pinned information for this domain again until the domain changes.
+            nestedScrollWebView.setIgnorePinnedDomainInformation(true);
         });
 
         // Set the title.
@@ -428,17 +431,15 @@ public class PinnedMismatchDialog extends DialogFragment {
             boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
 
             // Create a red foreground color span.  The deprecated `getResources().getColor` must be used until the minimum API >= 23.
-            @SuppressWarnings("deprecation") ForegroundColorSpan redColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.red_a700));
+            ForegroundColorSpan redColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.red_a700));
 
             // Create a blue foreground color span.
             ForegroundColorSpan blueColorSpan;
 
             // Set the blue color span according to the theme.  The deprecated `getResources().getColor` must be used until the minimum API >= 23.
             if (darkTheme) {
-                //noinspection deprecation
                 blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400));
             } else {
-                //noinspection deprecation
                 blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_700));
             }