Add an option to block all third-party requests. https://redmine.stoutner.com/issues/209
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / SettingsFragment.java
index aac9b0d357a73f5ea5f1a473b3a8df1b23971926..19fa1e3a9190a9fdff4a581537ca1a1c20df8bd6 100644 (file)
@@ -51,7 +51,7 @@ public class SettingsFragment extends PreferenceFragment {
         // Initialize savedPreferences.
         savedPreferences = getPreferenceScreen().getSharedPreferences();
 
-        // Get handles for the preferences we need to modify.
+        // Get handles for the preferences.
         final Preference javaScriptPreference = findPreference("javascript_enabled");
         final Preference firstPartyCookiesPreference = findPreference("first_party_cookies_enabled");
         final Preference thirdPartyCookiesPreference = findPreference("third_party_cookies_enabled");
@@ -66,6 +66,7 @@ public class SettingsFragment extends PreferenceFragment {
         final Preference easyPrivacyPreference = findPreference("easyprivacy");
         final Preference fanboyAnnoyanceListPreference = findPreference("fanboy_annoyance_list");
         final Preference fanboySocialBlockingListPreference = findPreference("fanboy_social_blocking_list");
+        final Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
         final Preference proxyThroughOrbotPreference = findPreference("proxy_through_orbot");
         final Preference torHomepagePreference = findPreference("tor_homepage");
         final Preference torSearchPreference = findPreference("tor_search");
@@ -423,6 +424,21 @@ public class SettingsFragment extends PreferenceFragment {
             }
         }
 
+        // Set the block all third-party requests icon.
+        if (savedPreferences.getBoolean("block_all_third_party_requests", false)) {
+            if (MainWebViewActivity.darkTheme) {
+                blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_dark);
+            } else {
+                blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_light);
+            }
+        } else {
+            if (MainWebViewActivity.darkTheme) {
+                blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_dark);
+            } else {
+                blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_light);
+            }
+        }
+
         // Set the Tor icons according to the theme.
         if (proxyThroughOrbot) {  // Proxying is enabled.
             if (MainWebViewActivity.darkTheme) {
@@ -1003,6 +1019,23 @@ public class SettingsFragment extends PreferenceFragment {
                     }
                     break;
 
+                case "block_all_third_party_requests":
+                    // Update the icon.
+                    if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
+                        if (MainWebViewActivity.darkTheme) {
+                            blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_dark);
+                        } else {
+                            blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_light);
+                        }
+                    } else {
+                        if (MainWebViewActivity.darkTheme) {
+                            blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_dark);
+                        } else {
+                            blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_light);
+                        }
+                    }
+                    break;
+
                 case "proxy_through_orbot":
                     // Get current settings.
                     boolean currentProxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false);