]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/dialogs/UrlHistoryDialog.java
Make first-party cookies tab aware.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / UrlHistoryDialog.java
index 0fe8afaa94e2e5d4078b1fae54e79d4896903204..13b8c3311e49b4233b540b1a379682b06e0fa3e4 100644 (file)
@@ -24,11 +24,13 @@ import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
 import android.util.Base64;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -42,7 +44,6 @@ import androidx.core.content.ContextCompat;
 import androidx.fragment.app.DialogFragment;  // The AndroidX dialog fragment must be used or an error is produced on API <=22.
 
 import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
 import com.stoutner.privacybrowser.adapters.HistoryArrayAdapter;
 import com.stoutner.privacybrowser.definitions.History;
 
@@ -50,11 +51,36 @@ import java.io.ByteArrayOutputStream;
 import java.util.ArrayList;
 
 public class UrlHistoryDialog extends DialogFragment{
-
-    // `historyArrayList`  and `currentPageId` pass information from `onCreate()` to `onCreateDialog()`.
+    // Declare the class variables.
     private final ArrayList<History> historyArrayList = new ArrayList<>();
     private int currentPageId;
 
+    // Create a URL history listener.
+    private UrlHistoryListener urlHistoryListener;
+
+
+    // The public interface is used to send information back to the parent activity.
+    public interface UrlHistoryListener {
+        // Send back the number of steps to move forward or back.
+        void onUrlHistoryEntrySelected(int moveBackOrForwardSteps);
+
+        // Clear the history.
+        void onClearHistory();
+    }
+
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+
+        // Check to make sure tha the parent activity implements the listener.
+        try {
+            urlHistoryListener = (UrlHistoryListener) context;
+        } catch (ClassCastException exception) {
+            throw new ClassCastException(context.toString() + " must implement UrlHistoryListener.");
+        }
+    }
+
+
     public static UrlHistoryDialog loadBackForwardList(Context context, WebBackForwardList webBackForwardList) {
         // Create an arguments bundle.
         Bundle argumentsBundle = new Bundle();
@@ -161,30 +187,6 @@ public class UrlHistoryDialog extends DialogFragment{
         currentPageId = urlStringArrayList.size() - 1 - originalCurrentPageId;
     }
 
-    // The public interface is used to send information back to the parent activity.
-    public interface UrlHistoryListener {
-        // Send back the number of steps to move forward or back.
-        void onUrlHistoryEntrySelected(int moveBackOrForwardSteps);
-
-        // Clear the history.
-        void onClearHistory();
-    }
-
-    // `urlHistoryListener` is used in `onAttach()` and `onCreateDialog()`.
-    private UrlHistoryListener urlHistoryListener;
-
-    @Override
-    public void onAttach(Context context) {
-        super.onAttach(context);
-
-        // Check to make sure tha the parent activity implements the listener.
-        try {
-            urlHistoryListener = (UrlHistoryListener) context;
-        } catch (ClassCastException exception) {
-            throw new ClassCastException(context.toString() + " must implement UrlHistoryListener.");
-        }
-    }
-
     @Override
     @NonNull
     // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
@@ -199,8 +201,15 @@ public class UrlHistoryDialog extends DialogFragment{
         // Use an alert dialog builder to create the alert dialog.
         AlertDialog.Builder dialogBuilder;
 
+        // Get a handle for the shared preferences.
+        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+        // Get the screenshot and theme preferences.
+        boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+        boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
         // Set the style according to the theme.
-        if (MainWebViewActivity.darkTheme) {
+        if (darkTheme) {
             dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
         } else {
             dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
@@ -227,7 +236,7 @@ public class UrlHistoryDialog extends DialogFragment{
         final AlertDialog alertDialog = dialogBuilder.create();
 
         // Disable screenshots if not allowed.
-        if (!MainWebViewActivity.allowScreenshots) {
+        if (!allowScreenshots) {
             // Remove the warning below that `getWindow()` might be null.
             assert alertDialog.getWindow() != null;