X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FSettingsFragment.java;h=210018cbdb9a0e7d4679df5c09972340a10b8d30;hp=8e7a7112599974b504c1c3046fce6f2d773ee122;hb=4ecc3c256e439e7779d1db4d84800a6b2f9b13e6;hpb=337aebc73ea8d43fd912198e1eff9fe9f8f8f536 diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java index 8e7a7112..210018cb 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java @@ -42,7 +42,10 @@ public class SettingsFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { + // Run the default commands. super.onCreate(savedInstanceState); + + // Load the preferences from the XML file. addPreferencesFromResource(R.xml.preferences); // Get a handle for the context. @@ -51,7 +54,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 +69,8 @@ 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 ultraPrivacyPreference = findPreference("ultraprivacy"); + 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"); @@ -83,6 +88,7 @@ public class SettingsFragment extends PreferenceFragment { final Preference homepagePreference = findPreference("homepage"); final Preference defaultFontSizePreference = findPreference("default_font_size"); final Preference swipeToRefreshPreference = findPreference("swipe_to_refresh"); + final Preference downloadWithExternalAppPreference = findPreference("download_with_external_app"); final Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons"); final Preference darkThemePreference = findPreference("dark_theme"); final Preference nightModePreference = findPreference("night_mode"); @@ -94,8 +100,8 @@ public class SettingsFragment extends PreferenceFragment { hideSystemBarsPreference.setDependency("full_screen_browsing_mode"); // Get Strings from the preferences. - String torSearchString = savedPreferences.getString("tor_search", "https://3g2upl4pq6kufc4m.onion/html/?q="); - String searchString = savedPreferences.getString("search", "https://duckduckgo.com/html/?q="); + String torSearchString = savedPreferences.getString("tor_search", getString(R.string.tor_search_default_value)); + String searchString = savedPreferences.getString("search", getString(R.string.search_default_value)); // Get booleans that are used in multiple places from the preferences. final boolean javaScriptEnabled = savedPreferences.getBoolean("javascript_enabled", false); @@ -136,12 +142,12 @@ public class SettingsFragment extends PreferenceFragment { final WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview); // Get the user agent arrays. - ArrayAdapter userAgentNamesArray = ArrayAdapter.createFromResource(context, R.array.user_agent_names, R.layout.domain_settings_spinner_item); + ArrayAdapter userAgentNamesArray = ArrayAdapter.createFromResource(context, R.array.user_agent_names, R.layout.spinner_item); String[] translatedUserAgentNamesArray = getResources().getStringArray(R.array.translated_user_agent_names); String[] userAgentDataArray = getResources().getStringArray(R.array.user_agent_data); // Get the current user agent name from the preference. - String userAgentName = savedPreferences.getString("user_agent", "Privacy Browser"); + String userAgentName = savedPreferences.getString("user_agent", getString(R.string.user_agent_default_value)); // Get the array position of the user agent name. int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName); @@ -169,15 +175,15 @@ public class SettingsFragment extends PreferenceFragment { } // Set the summary text for the custom user agent preference and enable it if user agent preference is set to custom. - customUserAgentPreference.setSummary(savedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0")); + customUserAgentPreference.setSummary(savedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value))); customUserAgentPreference.setEnabled(userAgentPreference.getSummary().equals(getString(R.string.custom_user_agent))); - // Set the Tor homepage URL as the summary text for the `tor_homepage` preference when the preference screen is loaded. The default is DuckDuckGo: `https://3g2upl4pq6kufc4m.onion`. - torHomepagePreference.setSummary(savedPreferences.getString("tor_homepage", "https://3g2upl4pq6kufc4m.onion")); + // Set the Tor homepage URL as the summary text for the `tor_homepage` preference when the preference screen is loaded. The default is Searx: `http://ulrn6sryqaifefld.onion/`. + torHomepagePreference.setSummary(savedPreferences.getString("tor_homepage", getString(R.string.tor_homepage_default_value))); - // Set the Tor search URL as the summary text for the Tor preference when the preference screen is loaded. The default is `https://3g2upl4pq6kufc4m.onion/html/?q=` + // Set the Tor search URL as the summary text for the Tor preference when the preference screen is loaded. if (torSearchString.equals("Custom URL")) { // Use R.string.custom_url, which will be translated, instead of the array value, which will not. torSearchPreference.setSummary(R.string.custom_url); @@ -187,13 +193,13 @@ public class SettingsFragment extends PreferenceFragment { } // Set the summary text for `tor_search_custom_url`. The default is `""`. - torSearchCustomURLPreference.setSummary(savedPreferences.getString("tor_search_custom_url", "")); + torSearchCustomURLPreference.setSummary(savedPreferences.getString("tor_search_custom_url", getString(R.string.tor_search_custom_url_default_value))); // Enable the Tor custom URL search options only if proxying through Orbot and the search is set to `Custom URL`. torSearchCustomURLPreference.setEnabled(proxyThroughOrbot && torSearchString.equals("Custom URL")); - // Set the search URL as the summary text for the search preference when the preference screen is loaded. The default is `https://duckduckgo.com/html/?q=`. + // Set the search URL as the summary text for the search preference when the preference screen is loaded. if (searchString.equals("Custom URL")) { // Use R.string.custom_url, which will be translated, instead of the array value, which will not. searchPreference.setSummary(R.string.custom_url); @@ -203,7 +209,7 @@ public class SettingsFragment extends PreferenceFragment { } // Set the summary text for `search_custom_url` (the default is `""`) and enable it if `search` is set to `Custom URL`. - searchCustomURLPreference.setSummary(savedPreferences.getString("search_custom_url", "")); + searchCustomURLPreference.setSummary(savedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value))); searchCustomURLPreference.setEnabled(searchString.equals("Custom URL")); @@ -217,10 +223,10 @@ public class SettingsFragment extends PreferenceFragment { clearCachePreference.setEnabled(!clearEverything); // Set the homepage URL as the summary text for the homepage preference. - homepagePreference.setSummary(savedPreferences.getString("homepage", "https://duckduckgo.com/?kao=-1&kak=-1")); + homepagePreference.setSummary(savedPreferences.getString("homepage", getString(R.string.homepage_default_value))); // Set the default font size as the summary text for the preference. - defaultFontSizePreference.setSummary(savedPreferences.getString("default_font_size", "100") + "%%"); + defaultFontSizePreference.setSummary(savedPreferences.getString("default_font_size", getString(R.string.font_size_default_value)) + "%%"); // Disable the JavaScript preference if Night Mode is enabled. JavaScript will be enabled for all web pages. javaScriptPreference.setEnabled(!nightMode); @@ -423,6 +429,36 @@ public class SettingsFragment extends PreferenceFragment { } } + // Set the UltraPrivacy icon. + if (savedPreferences.getBoolean("ultraprivacy", true)) { + if (MainWebViewActivity.darkTheme) { + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark); + } else { + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light); + } + } else { + if (MainWebViewActivity.darkTheme) { + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark); + } else { + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light); + } + } + + // 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) { @@ -604,6 +640,21 @@ public class SettingsFragment extends PreferenceFragment { } } + // Set the download with external app preference icon. + if (savedPreferences.getBoolean("download_with_external_app", false)) { + if (MainWebViewActivity.darkTheme) { + downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_dark); + } else { + downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_light); + } + } else { + if (MainWebViewActivity.darkTheme) { + downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_dark); + } else { + downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_light); + } + } + // Set the display additional app bar icons preference icon. if (savedPreferences.getBoolean("display_additional_app_bar_icons", false)) { if (MainWebViewActivity.darkTheme) { @@ -780,7 +831,7 @@ public class SettingsFragment extends PreferenceFragment { case "user_agent": // Get the new user agent name. - String newUserAgentName = sharedPreferences.getString("user_agent", "Privacy Browser"); + String newUserAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value)); // Get the array position for the new user agent name. int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName); @@ -838,7 +889,7 @@ public class SettingsFragment extends PreferenceFragment { case "custom_user_agent": // Set the new custom user agent as the summary text for the preference. - customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0")); + customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value))); break; case "incognito_mode": @@ -944,7 +995,7 @@ public class SettingsFragment extends PreferenceFragment { boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboy_social_blocking_list", true); // Update the Fanboy icons. - if (sharedPreferences.getBoolean("fanboy_annoyance_list", true)) { + if (currentFanboyAnnoyanceList) { // Fanboy's annoyance list is enabled. if (MainWebViewActivity.darkTheme) { // Update the Fanboy's annoyance list icon. fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_dark); @@ -958,16 +1009,16 @@ public class SettingsFragment extends PreferenceFragment { // Update the Fanboy's social blocking list icon. fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_light); } - } else { + } else { // Fanboy's annoyance list is disabled. if (MainWebViewActivity.darkTheme) { // Update the Fanboy's annoyance list icon. fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_dark); // Update the Fanboy's social blocking list icon. if (currentFanboySocialBlockingList) { - fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_dark); + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_dark); } else { - fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_dark); + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_dark); } } else { // Update the Fanboy's annoyance list icon. @@ -975,9 +1026,9 @@ public class SettingsFragment extends PreferenceFragment { // Update the Fanboy's social blocking list icon. if (currentFanboySocialBlockingList) { - fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_light); + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_light); } else { - fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_light); + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_light); } } } @@ -1003,10 +1054,44 @@ public class SettingsFragment extends PreferenceFragment { } break; + case "ultraprivacy": + // Update the icon. + if (sharedPreferences.getBoolean("ultraprivacy", true)) { + if (MainWebViewActivity.darkTheme) { + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark); + } else { + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light); + } + } else { + if (MainWebViewActivity.darkTheme) { + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark); + } else { + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light); + } + } + 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); - String currentTorSearchString = sharedPreferences.getString("tor_search", "https://3g2upl4pq6kufc4m.onion/html/?q="); + String currentTorSearchString = sharedPreferences.getString("tor_search", getString(R.string.tor_search_default_value)); // Enable the Tor custom URL search option only if `currentProxyThroughOrbot` is true and the search is set to `Custom URL`. torSearchCustomURLPreference.setEnabled(currentProxyThroughOrbot && currentTorSearchString.equals("Custom URL")); @@ -1053,13 +1138,13 @@ public class SettingsFragment extends PreferenceFragment { break; case "tor_homepage": - // Set the new tor homepage URL as the summary text for the `tor_homepage` preference. The default is DuckDuckGo: `https://3g2upl4pq6kufc4m.onion`. - torHomepagePreference.setSummary(sharedPreferences.getString("tor_homepage", "https://3g2upl4pq6kufc4m.onion")); + // Set the new tor homepage URL as the summary text for the `tor_homepage` preference. The default is Searx: `http://ulrn6sryqaifefld.onion/`. + torHomepagePreference.setSummary(sharedPreferences.getString("tor_homepage", getString(R.string.tor_homepage_default_value))); break; case "tor_search": // Get the present search string. - String presentTorSearchString = sharedPreferences.getString("tor_search", "https://3g2upl4pq6kufc4m.onion/html/?q="); + String presentTorSearchString = sharedPreferences.getString("tor_search", getString(R.string.tor_search_default_value)); // Update the preferences. if (presentTorSearchString.equals("Custom URL")) { @@ -1093,12 +1178,12 @@ public class SettingsFragment extends PreferenceFragment { case "tor_search_custom_url": // Set the summary text for `tor_search_custom_url`. - torSearchCustomURLPreference.setSummary(sharedPreferences.getString("tor_search_custom_url", "")); + torSearchCustomURLPreference.setSummary(sharedPreferences.getString("tor_search_custom_url", getString(R.string.tor_search_custom_url_default_value))); break; case "search": // Store the new search string. - String newSearchString = sharedPreferences.getString("search", "https://duckduckgo.com/html/?q="); + String newSearchString = sharedPreferences.getString("search", getString(R.string.search_default_value)); // Update `searchPreference` and `searchCustomURLPreference`. if (newSearchString.equals("Custom URL")) { // `Custom URL` is selected. @@ -1132,7 +1217,7 @@ public class SettingsFragment extends PreferenceFragment { case "search_custom_url": // Set the new custom search URL as the summary text for `search_custom_url`. The default is `""`. - searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", "")); + searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value))); break; case "full_screen_browsing_mode": @@ -1381,13 +1466,13 @@ public class SettingsFragment extends PreferenceFragment { break; case "homepage": - // Set the new homepage URL as the summary text for the Homepage preference. The default is `https://www.duckduckgo.com`. - homepagePreference.setSummary(sharedPreferences.getString("homepage", "https://www.duckduckgo.com")); + // Set the new homepage URL as the summary text for the Homepage preference. + homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value))); break; case "default_font_size": // Update the summary text of `default_font_size`. - defaultFontSizePreference.setSummary(sharedPreferences.getString("default_font_size", "100") + "%%"); + defaultFontSizePreference.setSummary(sharedPreferences.getString("default_font_size", getString(R.string.font_size_default_value)) + "%%"); break; case "swipe_to_refresh": @@ -1407,6 +1492,23 @@ public class SettingsFragment extends PreferenceFragment { } break; + case "download_with_external_app": + // Update the icon. + if (sharedPreferences.getBoolean("download_with_external_app", false)) { + if (MainWebViewActivity.darkTheme) { + downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_dark); + } else { + downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_light); + } + } else { + if (MainWebViewActivity.darkTheme) { + downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_dark); + } else { + downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_light); + } + } + break; + case "display_additional_app_bar_icons": // Update the icon. if (sharedPreferences.getBoolean("display_additional_app_bar_icons", false)) {