From: Soren Stoutner Date: Wed, 26 Oct 2022 00:51:38 +0000 (-0700) Subject: Add a bottom app bar to Settings. https://redmine.stoutner.com/issues/716 X-Git-Tag: v3.12~17 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff_plain;h=9e11e18f4775c6bdd41f752f3baa290a0b50621d Add a bottom app bar to Settings. https://redmine.stoutner.com/issues/716 --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dbae9b6..cc2645dd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ - @@ -94,8 +93,7 @@ `android:configChanges="keyboard|keyboardHidden"` makes the activity not restart when a bluetooth keyboard is activated/goes to sleep. `android:launchMode="singleTask"` makes the app launch in a new task instead of inside the task of the program that sends it an intent. It also makes it reuse an existing Privacy Browser activity if available instead of launching a new one. - `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. - `tools:ignore="unusedAttribute"` removes the lint warning that `persistableMode` does not apply to API < 21. --> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:exported="true" > @@ -163,50 +160,43 @@ + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> + `android:persistableMode="persistNever"` removes Privacy Browser from the recent apps list on a device reboot. --> + android:persistableMode="persistNever" /> diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.kt index 0e1f320d..72e50c4c 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2022 Soren Stoutner . + * Copyright 2016-2022 Soren Stoutner . * * This file is part of Privacy Browser Android . * diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt index 949b678a..2edab552 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt @@ -205,9 +205,6 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI addDomainDialog.show(supportFragmentManager, resources.getString(R.string.add_domain)) } - // Get a handle for the activity. - val activity: Activity = this - // Control what the navigation bar back button does. val onBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { @@ -225,14 +222,14 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI undoDeleteSnackbar!!.dismiss() } else { // Go home. - NavUtils.navigateUpFromSameTask(activity) + finish() } } else if (closeOnBack) { // Go directly back to the main WebView activity because the domains activity was launched from the options menu. // Save the current domain settings. saveDomainSettings(coordinatorLayout) // Go home. - NavUtils.navigateUpFromSameTask(activity) + finish() } else if (findViewById(R.id.domain_settings_scrollview) != null) { // The device is in single-paned mode and domain settings fragment is displayed. // Save the current domain settings. saveDomainSettings(coordinatorLayout) @@ -261,7 +258,7 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI undoDeleteSnackbar!!.dismiss() } else { // Go home. - NavUtils.navigateUpFromSameTask(activity) + finish() } } } @@ -394,14 +391,14 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI undoDeleteSnackbar!!.dismiss() } else { // Go home. - NavUtils.navigateUpFromSameTask(this) + finish() } } else if (closeOnBack) { // Go directly back to the main WebView activity because the domains activity was launched from the options menu. // Save the current domain settings. saveDomainSettings(coordinatorLayout) // Go home. - NavUtils.navigateUpFromSameTask(this) + finish() } else if (findViewById(R.id.domain_settings_scrollview) != null) { // The device is in single-paned mode and the domain settings fragment is displayed. // Save the current domain settings. saveDomainSettings(coordinatorLayout) @@ -430,7 +427,7 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI undoDeleteSnackbar!!.dismiss() } else { // Go home. - NavUtils.navigateUpFromSameTask(this) + finish() } } } diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 2b9ad637..db953814 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -1,5 +1,5 @@ /* - * Copyright © 2015-2022 Soren Stoutner . + * Copyright 2015-2022 Soren Stoutner . * * Download cookie code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner . * @@ -278,6 +278,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Declare the class variables private boolean bottomAppBar; + private boolean displayAdditionalAppBarIcons; private boolean displayingFullScreenVideo; private boolean downloadWithExternalApp; private boolean fullScreenBrowsingModeEnabled; @@ -498,9 +499,10 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Get the preferences. - String appTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value)); + String appTheme = sharedPreferences.getString(getString(R.string.app_theme_key), getString(R.string.app_theme_default_value)); boolean allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false); bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false); + displayAdditionalAppBarIcons = sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false); // Get the theme entry values string array. String[] appThemeEntryValuesStringArray = getResources().getStringArray(R.array.app_theme_entry_values); @@ -666,7 +668,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } // Add a new tab if specified in the preferences. - if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) { // Load the URL in a new tab. + if (sharedPreferences.getBoolean(getString(R.string.open_intents_in_new_tab_key), true)) { // Load the URL in a new tab. // Set the loading new intent flag. loadingNewIntent = true; @@ -973,12 +975,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Disable the clear form data menu item if the API >= 26 so that the status of the main Clear Data is calculated correctly. optionsClearFormDataMenuItem.setEnabled(Build.VERSION.SDK_INT < 26); - // Get the shared preferences. - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - - // Get the dark theme and app bar preferences. - boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false); - // Set the status of the additional app bar icons. Setting the refresh menu item to `SHOW_AS_ACTION_ALWAYS` makes it appear even on small devices like phones. if (displayAdditionalAppBarIcons) { optionsRefreshMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); @@ -3523,13 +3519,13 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Store the values from the shared preferences in variables. - incognitoModeEnabled = sharedPreferences.getBoolean("incognito_mode", false); + incognitoModeEnabled = sharedPreferences.getBoolean(getString(R.string.incognito_mode_key), false); sanitizeTrackingQueries = sharedPreferences.getBoolean(getString(R.string.tracking_queries_key), true); sanitizeAmpRedirects = sharedPreferences.getBoolean(getString(R.string.amp_redirects_key), true); - proxyMode = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value)); - fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean("full_screen_browsing_mode", false); + proxyMode = sharedPreferences.getString(getString(R.string.proxy_key), getString(R.string.proxy_default_value)); + fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean(getString(R.string.full_screen_browsing_mode_key), false); + hideAppBar = sharedPreferences.getBoolean(getString(R.string.hide_app_bar_key), true); downloadWithExternalApp = sharedPreferences.getBoolean(getString(R.string.download_with_external_app_key), false); - hideAppBar = sharedPreferences.getBoolean("hide_app_bar", true); scrollAppBar = sharedPreferences.getBoolean(getString(R.string.scroll_app_bar_key), true); // Apply the saved proxy mode if the app has been restarted. @@ -3542,14 +3538,13 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } // Get the search string. - String searchString = sharedPreferences.getString("search", getString(R.string.search_default_value)); + String searchString = sharedPreferences.getString(getString(R.string.search_key), getString(R.string.search_default_value)); // Set the search string. - if (searchString.equals("Custom URL")) { // A custom search string is used. - searchURL = sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)); - } else { // A custom search string is not used. + if (searchString.equals(getString(R.string.custom_url_item))) + searchURL = sharedPreferences.getString(getString(R.string.search_custom_url_key), getString(R.string.search_custom_url_default_value)); + else searchURL = searchString; - } // Apply the proxy. applyProxy(false); @@ -4101,17 +4096,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook urlRelativeLayout.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.domain_settings_url_background, null)); } else { // The new URL does not have custom domain settings. Load the defaults. // Store the values from the shared preferences. - nestedScrollWebView.getSettings().setJavaScriptEnabled(sharedPreferences.getBoolean("javascript", false)); + nestedScrollWebView.getSettings().setJavaScriptEnabled(sharedPreferences.getBoolean(getString(R.string.javascript_key), false)); nestedScrollWebView.setAcceptCookies(sharedPreferences.getBoolean(getString(R.string.cookies_key), false)); - nestedScrollWebView.getSettings().setDomStorageEnabled(sharedPreferences.getBoolean("dom_storage", false)); - boolean saveFormData = sharedPreferences.getBoolean("save_form_data", false); // Form data can be removed once the minimum API >= 26. - nestedScrollWebView.setEasyListEnabled(sharedPreferences.getBoolean("easylist", true)); - nestedScrollWebView.setEasyPrivacyEnabled(sharedPreferences.getBoolean("easyprivacy", true)); - nestedScrollWebView.setFanboysAnnoyanceListEnabled(sharedPreferences.getBoolean("fanboys_annoyance_list", true)); - nestedScrollWebView.setFanboysSocialBlockingListEnabled(sharedPreferences.getBoolean("fanboys_social_blocking_list", true)); - nestedScrollWebView.setUltraListEnabled(sharedPreferences.getBoolean("ultralist", true)); - nestedScrollWebView.setUltraPrivacyEnabled(sharedPreferences.getBoolean("ultraprivacy", true)); - nestedScrollWebView.setBlockAllThirdPartyRequests(sharedPreferences.getBoolean("block_all_third_party_requests", false)); + nestedScrollWebView.getSettings().setDomStorageEnabled(sharedPreferences.getBoolean(getString(R.string.dom_storage_key), false)); + boolean saveFormData = sharedPreferences.getBoolean(getString(R.string.save_form_data_key), false); // Form data can be removed once the minimum API >= 26. + nestedScrollWebView.setEasyListEnabled(sharedPreferences.getBoolean(getString(R.string.easylist_key), true)); + nestedScrollWebView.setEasyPrivacyEnabled(sharedPreferences.getBoolean(getString(R.string.easyprivacy_key), true)); + nestedScrollWebView.setFanboysAnnoyanceListEnabled(sharedPreferences.getBoolean(getString(R.string.fanboys_annoyance_list_key), true)); + nestedScrollWebView.setFanboysSocialBlockingListEnabled(sharedPreferences.getBoolean(getString(R.string.fanboys_social_blocking_list_key), true)); + nestedScrollWebView.setUltraListEnabled(sharedPreferences.getBoolean(getString(R.string.ultralist_key), true)); + nestedScrollWebView.setUltraPrivacyEnabled(sharedPreferences.getBoolean(getString(R.string.ultraprivacy_key), true)); + nestedScrollWebView.setBlockAllThirdPartyRequests(sharedPreferences.getBoolean(getString(R.string.block_all_third_party_requests_key), false)); // Apply the default cookie setting. cookieManager.setAcceptCookie(nestedScrollWebView.getAcceptCookies()); @@ -4685,7 +4680,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } // Add a new tab if specified in the preferences. - if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) { // Load the URL in a new tab. + if (sharedPreferences.getBoolean(getString(R.string.open_intents_in_new_tab_key), true)) { // Load the URL in a new tab. // Set the loading new intent flag. loadingNewIntent = true; @@ -4813,7 +4808,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook bookmarksDatabaseHelper.close(); // Get the status of the clear everything preference. - boolean clearEverything = sharedPreferences.getBoolean("clear_everything", true); + boolean clearEverything = sharedPreferences.getBoolean(getString(R.string.clear_everything_key), true); // Get a handle for the runtime. Runtime runtime = Runtime.getRuntime(); @@ -4823,7 +4818,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook String privateDataDirectoryString = getApplicationInfo().dataDir; // Clear cookies. - if (clearEverything || sharedPreferences.getBoolean("clear_cookies", true)) { + if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_cookies_key), true)) { // Request the cookies be deleted. CookieManager.getInstance().removeAllCookies(null); @@ -4842,7 +4837,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } // Clear DOM storage. - if (clearEverything || sharedPreferences.getBoolean("clear_dom_storage", true)) { + if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_dom_storage_key), true)) { // Ask `WebStorage` to clear the DOM storage. WebStorage webStorage = WebStorage.getInstance(); webStorage.deleteAllData(); @@ -4870,7 +4865,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } // Clear form data if the API < 26. - if ((Build.VERSION.SDK_INT < 26) && (clearEverything || sharedPreferences.getBoolean("clear_form_data", true))) { + if ((Build.VERSION.SDK_INT < 26) && (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_form_data_key), true))) { WebViewDatabase webViewDatabase = WebViewDatabase.getInstance(this); webViewDatabase.clearFormData(); @@ -4902,7 +4897,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } // Clear the cache. - if (clearEverything || sharedPreferences.getBoolean("clear_cache", true)) { + if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_cache_key), true)) { // Clear the cache from each WebView. for (int i = 0; i < webViewPagerAdapter.getCount(); i++) { // Get the WebView tab fragment. @@ -6100,13 +6095,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Set the title. optionsRefreshMenuItem.setTitle(R.string.stop); - // Get the app bar and theme preferences. - boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false); - - // Set the icon if it is displayed in the AppBar. Once the minimum API is >= 26, the blue and black icons can be combined with a tint list. - if (displayAdditionalAppBarIcons) { + // Set the icon if it is displayed in the AppBar. + if (displayAdditionalAppBarIcons) optionsRefreshMenuItem.setIcon(R.drawable.close_blue); - } } } @@ -6122,14 +6113,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Reset the Refresh title. optionsRefreshMenuItem.setTitle(R.string.refresh); - // Get the app bar and theme preferences. - boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false); - - // If the icon is displayed in the app bar, reset it according to the theme. - if (displayAdditionalAppBarIcons) { - // Set the icon. + // Reset the icon if it is displayed in the app bar. + if (displayAdditionalAppBarIcons) optionsRefreshMenuItem.setIcon(R.drawable.refresh_enabled); - } } // Get the application's private data directory, which will be something like `/data/user/0/com.stoutner.privacybrowser.standard`, @@ -6378,4 +6364,4 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/SettingsActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/SettingsActivity.java deleted file mode 100644 index 66986bac..00000000 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/SettingsActivity.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright © 2016-2020,2022 Soren Stoutner . - * - * This file is part of Privacy Browser Android . - * - * 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 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 Android. If not, see . - */ - -package com.stoutner.privacybrowser.activities; - -import android.content.SharedPreferences; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.view.WindowManager; - -import androidx.appcompat.app.AppCompatActivity; - -import com.stoutner.privacybrowser.fragments.SettingsFragment; - -public class SettingsActivity extends AppCompatActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - // Get a handle for the shared preferences. - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - - // Get the screenshot and theme preferences. - boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false); - - // Disable screenshots if not allowed. - if (!allowScreenshots) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); - } - - // Run the default commands. - super.onCreate(savedInstanceState); - - // Display the settings fragment. - getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit(); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/SettingsActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/SettingsActivity.kt new file mode 100644 index 00000000..35cb1f62 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/SettingsActivity.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2016-2022 Soren Stoutner . + * + * This file is part of Privacy Browser Android . + * + * 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 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 Android. If not, see . + */ + +package com.stoutner.privacybrowser.activities + +import android.os.Bundle +import android.view.MenuItem +import android.view.WindowManager + +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.widget.Toolbar +import androidx.preference.PreferenceManager + +import com.stoutner.privacybrowser.R +import com.stoutner.privacybrowser.fragments.SettingsFragment + +class SettingsActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + // Get a handle for the shared preferences. + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext) + + // Get the preference. + val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false) + val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false) + + // Disable screenshots if not allowed. + if (!allowScreenshots) window.addFlags(WindowManager.LayoutParams.FLAG_SECURE) + + // Run the default commands. + super.onCreate(savedInstanceState) + + // Set the content view. + if (bottomAppBar) { + setContentView(R.layout.settings_bottom_appbar) + } else { + setContentView(R.layout.settings_top_appbar) + } + + // Get a handle for the toolbar. + val toolbar = findViewById(R.id.toolbar) + + // Set the support action bar. + setSupportActionBar(toolbar) + + // Get a handle for the action bar. + val actionBar = supportActionBar!! + + // Display the home arrow on the action bar. + actionBar.setDisplayHomeAsUpEnabled(true) + + // Display the settings fragment. + supportFragmentManager.beginTransaction().replace(R.id.preferences_framelayout, SettingsFragment()).commit() + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + // As the back arrow is the only option, finish the activity. + finish() + + // Consume the event. + return true + } +} diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.kt b/app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.kt index 0b2d6ed0..f1cc8cb3 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.kt @@ -113,7 +113,7 @@ class AddDomainDialog : DialogFragment() { val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) // Get the screenshot preference. - val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots), false) + val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false) // Disable screenshots if not allowed. if (!allowScreenshots) { diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt index 342c3585..6d74af79 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt @@ -286,8 +286,8 @@ class AboutVersionFragment : Fragment() { systemTotalMemoryLabel = getString(R.string.system_total_memory) + " " val easyListLabel = getString(R.string.easylist_label) + " " val easyPrivacyLabel = getString(R.string.easyprivacy_label) + " " - val fanboyAnnoyanceLabel = getString(R.string.fanboy_annoyance_label) + " " - val fanboySocialLabel = getString(R.string.fanboy_social_label) + " " + val fanboyAnnoyanceLabel = getString(R.string.fanboys_annoyance_label) + " " + val fanboySocialLabel = getString(R.string.fanboys_social_label) + " " val ultraListLabel = getString(R.string.ultralist_label) + " " val ultraPrivacyLabel = getString(R.string.ultraprivacy_label) + " " val issuerDNLabel = getString(R.string.issuer_dn) + " " diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java deleted file mode 100644 index d7aecd30..00000000 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java +++ /dev/null @@ -1,1443 +0,0 @@ -/* - * Copyright © 2016-2022 Soren Stoutner . - * - * This file is part of Privacy Browser Android . - * - * 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 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 Android. If not, see . - */ - -package com.stoutner.privacybrowser.fragments; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.content.res.Resources; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.view.LayoutInflater; -import android.view.View; -import android.webkit.WebView; -import android.widget.ArrayAdapter; - -import androidx.appcompat.app.AppCompatDelegate; -import androidx.preference.Preference; -import androidx.preference.PreferenceCategory; -import androidx.preference.PreferenceFragmentCompat; - -import com.stoutner.privacybrowser.R; -import com.stoutner.privacybrowser.activities.MainWebViewActivity; -import com.stoutner.privacybrowser.helpers.ProxyHelper; - -import java.util.Objects; - -public class SettingsFragment extends PreferenceFragmentCompat { - // Declare the class variables. - private String defaultUserAgent; - private ArrayAdapter userAgentNamesArray; - private String[] translatedUserAgentNamesArray; - private String[] userAgentDataArray; - private String[] appThemeEntriesStringArray; - private String[] appThemeEntryValuesStringArray; - private String[] webViewThemeEntriesStringArray; - private String[] webViewThemeEntryValuesStringArray; - private SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener; - - // Declare the class views. - private Preference javaScriptPreference; - private Preference cookiesPreference; - private Preference domStoragePreference; - private Preference formDataPreference; // The form data preference can be removed once the minimum API >= 26. - private Preference userAgentPreference; - private Preference customUserAgentPreference; - private Preference xRequestedWithHeaderPreference; - private Preference incognitoModePreference; - private Preference allowScreenshotsPreference; - private Preference easyListPreference; - private Preference easyPrivacyPreference; - private Preference fanboyAnnoyanceListPreference; - private Preference fanboySocialBlockingListPreference; - private Preference ultraListPreference; - private Preference ultraPrivacyPreference; - private Preference blockAllThirdPartyRequestsPreference; - private Preference trackingQueriesPreference; - private Preference ampRedirectsPreference; - private Preference searchPreference; - private Preference searchCustomURLPreference; - private Preference proxyPreference; - private Preference proxyCustomUrlPreference; - private Preference fullScreenBrowsingModePreference; - private Preference hideAppBarPreference; - private Preference clearEverythingPreference; - private Preference clearCookiesPreference; - private Preference clearDomStoragePreference; - private Preference clearFormDataPreference; // The clear form data preference can be removed once the minimum API >= 26. - private Preference clearLogcatPreference; - private Preference clearCachePreference; - private Preference homepagePreference; - private Preference fontSizePreference; - private Preference openIntentsInNewTabPreference; - private Preference swipeToRefreshPreference; - private Preference downloadWithExternalAppPreference; - private Preference scrollAppBarPreference; - private Preference bottomAppBarPreference; - private Preference displayAdditionalAppBarIconsPreference; - private Preference appThemePreference; - private Preference webViewThemePreference; - private Preference wideViewportPreference; - private Preference displayWebpageImagesPreference; - - @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - // Load the preferences from the XML file. - setPreferencesFromResource(R.xml.preferences, rootKey); - - // Get a handle for the activity. - Activity activity = getActivity(); - - // Remove the lint warning below that `getApplicationContext()` might produce a null pointer exception. - assert activity != null; - - // Get a handle for the resources. - Resources resources = getResources(); - - // Get a handle for the shared preferences. - SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); - - // Remove the incorrect warning below that the shared preferences might be null. - assert sharedPreferences != null; - - // Get handles for the preferences. - javaScriptPreference = findPreference("javascript"); - cookiesPreference = findPreference(getString(R.string.cookies_key)); - domStoragePreference = findPreference("dom_storage"); - formDataPreference = findPreference("save_form_data"); // The form data preference can be removed once the minimum API >= 26. - userAgentPreference = findPreference(getString(R.string.user_agent_key)); - customUserAgentPreference = findPreference("custom_user_agent"); - xRequestedWithHeaderPreference = findPreference(getString(R.string.x_requested_with_header_key)); - incognitoModePreference = findPreference("incognito_mode"); - allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key)); - easyListPreference = findPreference("easylist"); - easyPrivacyPreference = findPreference("easyprivacy"); - fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list"); - fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list"); - ultraListPreference = findPreference("ultralist"); - ultraPrivacyPreference = findPreference("ultraprivacy"); - blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests"); - trackingQueriesPreference = findPreference(getString(R.string.tracking_queries_key)); - ampRedirectsPreference = findPreference(getString(R.string.amp_redirects_key)); - searchPreference = findPreference("search"); - searchCustomURLPreference = findPreference("search_custom_url"); - proxyPreference = findPreference("proxy"); - proxyCustomUrlPreference = findPreference(getString(R.string.proxy_custom_url_key)); - fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode"); - hideAppBarPreference = findPreference("hide_app_bar"); - clearEverythingPreference = findPreference("clear_everything"); - clearCookiesPreference = findPreference("clear_cookies"); - clearDomStoragePreference = findPreference("clear_dom_storage"); - clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26. - clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key)); - clearCachePreference = findPreference("clear_cache"); - homepagePreference = findPreference("homepage"); - fontSizePreference = findPreference(getString(R.string.font_size_key)); - openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab"); - swipeToRefreshPreference = findPreference(getString(R.string.swipe_to_refresh_key)); - downloadWithExternalAppPreference = findPreference(getString(R.string.download_with_external_app_key)); - scrollAppBarPreference = findPreference(getString(R.string.scroll_app_bar_key)); - bottomAppBarPreference = findPreference(getString(R.string.bottom_app_bar_key)); - displayAdditionalAppBarIconsPreference = findPreference(getString(R.string.display_additional_app_bar_icons_key)); - appThemePreference = findPreference("app_theme"); - webViewThemePreference = findPreference(getString(R.string.webview_theme_key)); - wideViewportPreference = findPreference(getString(R.string.wide_viewport_key)); - displayWebpageImagesPreference = findPreference(getString(R.string.display_webpage_images_key)); - - // Remove the lint warnings below that the preferences might be null. - assert javaScriptPreference != null; - assert cookiesPreference != null; - assert domStoragePreference != null; - assert formDataPreference != null; - assert userAgentPreference != null; - assert customUserAgentPreference != null; - assert xRequestedWithHeaderPreference != null; - assert incognitoModePreference != null; - assert allowScreenshotsPreference != null; - assert easyListPreference != null; - assert easyPrivacyPreference != null; - assert fanboyAnnoyanceListPreference != null; - assert fanboySocialBlockingListPreference != null; - assert ultraListPreference != null; - assert ultraPrivacyPreference != null; - assert blockAllThirdPartyRequestsPreference != null; - assert trackingQueriesPreference != null; - assert ampRedirectsPreference != null; - assert searchPreference != null; - assert searchCustomURLPreference != null; - assert proxyPreference != null; - assert proxyCustomUrlPreference != null; - assert fullScreenBrowsingModePreference != null; - assert hideAppBarPreference != null; - assert clearEverythingPreference != null; - assert clearCookiesPreference != null; - assert clearDomStoragePreference != null; - assert clearFormDataPreference != null; - assert clearLogcatPreference != null; - assert clearCachePreference != null; - assert homepagePreference != null; - assert fontSizePreference != null; - assert openIntentsInNewTabPreference != null; - assert swipeToRefreshPreference != null; - assert downloadWithExternalAppPreference != null; - assert scrollAppBarPreference != null; - assert bottomAppBarPreference != null; - assert displayAdditionalAppBarIconsPreference != null; - assert appThemePreference != null; - assert webViewThemePreference != null; - assert wideViewportPreference != null; - assert displayWebpageImagesPreference != null; - - // Set the preference dependencies. - hideAppBarPreference.setDependency("full_screen_browsing_mode"); - domStoragePreference.setDependency("javascript"); - - // Get strings from the preferences. - String userAgentName = sharedPreferences.getString(getString(R.string.user_agent_key), getString(R.string.user_agent_default_value)); - String searchString = sharedPreferences.getString("search", getString(R.string.search_default_value)); - String proxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value)); - - // Get booleans that are used in multiple places from the preferences. - boolean javaScriptEnabled = sharedPreferences.getBoolean("javascript", false); - boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboys_annoyance_list", true); - boolean fanboySocialBlockingEnabled = sharedPreferences.getBoolean("fanboys_social_blocking_list", true); - boolean fullScreenBrowsingMode = sharedPreferences.getBoolean("full_screen_browsing_mode", false); - boolean clearEverything = sharedPreferences.getBoolean("clear_everything", true); - - // Remove the form data preferences if the API is >= 26 as they no longer do anything. - if (Build.VERSION.SDK_INT >= 26) { - // Get handles for the categories. - PreferenceCategory privacyCategory = findPreference("privacy"); - PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit"); - - // Remove the incorrect lint warnings below that the preference categories might be null. - assert privacyCategory != null; - assert clearAndExitCategory != null; - - // Remove the form data preferences. - privacyCategory.removePreference(formDataPreference); - clearAndExitCategory.removePreference(clearFormDataPreference); - } - - // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled. - fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled); - - - // Inflate a WebView to get the default user agent. - LayoutInflater inflater = getActivity().getLayoutInflater(); - - // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because the `bare_webview` will not be displayed. - @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false); - - // Get a handle for a bare WebView. - WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview); - - // Get the default user agent. - defaultUserAgent = bareWebView.getSettings().getUserAgentString(); - - // Get the user agent arrays. - userAgentNamesArray = ArrayAdapter.createFromResource(requireContext(), R.array.user_agent_names, R.layout.spinner_item); - translatedUserAgentNamesArray = resources.getStringArray(R.array.translated_user_agent_names); - userAgentDataArray = resources.getStringArray(R.array.user_agent_data); - - // Get the array position of the user agent name. - int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName); - - // Populate the user agent summary. - switch (userAgentArrayPosition) { - case MainWebViewActivity.UNRECOGNIZED_USER_AGENT: // The user agent name is not on the canonical list. - // This is probably because it was set in an older version of Privacy Browser before the switch to persistent user agent names. Use the current user agent entry name as the summary. - userAgentPreference.setSummary(userAgentName); - break; - - case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT: - // Get the user agent text from the webview (which changes based on the version of Android and WebView installed). - userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + defaultUserAgent); - break; - - case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT: - // Set the summary text. - userAgentPreference.setSummary(R.string.custom_user_agent); - break; - - default: - // Get the user agent summary from the user agent data array. - userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]); - } - - // Set the summary text for the custom user agent preference. - customUserAgentPreference.setSummary(sharedPreferences.getString(getString(R.string.custom_user_agent_key), getString(R.string.custom_user_agent_default_value))); - - // Only enable the custom user agent preference if the user agent is set to `Custom`. - customUserAgentPreference.setEnabled(Objects.equals(userAgentPreference.getSummary(), getString(R.string.custom_user_agent))); - - // 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); - } else { - // Set the array value as the summary text. - searchPreference.setSummary(searchString); - } - - // Set the summary text for the search custom URL (the default is `""`). - searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value))); - - // Only enable the search custom URL preference if the search is set to `Custom URL`. - searchCustomURLPreference.setEnabled(searchString.equals("Custom URL")); - - - // Set the summary text for the proxy preference when the preference screen is loaded. - switch (proxyString) { - case ProxyHelper.NONE: - proxyPreference.setSummary(getString(R.string.no_proxy_enabled)); - break; - - case ProxyHelper.TOR: - proxyPreference.setSummary(getString(R.string.tor_enabled)); - break; - - case ProxyHelper.I2P: - proxyPreference.setSummary(getString(R.string.i2p_enabled)); - break; - - case ProxyHelper.CUSTOM: - proxyPreference.setSummary(getString(R.string.custom_proxy)); - break; - } - - // Set the summary text for the custom proxy URL. - proxyCustomUrlPreference.setSummary(sharedPreferences.getString(getString(R.string.proxy_custom_url_key), getString(R.string.proxy_custom_url_default_value))); - - // Only enable the custom proxy URL if a custom proxy is selected. - proxyCustomUrlPreference.setEnabled(proxyString.equals(ProxyHelper.CUSTOM)); - - - // Set the status of the clear and exit preferences. - clearCookiesPreference.setEnabled(!clearEverything); - clearDomStoragePreference.setEnabled(!clearEverything); - clearFormDataPreference.setEnabled(!clearEverything); // The form data line can be removed once the minimum API is >= 26. - clearLogcatPreference.setEnabled(!clearEverything); - clearCachePreference.setEnabled(!clearEverything); - - - // Set the homepage URL as the summary text for the homepage preference. - homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value))); - - - // Set the font size as the summary text for the preference. - fontSizePreference.setSummary(sharedPreferences.getString(getString(R.string.font_size_key), getString(R.string.font_size_default_value)) + "%"); - - - // Get the app theme string arrays. - appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries); - appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values); - - // Get the current app theme. - String currentAppTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value)); - - // Declare an app theme entry number. - int appThemeEntryNumber; - - // Get the app theme entry number that matches the current app theme. A switch statement cannot be used because the theme entry values string array is not a compile time constant. - if (currentAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected. - // Store the app theme entry number. - appThemeEntryNumber = 1; - } else if (currentAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected. - // Store the app theme entry number. - appThemeEntryNumber = 2; - } else { // The system default theme is selected. - // Store the app theme entry number. - appThemeEntryNumber = 0; - } - - // Set the current theme as the summary text for the preference. - appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]); - - // Disable the WebView theme preference if the API >= 33 and the app theme is set to light. - webViewThemePreference.setEnabled((Build.VERSION.SDK_INT < 33) || (appThemeEntryNumber != 1)); - - - // Get the WebView theme string arrays. - webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries); - webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values); - - // Get the current WebView theme. - String currentWebViewTheme = sharedPreferences.getString(getString(R.string.webview_theme_key), getString(R.string.webview_theme_default_value)); - - // Define a WebView theme entry number. - int webViewThemeEntryNumber; - - // Get the WebView theme entry number that matches the current WebView theme. A switch statement cannot be used because the WebView theme entry values string array is not a compile time constant. - if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) { // The light theme is selected. - // Store the WebView theme entry number. - webViewThemeEntryNumber = 1; - } else if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected. - // Store the WebView theme entry number. - webViewThemeEntryNumber = 2; - } else { // The system default theme is selected. - // Store the WebView theme entry number. - webViewThemeEntryNumber = 0; - } - - // Set the current theme as the summary text for the preference. - webViewThemePreference.setSummary(webViewThemeEntriesStringArray[webViewThemeEntryNumber]); - - - // Set the JavaScript icon. - if (javaScriptEnabled) { - javaScriptPreference.setIcon(R.drawable.javascript_enabled); - } else { - javaScriptPreference.setIcon(R.drawable.privacy_mode); - } - - // Set the cookies icon. - if (sharedPreferences.getBoolean(getString(R.string.cookies_key), false)) { - cookiesPreference.setIcon(R.drawable.cookies_enabled); - } else { - cookiesPreference.setIcon(R.drawable.cookies_disabled); - } - - // Set the DOM storage icon. - if (javaScriptEnabled) { // The preference is enabled. - if (sharedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled. - domStoragePreference.setIcon(R.drawable.dom_storage_enabled); - } else { // DOM storage is disabled. - domStoragePreference.setIcon(R.drawable.dom_storage_disabled); - } - } else { // The preference is disabled. The icon should be ghosted. - domStoragePreference.setIcon(R.drawable.dom_storage_ghosted); - } - - // Set the save form data icon if API < 26. Save form data has no effect on API >= 26. - if (Build.VERSION.SDK_INT < 26) { - if (sharedPreferences.getBoolean("save_form_data", false)) - formDataPreference.setIcon(R.drawable.form_data_enabled); - else - formDataPreference.setIcon(R.drawable.form_data_disabled); - } - - // Set the custom user agent icon. - if (customUserAgentPreference.isEnabled()) - customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled); - else - customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted); - - // Set the X-Requested With header icon. - if (sharedPreferences.getBoolean(getString(R.string.x_requested_with_header_key), true)) - xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_enabled); - else - xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_disabled); - - // Set the incognito mode icon. - if (sharedPreferences.getBoolean("incognito_mode", false)) - incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled); - else - incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled); - - // Set the allow screenshots icon. - if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled); - else - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled); - - // Set the EasyList icon. - if (sharedPreferences.getBoolean("easylist", true)) - easyListPreference.setIcon(R.drawable.block_ads_enabled); - else - easyListPreference.setIcon(R.drawable.block_ads_disabled); - - // Set the EasyPrivacy icon. - if (sharedPreferences.getBoolean("easyprivacy", true)) - easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled); - else - easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled); - - // Set the Fanboy lists icons. - if (fanboyAnnoyanceListEnabled) { - // Set the Fanboy annoyance list icon. - fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled); - - // Set the Fanboy social blocking list icon. - fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted); - } else { - // Set the Fanboy annoyance list icon. - fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled); - - // Set the Fanboy social blocking list icon. - if (fanboySocialBlockingEnabled) { - fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled); - } else { - fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled); - } - } - - // Set the UltraList icon. - if (sharedPreferences.getBoolean("ultralist", true)){ - ultraListPreference.setIcon(R.drawable.block_ads_enabled); - } else { - ultraListPreference.setIcon(R.drawable.block_ads_disabled); - } - - // Set the UltraPrivacy icon. - if (sharedPreferences.getBoolean("ultraprivacy", true)) { - ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled); - } else { - ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled); - } - - // Set the block all third-party requests icon. - if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) { - blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled); - } else { - blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled); - } - - // Set the Tracking Queries icon. - if (sharedPreferences.getBoolean(getString(R.string.tracking_queries_key), true)) { - trackingQueriesPreference.setIcon(R.drawable.modify_url_enabled); - } else { - trackingQueriesPreference.setIcon(R.drawable.modify_url_disabled); - } - - // Set the AMP Redirects icon. - if (sharedPreferences.getBoolean(getString(R.string.amp_redirects_key), true)) { - ampRedirectsPreference.setIcon(R.drawable.modify_url_enabled); - } else { - ampRedirectsPreference.setIcon(R.drawable.modify_url_disabled); - } - - // Set the search custom URL icon. - if (searchCustomURLPreference.isEnabled()) { - searchCustomURLPreference.setIcon(R.drawable.search_custom_enabled); - } else { - searchCustomURLPreference.setIcon(R.drawable.search_custom_ghosted); - } - - // Set the Proxy icons according to the theme and status. - if (proxyString.equals(ProxyHelper.NONE)) { // Proxying is disabled. - // Set the main proxy icon to be disabled. - proxyPreference.setIcon(R.drawable.proxy_disabled); - - // Set the custom proxy URL icon to be ghosted. - proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted); - } else { // Proxying is enabled. - // Set the main proxy icon to be enabled. - proxyPreference.setIcon(R.drawable.proxy_enabled); - - // Set the custom proxy URL icon according to its status. - if (proxyCustomUrlPreference.isEnabled()) { - proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled); - } else { - proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted); - } - } - - // Set the full screen browsing mode icons. - if (fullScreenBrowsingMode) { // Full screen browsing mode is enabled. - // Set the full screen browsing mode preference icon. - fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled); - - // Set the hide app bar icon. - if (sharedPreferences.getBoolean("hide_app_bar", true)) { - hideAppBarPreference.setIcon(R.drawable.app_bar_enabled); - } else { - hideAppBarPreference.setIcon(R.drawable.app_bar_disabled); - } - } else { // Full screen browsing mode is disabled. - // Set the icons. - fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled); - hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted); - } - - // Set the clear everything preference icon. - if (clearEverything) { - clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled); - } else { - clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled); - } - - // Set the clear cookies preference icon. - if (clearEverything || sharedPreferences.getBoolean("clear_cookies", true)) { - clearCookiesPreference.setIcon(R.drawable.clear_cookies_enabled); - } else { - clearCookiesPreference.setIcon(R.drawable.clear_cookies_disabled); - } - - // Set the clear DOM storage preference icon. - if (clearEverything || sharedPreferences.getBoolean("clear_dom_storage", true)) { - clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_enabled); - } else { - clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_disabled); - } - - // Set the clear form data preference icon if the API < 26. It has no effect on newer versions of Android. - if (Build.VERSION.SDK_INT < 26) { - if (clearEverything || sharedPreferences.getBoolean("clear_form_data", true)) { - clearFormDataPreference.setIcon(R.drawable.clear_form_data_enabled); - } else { - clearFormDataPreference.setIcon(R.drawable.clear_form_data_disabled); - } - } - - // Set the clear logcat preference icon. - if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) { - clearLogcatPreference.setIcon(R.drawable.clear_logcat_enabled); - } else { - clearLogcatPreference.setIcon(R.drawable.clear_logcat_disabled); - } - - // Set the clear cache preference icon. - if (clearEverything || sharedPreferences.getBoolean("clear_cache", true)) { - clearCachePreference.setIcon(R.drawable.clear_cache_enabled); - } else { - clearCachePreference.setIcon(R.drawable.clear_cache_disabled); - } - - // Set the open intents in new tab preference icon. - if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) { - openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled); - } else { - openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled); - } - - // Set the swipe to refresh preference icon. - if (sharedPreferences.getBoolean(getString(R.string.swipe_to_refresh_key), true)) - swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled); - else - swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled); - - // Set the download with external app preference icon. - if (sharedPreferences.getBoolean(getString(R.string.download_with_external_app_key), false)) - downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled); - else - downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled); - - // Set the scroll app bar preference icon. - if (sharedPreferences.getBoolean(getString(R.string.scroll_app_bar_key), true)) - scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled); - else - scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled); - - // Set the bottom app bar preference icon. - if (sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)) - bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled); - else - bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled); - - // Set the display additional app bar icons preference icon. - if (sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false)) - displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled); - else - displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled); - - // Set the WebView theme preference icon. - if (webViewThemePreference.isEnabled()) { // The WebView theme preference is enabled. - switch (webViewThemeEntryNumber) { - case 0: // The system default WebView theme is selected. - // Get the current theme status. - int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; - - // Set the icon according to the app theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) - webViewThemePreference.setIcon(R.drawable.webview_light_theme); - else - webViewThemePreference.setIcon(R.drawable.webview_dark_theme); - break; - - case 1: // The light WebView theme is selected. - // Set the icon. - webViewThemePreference.setIcon(R.drawable.webview_light_theme); - break; - - case 2: // The dark WebView theme is selected. - // Set the icon. - webViewThemePreference.setIcon(R.drawable.webview_dark_theme); - break; - } - } else { // The WebView theme preference is disabled. - webViewThemePreference.setIcon(R.drawable.webview_theme_ghosted); - } - - // Set the wide viewport preference icon. - if (sharedPreferences.getBoolean(getString(R.string.wide_viewport_key), true)) { - wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled); - } else { - wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled); - } - - // Set the display webpage images preference icon. - if (sharedPreferences.getBoolean(getString(R.string.display_webpage_images_key), true)) { - displayWebpageImagesPreference.setIcon(R.drawable.images_enabled); - } else { - displayWebpageImagesPreference.setIcon(R.drawable.images_disabled); - } - } - - // The listener should be unregistered when the app is paused. - @Override - public void onPause() { - // Run the default commands. - super.onPause(); - - // Get a handle for the shared preferences. - SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); - - // Remove the incorrect lint warning below that the shared preferences might be null. - assert sharedPreferences != null; - - // Unregister the shared preference listener. - sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); - } - - // The listener should be re-registered when the app is resumed. - @Override - public void onResume() { - // Run the default commands. - super.onResume(); - - // Get a new shared preference change listener. - sharedPreferenceChangeListener = getSharedPreferenceChangeListener(requireContext()); - - // Get a handle for the shared preferences. - SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); - - // Remove the incorrect lint warning below that the shared preferences might be null. - assert sharedPreferences != null; - - // Re-register the shared preference listener. - sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); - } - - // The context must be passed to the shared preference change listener or else any calls to the system `getString()` will crash if the app has been restarted. - // This can be removed at some future point, perhaps after the switch to PreferenceScreenCompat. It isn't an issue in Privacy Cell. - private SharedPreferences.OnSharedPreferenceChangeListener getSharedPreferenceChangeListener(Context context) { - // Return the shared preference change listener. - return (SharedPreferences sharedPreferences, String key) -> { - switch (key) { - case "javascript": - // Update the icons and the DOM storage preference status. - if (sharedPreferences.getBoolean("javascript", false)) { // The JavaScript preference is enabled. - // Update the icon for the JavaScript preference. - javaScriptPreference.setIcon(R.drawable.javascript_enabled); - - // Update the status of the DOM storage preference. - domStoragePreference.setEnabled(true); - - // Update the icon for the DOM storage preference. - if (sharedPreferences.getBoolean("dom_storage", false)) { - domStoragePreference.setIcon(R.drawable.dom_storage_enabled); - } else { - domStoragePreference.setIcon(R.drawable.dom_storage_disabled); - } - } else { // The JavaScript preference is disabled. - // Update the icon for the JavaScript preference. - javaScriptPreference.setIcon(R.drawable.privacy_mode); - - // Update the status of the DOM storage preference. - domStoragePreference.setEnabled(false); - - // Set the icon for DOM storage preference to be ghosted. - domStoragePreference.setIcon(R.drawable.dom_storage_ghosted); - } - break; - - case "cookies": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.cookies_key), false)) { - cookiesPreference.setIcon(R.drawable.cookies_enabled); - } else { - cookiesPreference.setIcon(R.drawable.cookies_disabled); - } - break; - - case "dom_storage": - // Update the icon. - if (sharedPreferences.getBoolean("dom_storage", false)) { - domStoragePreference.setIcon(R.drawable.dom_storage_enabled); - } else { - domStoragePreference.setIcon(R.drawable.dom_storage_disabled); - } - break; - - // Save form data can be removed once the minimum API >= 26. - case "save_form_data": - // Update the icon. - if (sharedPreferences.getBoolean("save_form_data", false)) { - formDataPreference.setIcon(R.drawable.form_data_enabled); - } else { - formDataPreference.setIcon(R.drawable.form_data_disabled); - } - break; - - case "user_agent": - // Get the new user agent name. - String newUserAgentName = sharedPreferences.getString(context.getString(R.string.user_agent_key), context.getString(R.string.user_agent_default_value)); - - // Get the array position for the new user agent name. - int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName); - - // Get the translated new user agent name. - String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition]; - - // Populate the user agent summary. - switch (newUserAgentArrayPosition) { - case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT: - // Get the user agent text from the webview (which changes based on the version of Android and WebView installed). - userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + defaultUserAgent); - - // Disable the custom user agent preference. - customUserAgentPreference.setEnabled(false); - - // Set the custom user agent preference icon. - customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted); - break; - - case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT: - // Set the summary text. - userAgentPreference.setSummary(R.string.custom_user_agent); - - // Enable the custom user agent preference. - customUserAgentPreference.setEnabled(true); - - // Set the custom user agent preference icon. - customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled); - break; - - default: - // Get the user agent summary from the user agent data array. - userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]); - - // Disable the custom user agent preference. - customUserAgentPreference.setEnabled(false); - - // Set the custom user agent preference icon. - customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted); - } - break; - - case "custom_user_agent": - // Set the new custom user agent as the summary text for the preference. - customUserAgentPreference.setSummary(sharedPreferences.getString(context.getString(R.string.custom_user_agent_key), context.getString(R.string.custom_user_agent_default_value))); - break; - - case "x_requested_with_header": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.x_requested_with_header_key), true)) - xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_enabled); - else - xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_disabled); - - // Restart Privacy Browser. - restartPrivacyBrowser(); - break; - - case "incognito_mode": - // Update the icon. - if (sharedPreferences.getBoolean("incognito_mode", false)) - incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled); - else - incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled); - break; - - case "allow_screenshots": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.allow_screenshots_key), false)) - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled); - else - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled); - - // Restart Privacy Browser. - restartPrivacyBrowser(); - break; - - case "easylist": - // Update the icon. - if (sharedPreferences.getBoolean("easylist", true)) - easyListPreference.setIcon(R.drawable.block_ads_enabled); - else - easyListPreference.setIcon(R.drawable.block_ads_disabled); - break; - - case "easyprivacy": - // Update the icon. - if (sharedPreferences.getBoolean("easyprivacy", true)) - easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled); - else - easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled); - break; - - case "fanboys_annoyance_list": - boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true); - boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true); - - // Update the Fanboy icons. - if (currentFanboyAnnoyanceList) { // Fanboy's annoyance list is enabled. - // Update the Fanboy's annoyance list icon. - fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled); - - // Update the Fanboy's social blocking list icon. - fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted); - } else { // Fanboy's annoyance list is disabled. - // Update the Fanboy's annoyance list icon. - fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled); - - // Update the Fanboy's social blocking list icon. - if (currentFanboySocialBlockingList) { - fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled); - } else { - fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled); - } - } - - // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled. - fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList); - break; - - case "fanboys_social_blocking_list": - // Update the icon. - if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) { - fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled); - } else { - fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled); - } - break; - - case "ultralist": - // Update the icon. - if (sharedPreferences.getBoolean("ultralist", true)) { - ultraListPreference.setIcon(R.drawable.block_ads_enabled); - } else { - ultraListPreference.setIcon(R.drawable.block_ads_disabled); - } - break; - - case "ultraprivacy": - // Update the icon. - if (sharedPreferences.getBoolean("ultraprivacy", true)) { - ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled); - } else { - ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled); - } - break; - - case "block_all_third_party_requests": - // Update the icon. - if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) { - blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled); - } else { - blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled); - } - break; - - case "tracking_queries": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.tracking_queries_key), true)) { - trackingQueriesPreference.setIcon(R.drawable.modify_url_enabled); - } else { - trackingQueriesPreference.setIcon(R.drawable.modify_url_disabled); - } - break; - - case "amp_redirects": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.amp_redirects_key), true)) { - ampRedirectsPreference.setIcon(R.drawable.modify_url_enabled); - } else { - ampRedirectsPreference.setIcon(R.drawable.modify_url_disabled); - } - break; - - case "search": - // Store the new search string. - String newSearchString = sharedPreferences.getString("search", context.getString(R.string.search_default_value)); - - // Update the search and search custom URL preferences. - if (newSearchString.equals("Custom URL")) { // `Custom URL` is selected. - // Set the summary text to `R.string.custom_url`, which is translated. - searchPreference.setSummary(R.string.custom_url); - - // Enable the search custom URL preference. - searchCustomURLPreference.setEnabled(true); - - // Set the search custom URL preference icon. - searchCustomURLPreference.setIcon(R.drawable.search_custom_enabled); - } else { // `Custom URL` is not selected. - // Set the summary text to `newSearchString`. - searchPreference.setSummary(newSearchString); - - // Disable `searchCustomURLPreference`. - searchCustomURLPreference.setEnabled(false); - - // Set the search custom URL preference icon. - searchCustomURLPreference.setIcon(R.drawable.search_custom_ghosted); - } - break; - - case "search_custom_url": - // Set the new search custom URL as the summary text for the preference. - searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", context.getString(R.string.search_custom_url_default_value))); - break; - - case "proxy": - // Get current proxy string. - String currentProxyString = sharedPreferences.getString("proxy", context.getString(R.string.proxy_default_value)); - - // Update the summary text for the proxy preference. - switch (currentProxyString) { - case ProxyHelper.NONE: - proxyPreference.setSummary(context.getString(R.string.no_proxy_enabled)); - break; - - case ProxyHelper.TOR: - proxyPreference.setSummary(context.getString(R.string.tor_enabled)); - break; - - case ProxyHelper.I2P: - proxyPreference.setSummary(context.getString(R.string.i2p_enabled)); - break; - - case ProxyHelper.CUSTOM: - proxyPreference.setSummary(context.getString(R.string.custom_proxy)); - break; - } - - // Update the status of the custom URL preference. - proxyCustomUrlPreference.setEnabled(currentProxyString.equals(ProxyHelper.CUSTOM)); - - // Update the icons. - if (currentProxyString.equals(ProxyHelper.NONE)) { // Proxying is disabled. - // Set the main proxy icon to be disabled - proxyPreference.setIcon(R.drawable.proxy_disabled); - - // Set the custom proxy URL icon to be ghosted. - proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted); - } else { // Proxying is enabled. - // Set the main proxy icon to be enabled. - proxyPreference.setIcon(R.drawable.proxy_enabled); - - /// Set the custom proxy URL icon according to its status. - if (proxyCustomUrlPreference.isEnabled()) { - proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled); - } else { - proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted); - } - } - break; - - case "proxy_custom_url": - // Set the summary text for the proxy custom URL. - proxyCustomUrlPreference.setSummary(sharedPreferences.getString(context.getString(R.string.proxy_custom_url_key), context.getString(R.string.proxy_custom_url_default_value))); - break; - - case "full_screen_browsing_mode": - if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) { // Full screen browsing is enabled. - // Set the full screen browsing mode preference icon. - fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled); - - // Set the hide app bar preference icon. - if (sharedPreferences.getBoolean("hide_app_bar", true)) { - hideAppBarPreference.setIcon(R.drawable.app_bar_enabled); - } else { - hideAppBarPreference.setIcon(R.drawable.app_bar_disabled); - } - } else { // Full screen browsing is disabled. - // Update the icons. - fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled); - hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted); - } - break; - - case "hide_app_bar": - // Update the icon. - if (sharedPreferences.getBoolean("hide_app_bar", true)) { - hideAppBarPreference.setIcon(R.drawable.app_bar_enabled); - } else { // Hide app bar is disabled. - // Set the icon according to the theme. - hideAppBarPreference.setIcon(R.drawable.app_bar_disabled); - } - break; - - case "clear_everything": - // Store the new clear everything status - boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true); - - // Update the status of the clear and exit preferences. - clearCookiesPreference.setEnabled(!newClearEverythingBoolean); - clearDomStoragePreference.setEnabled(!newClearEverythingBoolean); - clearFormDataPreference.setEnabled(!newClearEverythingBoolean); // This line can be removed once the minimum API >= 26. - clearLogcatPreference.setEnabled(!newClearEverythingBoolean); - clearCachePreference.setEnabled(!newClearEverythingBoolean); - - // Update the clear everything preference icon. - if (newClearEverythingBoolean) { - clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled); - } else { - clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled); - } - - // Update the clear cookies preference icon. - if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) { - clearCookiesPreference.setIcon(R.drawable.clear_cookies_enabled); - } else { - clearCookiesPreference.setIcon(R.drawable.clear_cookies_disabled); - } - - // Update the clear dom storage preference icon. - if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) { - clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_enabled); - } else { - clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_disabled); - } - - // Update the clear form data preference icon if the API < 26. - if (Build.VERSION.SDK_INT < 26) { - if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) { - clearFormDataPreference.setIcon(R.drawable.clear_form_data_enabled); - } else { - clearFormDataPreference.setIcon(R.drawable.clear_form_data_disabled); - } - } - - // Update the clear logcat preference icon. - if (newClearEverythingBoolean || sharedPreferences.getBoolean(context.getString(R.string.clear_logcat_key), true)) { - clearLogcatPreference.setIcon(R.drawable.clear_logcat_enabled); - } else { - clearLogcatPreference.setIcon(R.drawable.clear_cache_disabled); - } - - // Update the clear cache preference icon. - if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) { - clearCachePreference.setIcon(R.drawable.clear_cache_enabled); - } else { - clearCachePreference.setIcon(R.drawable.clear_cache_disabled); - } - break; - - case "clear_cookies": - // Update the icon. - if (sharedPreferences.getBoolean("clear_cookies", true)) { - clearCookiesPreference.setIcon(R.drawable.clear_cookies_enabled); - } else { - clearCookiesPreference.setIcon(R.drawable.clear_cookies_disabled); - } - break; - - case "clear_dom_storage": - // Update the icon. - if (sharedPreferences.getBoolean("clear_dom_storage", true)) { - clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_enabled); - } else { - clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_disabled); - } - break; - - // This section can be removed once the minimum API >= 26. - case "clear_form_data": - // Update the icon. - if (sharedPreferences.getBoolean("clear_form_data", true)) { - clearFormDataPreference.setIcon(R.drawable.clear_form_data_enabled); - } else { - clearFormDataPreference.setIcon(R.drawable.clear_form_data_disabled); - } - break; - - case "clear_logcat": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.clear_logcat_key), true)) { - clearLogcatPreference.setIcon(R.drawable.clear_logcat_enabled); - } else { - clearLogcatPreference.setIcon(R.drawable.clear_logcat_disabled); - } - break; - - case "clear_cache": - // Update the icon. - if (sharedPreferences.getBoolean("clear_cache", true)) { - clearCachePreference.setIcon(R.drawable.clear_cache_enabled); - } else { - clearCachePreference.setIcon(R.drawable.clear_cache_disabled); - } - break; - - case "homepage": - // Set the new homepage URL as the summary text for the Homepage preference. - homepagePreference.setSummary(sharedPreferences.getString("homepage", context.getString(R.string.homepage_default_value))); - break; - - case "font_size": - // Update the font size summary text. - fontSizePreference.setSummary(sharedPreferences.getString(context.getString(R.string.font_size_key), context.getString(R.string.font_size_default_value)) + "%"); - break; - - case "open_intents_in_new_tab": - // Update the icon. - if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) - openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled); - else - openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled); - break; - - case "swipe_to_refresh": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.swipe_to_refresh_key), true)) - swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled); - else - swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled); - break; - - case "download_with_external_app": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.download_with_external_app_key), false)) - downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled); - else - downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled); - break; - - case "scroll_app_bar": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.scroll_app_bar_key), true)) - scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled); - else - scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled); - - break; - - case "bottom_app_bar": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.bottom_app_bar_key), false)) - bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled); - else - bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled); - - // Restart Privacy Browser. - restartPrivacyBrowser(); - break; - - case "display_additional_app_bar_icons": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.display_additional_app_bar_icons_key), false)) - displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled); - else - displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled); - break; - - case "app_theme": - // Get the new theme. - String newAppTheme = sharedPreferences.getString("app_theme", context.getString(R.string.app_theme_default_value)); - - // Declare an app theme entry number. - int appThemeEntryNumber; - - // Get the app theme entry number that matches the current app theme. A switch statement cannot be used because the theme entry values string array is not a compile time constant. - if (newAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected. - // Store the app theme entry number. - appThemeEntryNumber = 1; - } else if (newAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected. - // Store the app theme entry number. - appThemeEntryNumber = 2; - } else { // The system default theme is selected. - // Store the app theme entry number. - appThemeEntryNumber = 0; - } - - // Update the system according to the new theme. A switch statement cannot be used because the theme entry values string array is not a compile-time constant. - switch (appThemeEntryNumber) { - case 0: // The system default theme is selected. - // Update the theme preference summary text. - appThemePreference.setSummary(appThemeEntriesStringArray[0]); - - // Apply the new theme. - if (Build.VERSION.SDK_INT >= 28) { // The system default theme is supported. - // Follow the system default theme. - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); - } else {// The system default theme is not supported. - // Follow the battery saver mode. - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY); - } - break; - - case 1: // The light theme is selected. - // Update the theme preference summary text. - appThemePreference.setSummary(appThemeEntriesStringArray[1]); - - // Apply the new theme. - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); - break; - - case 2: - // Update the theme preference summary text. - appThemePreference.setSummary(appThemeEntriesStringArray[2]); - - // Apply the new theme. - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); - break; - } - - // Disable the WebView theme preference if the API >= 33 and the app theme is set to light. - webViewThemePreference.setEnabled((Build.VERSION.SDK_INT < 33) || (appThemeEntryNumber != 1)); - - // Get the WebView theme. - String webViewTheme = sharedPreferences.getString(context.getString(R.string.webview_theme_key), context.getString(R.string.webview_theme_default_value)); - - // Declare a WebView theme entry number. - int webViewThemeEntryNumber; - - // Get the webView theme entry number that matches the new WebView theme. A switch statement cannot be used because the theme entry values string array is not a compile time constant. - if (webViewTheme.equals(webViewThemeEntriesStringArray[1])) { // The light theme is selected. - // Store the WebView theme entry number. - webViewThemeEntryNumber = 1; - } else if (webViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected. - // Store the WebView theme entry number. - webViewThemeEntryNumber = 2; - } else { // The system default theme is selected. - // Store the WebView theme entry number. - webViewThemeEntryNumber = 0; - } - - // Update the WebView theme preference icon. - if (webViewThemePreference.isEnabled()) { // The WebView theme preference is enabled. - switch (webViewThemeEntryNumber) { - case 0: // The system default WebView theme is selected. - // Get the current theme status. - int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; - - // Set the icon according to the app theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) - webViewThemePreference.setIcon(R.drawable.webview_light_theme); - else - webViewThemePreference.setIcon(R.drawable.webview_dark_theme); - break; - - case 1: // The light WebView theme is selected. - // Set the icon. - webViewThemePreference.setIcon(R.drawable.webview_light_theme); - break; - - case 2: // The dark WebView theme is selected. - // Set the icon. - webViewThemePreference.setIcon(R.drawable.webview_dark_theme); - break; - } - } else { // The WebView theme preference is disabled. - webViewThemePreference.setIcon(R.drawable.webview_theme_ghosted); - } - break; - - case "webview_theme": - // Get the new WebView theme. - String newWebViewTheme = sharedPreferences.getString(context.getString(R.string.webview_theme_key), context.getString(R.string.webview_theme_default_value)); - - // Declare a new WebView theme entry number. - int newWebViewThemeEntryNumber; - - // Get the webView theme entry number that matches the new WebView theme. A switch statement cannot be used because the theme entry values string array is not a compile time constant. - if (newWebViewTheme.equals(webViewThemeEntriesStringArray[1])) { // The light theme is selected. - // Store the new WebView theme entry number. - newWebViewThemeEntryNumber = 1; - } else if (newWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected. - // Store the new WebView theme entry number. - newWebViewThemeEntryNumber = 2; - } else { // The system default theme is selected. - // Store the new WebView theme entry number. - newWebViewThemeEntryNumber = 0; - } - - // Update the icon. - switch (newWebViewThemeEntryNumber) { - case 0: // The system default WebView theme is selected. - // Get the current theme status. - int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; - - // Set the icon. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - webViewThemePreference.setIcon(R.drawable.webview_light_theme); - } else { - webViewThemePreference.setIcon(R.drawable.webview_dark_theme); - } - break; - - case 1: // The light theme is selected. - // Set the icon. - webViewThemePreference.setIcon(R.drawable.webview_light_theme); - break; - - case 2: // The dark theme is selected. - // Set the icon. - webViewThemePreference.setIcon(R.drawable.webview_dark_theme); - break; - } - - // Set the current theme as the summary text for the preference. - webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]); - break; - - case "wide_viewport": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.wide_viewport_key), true)) { - wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled); - } else { - wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled); - } - break; - - case "display_webpage_images": - // Update the icon. - if (sharedPreferences.getBoolean(context.getString(R.string.display_webpage_images_key), true)) { - displayWebpageImagesPreference.setIcon(R.drawable.images_enabled); - } else { - displayWebpageImagesPreference.setIcon(R.drawable.images_disabled); - } - break; - } - }; - } - - private void restartPrivacyBrowser() { - // Create an intent to restart Privacy Browser. - Intent restartIntent = requireActivity().getParentActivityIntent(); - - // Assert that the intent is not null to remove the lint error below. - assert restartIntent != null; - - // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`. - restartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - - // Create a handler to restart the activity. - Handler restartHandler = new Handler(Looper.getMainLooper()); - - // Create a runnable to restart the activity. - Runnable restartRunnable = () -> { - // Restart the activity. - startActivity(restartIntent); - - // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart. - System.exit(0); - }; - - // Restart the activity after 400 milliseconds, so that the app has enough time to save the change to the preference. - restartHandler.postDelayed(restartRunnable, 400); - } -} diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.kt b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.kt new file mode 100644 index 00000000..c6fb15fb --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.kt @@ -0,0 +1,1234 @@ +/* + * Copyright 2016-2022 Soren Stoutner . + * + * This file is part of Privacy Browser Android . + * + * 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 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 Android. If not, see . + */ + +package com.stoutner.privacybrowser.fragments + +import android.annotation.SuppressLint +import android.content.Intent +import android.content.SharedPreferences +import android.content.SharedPreferences.OnSharedPreferenceChangeListener +import android.content.res.Configuration +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.webkit.WebView +import android.widget.ArrayAdapter + +import androidx.appcompat.app.AppCompatDelegate +import androidx.preference.Preference +import androidx.preference.PreferenceCategory +import androidx.preference.PreferenceFragmentCompat + +import com.stoutner.privacybrowser.R +import com.stoutner.privacybrowser.activities.MainWebViewActivity +import com.stoutner.privacybrowser.helpers.ProxyHelper +import kotlin.system.exitProcess + +class SettingsFragment : PreferenceFragmentCompat() { + // Declare the class variables. + private lateinit var appThemeEntriesStringArray: Array + private lateinit var appThemeEntryValuesStringArray: Array + private lateinit var defaultUserAgent: String + private lateinit var sharedPreferenceChangeListener: OnSharedPreferenceChangeListener + private lateinit var translatedUserAgentNamesArray: Array + private lateinit var userAgentDataArray: Array + private lateinit var userAgentNamesArray: ArrayAdapter + private lateinit var webViewThemeEntriesStringArray: Array + private lateinit var webViewThemeEntryValuesStringArray: Array + + // Define the the class views. + private lateinit var javaScriptPreference: Preference + private lateinit var cookiesPreference: Preference + private lateinit var domStoragePreference: Preference + private lateinit var formDataPreference: Preference // The form data preference can be removed once the minimum API >= 26. + private lateinit var userAgentPreference: Preference + private lateinit var customUserAgentPreference: Preference + private lateinit var xRequestedWithHeaderPreference: Preference + private lateinit var incognitoModePreference: Preference + private lateinit var allowScreenshotsPreference: Preference + private lateinit var easyListPreference: Preference + private lateinit var easyPrivacyPreference: Preference + private lateinit var fanboyAnnoyanceListPreference: Preference + private lateinit var fanboySocialBlockingListPreference: Preference + private lateinit var ultraListPreference: Preference + private lateinit var ultraPrivacyPreference: Preference + private lateinit var blockAllThirdPartyRequestsPreference: Preference + private lateinit var trackingQueriesPreference: Preference + private lateinit var ampRedirectsPreference: Preference + private lateinit var searchPreference: Preference + private lateinit var searchCustomURLPreference: Preference + private lateinit var proxyPreference: Preference + private lateinit var proxyCustomUrlPreference: Preference + private lateinit var fullScreenBrowsingModePreference: Preference + private lateinit var hideAppBarPreference: Preference + private lateinit var clearEverythingPreference: Preference + private lateinit var clearCookiesPreference: Preference + private lateinit var clearDomStoragePreference: Preference + private lateinit var clearFormDataPreference: Preference // The clear form data preference can be removed once the minimum API >= 26. + private lateinit var clearLogcatPreference: Preference + private lateinit var clearCachePreference: Preference + private lateinit var homepagePreference: Preference + private lateinit var fontSizePreference: Preference + private lateinit var openIntentsInNewTabPreference: Preference + private lateinit var swipeToRefreshPreference: Preference + private lateinit var downloadWithExternalAppPreference: Preference + private lateinit var scrollAppBarPreference: Preference + private lateinit var bottomAppBarPreference: Preference + private lateinit var displayAdditionalAppBarIconsPreference: Preference + private lateinit var appThemePreference: Preference + private lateinit var webViewThemePreference: Preference + private lateinit var wideViewportPreference: Preference + private lateinit var displayWebpageImagesPreference: Preference + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + // Load the preferences from the XML file. + setPreferencesFromResource(R.xml.preferences, rootKey) + + // Get a handle for the shared preferences. + val sharedPreferences = preferenceScreen.sharedPreferences!! + + // Get handles for the preferences. + javaScriptPreference = findPreference(getString(R.string.javascript_key))!! + cookiesPreference = findPreference(getString(R.string.cookies_key))!! + domStoragePreference = findPreference(getString(R.string.dom_storage_key))!! + formDataPreference = findPreference(getString(R.string.save_form_data_key))!! // The form data preference can be removed once the minimum API >= 26. + userAgentPreference = findPreference(getString(R.string.user_agent_key))!! + customUserAgentPreference = findPreference(getString(R.string.custom_user_agent_key))!! + xRequestedWithHeaderPreference = findPreference(getString(R.string.x_requested_with_header_key))!! + incognitoModePreference = findPreference(getString(R.string.incognito_mode_key))!! + allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key))!! + easyListPreference = findPreference(getString(R.string.easylist_key))!! + easyPrivacyPreference = findPreference(getString(R.string.easyprivacy_key))!! + fanboyAnnoyanceListPreference = findPreference(getString(R.string.fanboys_annoyance_list_key))!! + fanboySocialBlockingListPreference = findPreference(getString(R.string.fanboys_social_blocking_list_key))!! + ultraListPreference = findPreference(getString(R.string.ultralist_key))!! + ultraPrivacyPreference = findPreference(getString(R.string.ultraprivacy_key))!! + blockAllThirdPartyRequestsPreference = findPreference(getString(R.string.block_all_third_party_requests_key))!! + trackingQueriesPreference = findPreference(getString(R.string.tracking_queries_key))!! + ampRedirectsPreference = findPreference(getString(R.string.amp_redirects_key))!! + searchPreference = findPreference(getString(R.string.search_key))!! + searchCustomURLPreference = findPreference(getString(R.string.search_custom_url_key))!! + proxyPreference = findPreference(getString(R.string.proxy_key))!! + proxyCustomUrlPreference = findPreference(getString(R.string.proxy_custom_url_key))!! + fullScreenBrowsingModePreference = findPreference(getString(R.string.full_screen_browsing_mode_key))!! + hideAppBarPreference = findPreference(getString(R.string.hide_app_bar_key))!! + clearEverythingPreference = findPreference(getString(R.string.clear_everything_key))!! + clearCookiesPreference = findPreference(getString(R.string.clear_cookies_key))!! + clearDomStoragePreference = findPreference(getString(R.string.clear_dom_storage_key))!! + clearFormDataPreference = findPreference(getString(R.string.clear_form_data_key))!! // The clear form data preference can be removed once the minimum API >= 26. + clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key))!! + clearCachePreference = findPreference(getString(R.string.clear_cache_key))!! + homepagePreference = findPreference(getString(R.string.homepage_key))!! + fontSizePreference = findPreference(getString(R.string.font_size_key))!! + openIntentsInNewTabPreference = findPreference(getString(R.string.open_intents_in_new_tab_key))!! + swipeToRefreshPreference = findPreference(getString(R.string.swipe_to_refresh_key))!! + downloadWithExternalAppPreference = findPreference(getString(R.string.download_with_external_app_key))!! + scrollAppBarPreference = findPreference(getString(R.string.scroll_app_bar_key))!! + bottomAppBarPreference = findPreference(getString(R.string.bottom_app_bar_key))!! + displayAdditionalAppBarIconsPreference = findPreference(getString(R.string.display_additional_app_bar_icons_key))!! + appThemePreference = findPreference(getString(R.string.app_theme_key))!! + webViewThemePreference = findPreference(getString(R.string.webview_theme_key))!! + wideViewportPreference = findPreference(getString(R.string.wide_viewport_key))!! + displayWebpageImagesPreference = findPreference(getString(R.string.display_webpage_images_key))!! + + // Set the preference dependencies. + domStoragePreference.dependency = getString(R.string.javascript_key) + hideAppBarPreference.dependency = getString(R.string.full_screen_browsing_mode_key) + + // Get strings from the preferences. + val userAgentName = sharedPreferences.getString(getString(R.string.user_agent_key), getString(R.string.user_agent_default_value)) + val searchString = sharedPreferences.getString(getString(R.string.search_key), getString(R.string.search_default_value)) + val proxyString = sharedPreferences.getString(getString(R.string.proxy_key), getString(R.string.proxy_default_value)) + + // Get booleans that are used in multiple places from the preferences. + val javaScriptEnabled = sharedPreferences.getBoolean(getString(R.string.javascript_key), false) + val fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean(getString(R.string.fanboys_annoyance_list_key), true) + val fanboySocialBlockingEnabled = sharedPreferences.getBoolean(getString(R.string.fanboys_social_blocking_list_key), true) + val fullScreenBrowsingMode = sharedPreferences.getBoolean(getString(R.string.full_screen_browsing_mode_key), false) + val clearEverything = sharedPreferences.getBoolean(getString(R.string.clear_everything_key), true) + + // Remove the form data preferences if the API is >= 26 as they no longer do anything. + if (Build.VERSION.SDK_INT >= 26) { + // Get handles for the categories. + val privacyCategory = findPreference(getString(R.string.privacy_category_key))!! + val clearAndExitCategory = findPreference(getString(R.string.clear_and_exit_category_key))!! + + // Remove the form data preferences. + privacyCategory.removePreference(formDataPreference) + clearAndExitCategory.removePreference(clearFormDataPreference) + } + + // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled. + fanboySocialBlockingListPreference.isEnabled = !fanboyAnnoyanceListEnabled + + + // Inflate a WebView to get the default user agent. + val inflater = requireActivity().layoutInflater + + // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because the `bare_webview` will not be displayed. + @SuppressLint("InflateParams") val bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false) + + // Get a handle for the bare WebView. + val bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview) + + // Get the default user agent. + defaultUserAgent = bareWebView.settings.userAgentString + + // Get the user agent arrays. + userAgentNamesArray = ArrayAdapter.createFromResource(requireContext(), R.array.user_agent_names, R.layout.spinner_item) + translatedUserAgentNamesArray = resources.getStringArray(R.array.translated_user_agent_names) + userAgentDataArray = resources.getStringArray(R.array.user_agent_data) + + // Populate the user agent summary. + when (val userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName)) { + // The user agent name is not on the canonical list. + // This is probably because it was set in an older version of Privacy Browser before the switch to persistent user agent names. Use the current user agent entry name as the summary. + MainWebViewActivity.UNRECOGNIZED_USER_AGENT -> userAgentPreference.summary = userAgentName + + // Get the user agent text from the webview (which changes based on the version of Android and WebView installed). + MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> userAgentPreference.summary = "${translatedUserAgentNamesArray[userAgentArrayPosition]}:\n$defaultUserAgent" + + // Display the custom user agent. + MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT -> userAgentPreference.setSummary(R.string.custom_user_agent) + + // Get the user agent summary from the user agent data array. + else -> userAgentPreference.summary = "${translatedUserAgentNamesArray[userAgentArrayPosition]}:\n${userAgentDataArray[userAgentArrayPosition]}" + } + + // Set the summary text for the custom user agent preference. + customUserAgentPreference.summary = sharedPreferences.getString(getString(R.string.custom_user_agent_key), getString(R.string.custom_user_agent_default_value)) + + // Only enable the custom user agent preference if the user agent is set to custom. + customUserAgentPreference.isEnabled = (userAgentPreference.summary == getString(R.string.custom_user_agent)) + + // Set the search URL as the summary text for the search preference when the preference screen is loaded. + if (searchString == getString(R.string.custom_url_item)) { + // Use R.string.custom_url, which will be translated, instead of the array value, which will not. + searchPreference.setSummary(R.string.custom_url) + } else { + // Set the array value as the summary text. + searchPreference.summary = searchString + } + + // Set the summary text for the search custom URL (the default is `""`). + searchCustomURLPreference.summary = sharedPreferences.getString(getString(R.string.search_custom_url_key), getString(R.string.search_custom_url_default_value)) + + // Only enable the search custom URL preference if the search is set to a custom URL. + searchCustomURLPreference.isEnabled = (searchString == getString(R.string.custom_url_item)) + + // Set the summary text for the proxy preference. + proxyPreference.summary = when (proxyString) { + ProxyHelper.NONE -> getString(R.string.no_proxy_enabled) + ProxyHelper.TOR -> getString(R.string.tor_enabled) + ProxyHelper.I2P -> getString(R.string.i2p_enabled) + ProxyHelper.CUSTOM -> getString(R.string.custom_proxy) + else -> getString(R.string.no_proxy_enabled) + } + + // Set the summary text for the custom proxy URL. + proxyCustomUrlPreference.summary = sharedPreferences.getString(getString(R.string.proxy_custom_url_key), getString(R.string.proxy_custom_url_default_value)) + + // Only enable the custom proxy URL if a custom proxy is selected. + proxyCustomUrlPreference.isEnabled = proxyString == ProxyHelper.CUSTOM + + // Set the status of the clear and exit preferences. + clearCookiesPreference.isEnabled = !clearEverything + clearDomStoragePreference.isEnabled = !clearEverything + clearFormDataPreference.isEnabled = !clearEverything // Clear form data can be removed once the minimum API is >= 26. + clearLogcatPreference.isEnabled = !clearEverything + clearCachePreference.isEnabled = !clearEverything + + // Set the homepage URL as the summary text for the homepage preference. + homepagePreference.summary = sharedPreferences.getString(getString(R.string.homepage_key), getString(R.string.homepage_default_value)) + + // Set the font size as the summary text for the preference. + fontSizePreference.summary = sharedPreferences.getString(getString(R.string.font_size_key), getString(R.string.font_size_default_value)) + "%" + + // Get the app theme string arrays. + appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries) + appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values) + + // Get the app theme entry number that matches the current app theme. + val appThemeEntryNumber: Int = when (sharedPreferences.getString(getString(R.string.app_theme_key), getString(R.string.app_theme_default_value))) { + appThemeEntryValuesStringArray[1] -> 1 // The light theme is selected. + appThemeEntryValuesStringArray[2] -> 2 // The dark theme is selected. + else -> 0 // The system default theme is selected. + } + + // Set the current theme as the summary text for the preference. + appThemePreference.summary = appThemeEntriesStringArray[appThemeEntryNumber] + + // Enable the WebView theme preference if the API < 33 or the app theme is not set to light. Google no longer allows light themes to display dark WebViews. + webViewThemePreference.isEnabled = ((Build.VERSION.SDK_INT < 33) || (appThemeEntryNumber != 1)) + + // Get the WebView theme string arrays. + webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries) + webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values) + + // Get the WebView theme entry number that matches the current WebView theme. + val webViewThemeEntryNumber: Int = when (sharedPreferences.getString(getString(R.string.webview_theme_key), getString(R.string.webview_theme_default_value))) { + webViewThemeEntryValuesStringArray[1] -> 1 // The light theme is selected. + webViewThemeEntryValuesStringArray[2] -> 2 // The dark theme is selected. + else -> 0 // The system default theme is selected. + } + + // Set the current theme as the summary text for the preference. + webViewThemePreference.summary = webViewThemeEntriesStringArray[webViewThemeEntryNumber] + + // Set the JavaScript icon. + if (javaScriptEnabled) + javaScriptPreference.setIcon(R.drawable.javascript_enabled) + else + javaScriptPreference.setIcon(R.drawable.privacy_mode) + + // Set the cookies icon. + if (sharedPreferences.getBoolean(getString(R.string.cookies_key), false)) + cookiesPreference.setIcon(R.drawable.cookies_enabled) + else + cookiesPreference.setIcon(R.drawable.cookies_disabled) + + // Set the DOM storage icon. + if (javaScriptEnabled) { // JavaScript is enabled. + if (sharedPreferences.getBoolean(getString(R.string.dom_storage_key), false)) // DOM storage is enabled. + domStoragePreference.setIcon(R.drawable.dom_storage_enabled) + else // DOM storage is disabled. + domStoragePreference.setIcon(R.drawable.dom_storage_disabled) + } else { // JavaScript is disabled. DOM storage should be ghosted. + domStoragePreference.setIcon(R.drawable.dom_storage_ghosted) + } + + // Set the save form data icon if API < 26. Save form data has no effect on API >= 26. + if (Build.VERSION.SDK_INT < 26) { + if (sharedPreferences.getBoolean(getString(R.string.save_form_data_key), false)) + formDataPreference.setIcon(R.drawable.form_data_enabled) + else + formDataPreference.setIcon(R.drawable.form_data_disabled) + } + + // Set the custom user agent icon. + if (customUserAgentPreference.isEnabled) + customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled) + else + customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted) + + // Set the X-Requested With header icon. + if (sharedPreferences.getBoolean(getString(R.string.x_requested_with_header_key), true)) + xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_enabled) + else + xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_disabled) + + // Set the incognito mode icon. + if (sharedPreferences.getBoolean(getString(R.string.incognito_mode_key), false)) + incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled) + else + incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled) + + // Set the allow screenshots icon. + if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled) + else + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled) + + // Set the EasyList icon. + if (sharedPreferences.getBoolean(getString(R.string.easylist_key), true)) + easyListPreference.setIcon(R.drawable.block_ads_enabled) + else + easyListPreference.setIcon(R.drawable.block_ads_disabled) + + // Set the EasyPrivacy icon. + if (sharedPreferences.getBoolean(getString(R.string.easyprivacy_key), true)) + easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled) + else + easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled) + + // Set the Fanboy lists icons. + if (fanboyAnnoyanceListEnabled) { + // Set the Fanboy annoyance list icon. + fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled) + + // Set the Fanboy social blocking list icon. + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted) + } else { + // Set the Fanboy annoyance list icon. + fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled) + + // Set the Fanboy social blocking list icon. + if (fanboySocialBlockingEnabled) + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled) + else + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled) + } + + // Set the UltraList icon. + if (sharedPreferences.getBoolean(getString(R.string.ultralist_key), true)) + ultraListPreference.setIcon(R.drawable.block_ads_enabled) + else + ultraListPreference.setIcon(R.drawable.block_ads_disabled) + + // Set the UltraPrivacy icon. + if (sharedPreferences.getBoolean(getString(R.string.ultraprivacy_key), true)) + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled) + else + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled) + + // Set the block all third-party requests icon. + if (sharedPreferences.getBoolean(getString(R.string.block_all_third_party_requests), false)) + blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled) + else + blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled) + + // Set the Tracking Queries icon. + if (sharedPreferences.getBoolean(getString(R.string.tracking_queries_key), true)) + trackingQueriesPreference.setIcon(R.drawable.modify_url_enabled) + else + trackingQueriesPreference.setIcon(R.drawable.modify_url_disabled) + + // Set the AMP Redirects icon. + if (sharedPreferences.getBoolean(getString(R.string.amp_redirects_key), true)) + ampRedirectsPreference.setIcon(R.drawable.modify_url_enabled) + else + ampRedirectsPreference.setIcon(R.drawable.modify_url_disabled) + + // Set the search custom URL icon. + if (searchCustomURLPreference.isEnabled) + searchCustomURLPreference.setIcon(R.drawable.search_custom_enabled) + else + searchCustomURLPreference.setIcon(R.drawable.search_custom_ghosted) + + // Set the proxy icons according to the theme and status. + if (proxyString == ProxyHelper.NONE) { // Proxying is disabled. + // Set the main proxy icon to be disabled. + proxyPreference.setIcon(R.drawable.proxy_disabled) + + // Set the custom proxy URL icon to be ghosted. + proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted) + } else { // Proxying is enabled. + // Set the main proxy icon to be enabled. + proxyPreference.setIcon(R.drawable.proxy_enabled) + + // Set the custom proxy URL icon according to its status. + if (proxyCustomUrlPreference.isEnabled) + proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled) + else + proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted) + } + + // Set the full-screen browsing mode icons. + if (fullScreenBrowsingMode) { // Full-screen browsing mode is enabled. + // Set the full screen browsing mode preference icon. + fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled) + + // Set the hide app bar icon. + if (sharedPreferences.getBoolean(getString(R.string.hide_app_bar_key), true)) + hideAppBarPreference.setIcon(R.drawable.app_bar_enabled) + else + hideAppBarPreference.setIcon(R.drawable.app_bar_disabled) + } else { // Full screen browsing mode is disabled. + // Set the icons. + fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled) + hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted) + } + + // Set the clear everything icon. + if (clearEverything) { + clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled) + } else { + clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled) + } + + // Set the clear cookies icon. + if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_cookies_key), true)) + clearCookiesPreference.setIcon(R.drawable.clear_cookies_enabled) + else + clearCookiesPreference.setIcon(R.drawable.clear_cookies_disabled) + + // Set the clear DOM storage icon. + if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_dom_storage_key), true)) + clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_enabled) + else + clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_disabled) + + // Set the clear form data icon if the API < 26. It has no effect on newer versions of Android. + if (Build.VERSION.SDK_INT < 26) { + if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_form_data_key), true)) + clearFormDataPreference.setIcon(R.drawable.clear_form_data_enabled) + else + clearFormDataPreference.setIcon(R.drawable.clear_form_data_disabled) + } + + // Set the clear logcat icon. + if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) + clearLogcatPreference.setIcon(R.drawable.clear_logcat_enabled) + else + clearLogcatPreference.setIcon(R.drawable.clear_logcat_disabled) + + // Set the clear cache icon. + if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_cache_key), true)) + clearCachePreference.setIcon(R.drawable.clear_cache_enabled) + else + clearCachePreference.setIcon(R.drawable.clear_cache_disabled) + + // Set the open intents in new tab icon. + if (sharedPreferences.getBoolean(getString(R.string.open_intents_in_new_tab_key), true)) + openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled) + else + openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled) + + // Set the swipe to refresh icon. + if (sharedPreferences.getBoolean(getString(R.string.swipe_to_refresh_key), true)) + swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled) + else + swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled) + + // Set the download with external app icon. + if (sharedPreferences.getBoolean(getString(R.string.download_with_external_app_key), false)) + downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled) + else + downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled) + + // Set the scroll app bar icon. + if (sharedPreferences.getBoolean(getString(R.string.scroll_app_bar_key), true)) + scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled) + else + scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled) + + // Set the bottom app bar icon. + if (sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)) + bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled) + else + bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled) + + // Set the display additional app bar icons icon. + if (sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false)) + displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled) + else + displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled) + + // Set the WebView theme icon. + if (webViewThemePreference.isEnabled) { // The WebView theme preference is enabled. + when (webViewThemeEntryNumber) { + // The system default WebView theme is selected. + 0 -> { + // Get the current theme status. + val currentThemeStatus = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) + webViewThemePreference.setIcon(R.drawable.webview_light_theme) + else + webViewThemePreference.setIcon(R.drawable.webview_dark_theme) + } + + // The light WebView theme is selected. + 1 -> { + // Set the icon. + webViewThemePreference.setIcon(R.drawable.webview_light_theme) + } + + // The dark WebView theme is selected. + 2 -> { + // Set the icon. + webViewThemePreference.setIcon(R.drawable.webview_dark_theme) + } + } + } else { // The WebView theme preference is disabled. + webViewThemePreference.setIcon(R.drawable.webview_theme_ghosted) + } + + // Set the wide viewport icon. + if (sharedPreferences.getBoolean(getString(R.string.wide_viewport_key), true)) + wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled) + else + wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled) + + // Set the display webpage images icon. + if (sharedPreferences.getBoolean(getString(R.string.display_webpage_images_key), true)) + displayWebpageImagesPreference.setIcon(R.drawable.images_enabled) + else + displayWebpageImagesPreference.setIcon(R.drawable.images_disabled) + } + + // The listener should be unregistered when the app is paused. + override fun onPause() { + // Run the default commands. + super.onPause() + + // Get a handle for the shared preferences. + val sharedPreferences = preferenceScreen.sharedPreferences!! + + // Unregister the shared preference listener. + sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener) + } + + // The listener should be re-registered when the app is resumed. + override fun onResume() { + // Run the default commands. + super.onResume() + + // Get a new shared preference change listener. + sharedPreferenceChangeListener = getSharedPreferenceChangeListener() + + // Get a handle for the shared preferences. + val sharedPreferences = preferenceScreen.sharedPreferences!! + + // Re-register the shared preference listener. + sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener) + } + + private fun getSharedPreferenceChangeListener(): OnSharedPreferenceChangeListener { + // Return the shared preference change listener. + return OnSharedPreferenceChangeListener { sharedPreferences: SharedPreferences, key: String? -> + when (key) { + getString(R.string.javascript_key) -> { + // Update the icons and the DOM storage preference status. + if (sharedPreferences.getBoolean(getString(R.string.javascript_key), false)) { // The JavaScript preference is enabled. + // Update the icon for the JavaScript preference. + javaScriptPreference.setIcon(R.drawable.javascript_enabled) + + // Update the status of the DOM storage preference. + domStoragePreference.isEnabled = true + + // Update the icon for the DOM storage preference. + if (sharedPreferences.getBoolean(getString(R.string.dom_storage_key), false)) + domStoragePreference.setIcon(R.drawable.dom_storage_enabled) + else + domStoragePreference.setIcon(R.drawable.dom_storage_disabled) + } else { // The JavaScript preference is disabled. + // Update the icon for the JavaScript preference. + javaScriptPreference.setIcon(R.drawable.privacy_mode) + + // Update the status of the DOM storage preference. + domStoragePreference.isEnabled = false + + // Set the icon for DOM storage preference to be ghosted. + domStoragePreference.setIcon(R.drawable.dom_storage_ghosted) + } + } + + getString(R.string.cookies_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.cookies_key), false)) + cookiesPreference.setIcon(R.drawable.cookies_enabled) + else + cookiesPreference.setIcon(R.drawable.cookies_disabled) + } + + getString(R.string.dom_storage_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.dom_storage_key), false)) + domStoragePreference.setIcon(R.drawable.dom_storage_enabled) + else + domStoragePreference.setIcon(R.drawable.dom_storage_disabled) + } + + getString(R.string.save_form_data_key) -> { // Saved form data can be removed once the minimum API >= 26. + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.save_form_data_key), false)) + formDataPreference.setIcon(R.drawable.form_data_enabled) + else + formDataPreference.setIcon(R.drawable.form_data_disabled) + } + + getString(R.string.user_agent_key) -> { + // Get the new user agent name. + val newUserAgentName = sharedPreferences.getString(getString(R.string.user_agent_key), getString(R.string.user_agent_default_value)) + + // Get the array position for the new user agent name. + val newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName) + + // Get the translated new user agent name. + val translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition] + + // Populate the user agent summary. + when (newUserAgentArrayPosition) { + MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> { + // Get the user agent text from the webview (which changes based on the version of Android and WebView installed). + userAgentPreference.summary = "$translatedNewUserAgentName:\n$defaultUserAgent" + + // Disable the custom user agent preference. + customUserAgentPreference.isEnabled = false + + // Set the custom user agent preference icon. + customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted) + } + + MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT -> { + // Set the summary text. + userAgentPreference.setSummary(R.string.custom_user_agent) + + // Enable the custom user agent preference. + customUserAgentPreference.isEnabled = true + + // Set the custom user agent preference icon. + customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled) + } + + else -> { + // Get the user agent summary from the user agent data array. + userAgentPreference.summary = "$translatedNewUserAgentName:\n${userAgentDataArray[newUserAgentArrayPosition]}" + + // Disable the custom user agent preference. + customUserAgentPreference.isEnabled = false + + // Set the custom user agent preference icon. + customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted) + } + } + } + + getString(R.string.custom_user_agent_key) -> { + // Set the new custom user agent as the summary text for the preference. + customUserAgentPreference.summary = sharedPreferences.getString(getString(R.string.custom_user_agent_key), getString(R.string.custom_user_agent_default_value)) + } + + getString(R.string.x_requested_with_header_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.x_requested_with_header_key), true)) + xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_enabled) + else + xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_disabled) + + // Restart Privacy Browser. + restartPrivacyBrowser() + } + + getString(R.string.incognito_mode_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.incognito_mode_key), false)) + incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled) + else + incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled) + } + + getString(R.string.allow_screenshots_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled) + else + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled) + + // Restart Privacy Browser. + restartPrivacyBrowser() + } + + getString(R.string.easylist_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.easylist_key), true)) + easyListPreference.setIcon(R.drawable.block_ads_enabled) + else + easyListPreference.setIcon(R.drawable.block_ads_disabled) + } + + getString(R.string.easyprivacy_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.easyprivacy_key), true)) + easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled) + else + easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled) + } + + getString(R.string.fanboys_annoyance_list_key) -> { + // Get the current Fanboy settings. + val currentFanboyAnnoyanceList = sharedPreferences.getBoolean(getString(R.string.fanboys_annoyance_list_key), true) + val currentFanboySocialBlockingList = sharedPreferences.getBoolean(getString(R.string.fanboys_social_blocking_list_key), true) + + // Update the Fanboy icons. + if (currentFanboyAnnoyanceList) { // Fanboy's annoyance list is enabled. + // Update the Fanboy's annoyance list icon. + fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled) + + // Update the Fanboy's social blocking list icon. + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted) + } else { // Fanboy's annoyance list is disabled. + // Update the Fanboy's annoyance list icon. + fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled) + + // Update the Fanboy's social blocking list icon. + if (currentFanboySocialBlockingList) + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled) + else + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled) + } + + // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled. + fanboySocialBlockingListPreference.isEnabled = !currentFanboyAnnoyanceList + } + + getString(R.string.fanboys_social_blocking_list_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.fanboys_social_blocking_list_key), true)) + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled) + else + fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled) + } + + getString(R.string.ultralist_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.ultralist_key), true)) + ultraListPreference.setIcon(R.drawable.block_ads_enabled) + else + ultraListPreference.setIcon(R.drawable.block_ads_disabled) + } + + getString(R.string.ultraprivacy_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.ultraprivacy_key), true)) + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled) + else + ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled) + } + + getString(R.string.block_all_third_party_requests_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.block_all_third_party_requests_key), false)) { + blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled) + } else { + blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled) + } + } + + getString(R.string.tracking_queries_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.tracking_queries_key), true)) + trackingQueriesPreference.setIcon(R.drawable.modify_url_enabled) + else + trackingQueriesPreference.setIcon(R.drawable.modify_url_disabled) + } + + getString(R.string.amp_redirects_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.amp_redirects_key), true)) + ampRedirectsPreference.setIcon(R.drawable.modify_url_enabled) + else + ampRedirectsPreference.setIcon(R.drawable.modify_url_disabled) + } + + getString(R.string.search_key) -> { + // Store the new search string. + val newSearchString = sharedPreferences.getString(getString(R.string.search_key), getString(R.string.search_default_value)) + + // Update the search and search custom URL preferences. + if (newSearchString == getString(R.string.custom_url_item)) { // A custom URL is selected. + // Set the summary text to `R.string.custom_url`, which is translated. + searchPreference.setSummary(R.string.custom_url) + + // Enable the search custom URL preference. + searchCustomURLPreference.isEnabled = true + + // Set the search custom URL preference icon. + searchCustomURLPreference.setIcon(R.drawable.search_custom_enabled) + } else { // A custom URL is not selected. + // Set the summary text to the new search string. + searchPreference.summary = newSearchString + + // Disable the search custom URL Preference. + searchCustomURLPreference.isEnabled = false + + // Set the search custom URL preference icon. + searchCustomURLPreference.setIcon(R.drawable.search_custom_ghosted) + } + } + + getString(R.string.search_custom_url_key) -> { + // Set the new search custom URL as the summary text for the preference. + searchCustomURLPreference.summary = sharedPreferences.getString(getString(R.string.search_custom_url_key), getString(R.string.search_custom_url_default_value)) + } + + getString(R.string.proxy_key) -> { + // Get the current proxy string. + val currentProxyString = sharedPreferences.getString(getString(R.string.proxy_key), getString(R.string.proxy_default_value)) + + // Update the proxy preference summary text. + proxyPreference.summary = when (currentProxyString) { + ProxyHelper.NONE -> getString(R.string.no_proxy_enabled) + ProxyHelper.TOR -> getString(R.string.tor_enabled) + ProxyHelper.I2P -> getString(R.string.i2p_enabled) + ProxyHelper.CUSTOM -> getString(R.string.custom_proxy) + else -> getString(R.string.no_proxy_enabled) + } + + // Update the status of the custom URL preference. + proxyCustomUrlPreference.isEnabled = currentProxyString == ProxyHelper.CUSTOM + + // Update the icons. + if (currentProxyString == ProxyHelper.NONE) { // Proxying is disabled. + // Set the main proxy icon to be disabled + proxyPreference.setIcon(R.drawable.proxy_disabled) + + // Set the custom proxy URL icon to be ghosted. + proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted) + } else { // Proxying is enabled. + // Set the main proxy icon to be enabled. + proxyPreference.setIcon(R.drawable.proxy_enabled) + + /// Set the custom proxy URL icon according to its status. + if (proxyCustomUrlPreference.isEnabled) + proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled) + else + proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted) + } + } + + getString(R.string.proxy_custom_url_key) -> { + // Set the summary text for the proxy custom URL. + proxyCustomUrlPreference.summary = sharedPreferences.getString(getString(R.string.proxy_custom_url_key), getString(R.string.proxy_custom_url_default_value)) + } + + getString(R.string.full_screen_browsing_mode_key) -> { + // Update the icons. + if (sharedPreferences.getBoolean(getString(R.string.full_screen_browsing_mode_key), false)) { // Full screen browsing is enabled. + // Set the full screen browsing mode preference icon. + fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled) + + // Set the hide app bar preference icon. + if (sharedPreferences.getBoolean(getString(R.string.hide_app_bar_key), true)) + hideAppBarPreference.setIcon(R.drawable.app_bar_enabled) + else + hideAppBarPreference.setIcon(R.drawable.app_bar_disabled) + } else { // Full screen browsing is disabled. + // Update the icons. + fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled) + hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted) + } + } + + getString(R.string.hide_app_bar_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.hide_app_bar_key), true)) + hideAppBarPreference.setIcon(R.drawable.app_bar_enabled) + else + hideAppBarPreference.setIcon(R.drawable.app_bar_disabled) + } + + getString(R.string.clear_everything_key) -> { + // Store the new clear everything status + val newClearEverythingBoolean = sharedPreferences.getBoolean(getString(R.string.clear_everything_key), true) + + // Update the status of the clear and exit preferences. + clearCookiesPreference.isEnabled = !newClearEverythingBoolean + clearDomStoragePreference.isEnabled = !newClearEverythingBoolean + clearFormDataPreference.isEnabled = !newClearEverythingBoolean // Clear form data can be removed once the minimum API >= 26. + clearLogcatPreference.isEnabled = !newClearEverythingBoolean + clearCachePreference.isEnabled = !newClearEverythingBoolean + + // Update the clear everything preference icon. + if (newClearEverythingBoolean) + clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled) + else + clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled) + + // Update the clear cookies preference icon. + if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_cookies_key), true)) + clearCookiesPreference.setIcon(R.drawable.clear_cookies_enabled) + else + clearCookiesPreference.setIcon(R.drawable.clear_cookies_disabled) + + // Update the clear dom storage preference icon. + if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_dom_storage_key), true)) + clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_enabled) + else + clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_disabled) + + // Update the clear form data preference icon if the API < 26. + if (Build.VERSION.SDK_INT < 26) { + if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_form_data_key), true)) + clearFormDataPreference.setIcon(R.drawable.clear_form_data_enabled) + else + clearFormDataPreference.setIcon(R.drawable.clear_form_data_disabled) + } + + // Update the clear logcat preference icon. + if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) + clearLogcatPreference.setIcon(R.drawable.clear_logcat_enabled) + else + clearLogcatPreference.setIcon(R.drawable.clear_logcat_disabled) + + // Update the clear cache preference icon. + if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_cache_key), true)) + clearCachePreference.setIcon(R.drawable.clear_cache_enabled) + else + clearCachePreference.setIcon(R.drawable.clear_cache_disabled) + } + + getString(R.string.clear_cookies_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.clear_cookies_key), true)) + clearCookiesPreference.setIcon(R.drawable.clear_cookies_enabled) + else + clearCookiesPreference.setIcon(R.drawable.clear_cookies_disabled) + } + + getString(R.string.clear_dom_storage_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.clear_dom_storage_key), true)) + clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_enabled) + else + clearDomStoragePreference.setIcon(R.drawable.clear_dom_storage_disabled) + } + + getString(R.string.clear_form_data_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.clear_form_data_key), true)) + clearFormDataPreference.setIcon(R.drawable.clear_form_data_enabled) + else + clearFormDataPreference.setIcon(R.drawable.clear_form_data_disabled) + } + + getString(R.string.clear_logcat_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) + clearLogcatPreference.setIcon(R.drawable.clear_logcat_enabled) + else + clearLogcatPreference.setIcon(R.drawable.clear_logcat_disabled) + } + + getString(R.string.clear_cache_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.clear_cache_key), true)) + clearCachePreference.setIcon(R.drawable.clear_cache_enabled) + else + clearCachePreference.setIcon(R.drawable.clear_cache_disabled) + } + + getString(R.string.homepage_key) -> { + // Set the new homepage URL as the summary text for the Homepage preference. + homepagePreference.summary = sharedPreferences.getString(getString(R.string.homepage_key), getString(R.string.homepage_default_value)) + } + + getString(R.string.font_size_key) -> { + // Update the font size summary text. + fontSizePreference.summary = sharedPreferences.getString(getString(R.string.font_size_key), getString(R.string.font_size_default_value)) + "%" + } + + getString(R.string.open_intents_in_new_tab_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.open_intents_in_new_tab_key), true)) + openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled) + else + openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled) + } + + getString(R.string.swipe_to_refresh_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.swipe_to_refresh_key), true)) + swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled) + else + swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled) + } + + getString(R.string.download_with_external_app_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.download_with_external_app_key), false)) + downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled) + else + downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled) + } + + getString(R.string.scroll_app_bar_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.scroll_app_bar_key), true)) + scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled) + else + scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled) + } + + getString(R.string.bottom_app_bar_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)) + bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled) + else + bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled) + + // Restart Privacy Browser. + restartPrivacyBrowser() + } + + getString(R.string.display_additional_app_bar_icons_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false)) + displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled) + else + displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled) + } + + getString(R.string.app_theme_key) -> { + // Get the app theme entry number that matches the current app theme. A switch statement cannot be used because the theme entry values string array is not a compile time constant. + val appThemeEntryNumber: Int = when (sharedPreferences.getString(getString(R.string.app_theme_key), getString(R.string.app_theme_default_value))) { + appThemeEntryValuesStringArray[1] -> 1 // The light theme is selected. + appThemeEntryValuesStringArray[2] -> 2 // The dark theme is selected. + else -> 0 // The system default theme is selected. + } + + // Update the system according to the new theme. + when (appThemeEntryNumber) { + 0 -> { // The system default theme is selected. + // Update the theme preference summary text. + appThemePreference.summary = appThemeEntriesStringArray[0] + + // Apply the new theme. + if (Build.VERSION.SDK_INT >= 28) { // The system default theme is supported. + // Follow the system default theme. + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) + } else { // The system default theme is not supported. + // Follow the battery saver mode. + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY) + } + } + + 1 -> { // The light theme is selected. + // Update the theme preference summary text. + appThemePreference.summary = appThemeEntriesStringArray[1] + + // Apply the new theme. + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) + } + + 2 -> { // The dark theme is selected. + // Update the theme preference summary text. + appThemePreference.summary = appThemeEntriesStringArray[2] + + // Apply the new theme. + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) + } + } + + // Enable the WebView theme preference if the API < 33 or the app theme is set to light. + webViewThemePreference.isEnabled = ((Build.VERSION.SDK_INT < 33) || (appThemeEntryNumber != 1)) + + // Get the webView theme entry number that matches the new WebView theme. + val webViewThemeEntryNumber: Int = when (sharedPreferences.getString(getString(R.string.webview_theme_key), getString(R.string.webview_theme_default_value))) { + webViewThemeEntriesStringArray[1] -> 1 // The light theme is selected. + webViewThemeEntryValuesStringArray[2] -> 2 // The dark theme is selected. + else -> 0 // The system default theme is selected. + } + + // Update the WebView theme icon. + if (webViewThemePreference.isEnabled) { // The WebView theme preference is enabled. + when (webViewThemeEntryNumber) { + // The system default WebView theme is selected. + 0 -> { + // Get the current theme status. + val currentThemeStatus = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) + webViewThemePreference.setIcon(R.drawable.webview_light_theme) + else + webViewThemePreference.setIcon(R.drawable.webview_dark_theme) + } + + // The light WebView theme is selected. + 1 -> { + // Set the icon. + webViewThemePreference.setIcon(R.drawable.webview_light_theme) + } + + // The dark WebView theme is selected. + 2 -> { + // Set the icon. + webViewThemePreference.setIcon(R.drawable.webview_dark_theme) + } + } + } else { // The WebView theme preference is disabled. + webViewThemePreference.setIcon(R.drawable.webview_theme_ghosted) + } + } + + getString(R.string.webview_theme_key) -> { + // Get the webView theme entry number that matches the new WebView theme. + val newWebViewThemeEntryNumber: Int = when (sharedPreferences.getString(getString(R.string.webview_theme_key), getString(R.string.webview_theme_default_value))) { + webViewThemeEntriesStringArray[1] -> 1 // The light theme is selected. + webViewThemeEntryValuesStringArray[2] -> 2 // The dark theme is selected. + else -> 0 // The system default theme is selected. + } + + // Update the WebView theme icon. + when (newWebViewThemeEntryNumber) { + // The system default WebView theme is selected. + 0 -> { + // Get the current theme status. + val currentThemeStatus = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + + // Set the icon. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) + webViewThemePreference.setIcon(R.drawable.webview_light_theme) + else + webViewThemePreference.setIcon(R.drawable.webview_dark_theme) + } + + // The light WebView theme is selected. + 1 -> { + // Set the icon. + webViewThemePreference.setIcon(R.drawable.webview_light_theme) + } + + // The dark WebView theme is selected. + 2 -> { + // Set the icon. + webViewThemePreference.setIcon(R.drawable.webview_dark_theme) + } + } + + // Set the current theme as the summary text for the preference. + webViewThemePreference.summary = webViewThemeEntriesStringArray[newWebViewThemeEntryNumber] + } + + getString(R.string.wide_viewport_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.wide_viewport_key), true)) + wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled) + else + wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled) + } + + getString(R.string.display_webpage_images_key) -> { + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.display_webpage_images_key), true)) + displayWebpageImagesPreference.setIcon(R.drawable.images_enabled) + else + displayWebpageImagesPreference.setIcon(R.drawable.images_disabled) + } + } + } + } + + private fun restartPrivacyBrowser() { + // Create an intent to restart Privacy Browser. + val restartIntent = requireActivity().parentActivityIntent!! + + // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`. + restartIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + + // Create a handler to restart the activity. + val restartHandler = Handler(Looper.getMainLooper()) + + // Create a runnable to restart the activity. + val restartRunnable = Runnable { + // Restart the activity. + startActivity(restartIntent) + + // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart. + exitProcess(0) + } + + // Restart the activity after 400 milliseconds, so that the app has enough time to save the change to the preference. + restartHandler.postDelayed(restartRunnable, 400) + } +} diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.kt b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.kt index c5401d45..98969343 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.kt @@ -318,17 +318,17 @@ class DomainsDatabaseHelper(private val appContext: Context) : SQLiteOpenHelper( val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext) // Get the default settings. - val javaScript = sharedPreferences.getBoolean("javascript", false) + val javaScript = sharedPreferences.getBoolean(appContext.getString(R.string.javascript_key), false) val cookies = sharedPreferences.getBoolean(appContext.getString(R.string.cookies_key), false) - val domStorage = sharedPreferences.getBoolean("dom_storage", false) - val saveFormData = sharedPreferences.getBoolean("save_form_data", false) // Form data can be removed once the minimum API >= 26. - val easyList = sharedPreferences.getBoolean("easylist", true) - val easyPrivacy = sharedPreferences.getBoolean("easyprivacy", true) - val fanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true) - val fanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true) - val ultraList = sharedPreferences.getBoolean("ultralist", true) - val ultraPrivacy = sharedPreferences.getBoolean("ultraprivacy", true) - val blockAllThirdPartyRequests = sharedPreferences.getBoolean("block_all_third_party_requests", false) + val domStorage = sharedPreferences.getBoolean(appContext.getString(R.string.dom_storage_key), false) + val saveFormData = sharedPreferences.getBoolean(appContext.getString(R.string.save_form_data_key), false) // Form data can be removed once the minimum API >= 26. + val easyList = sharedPreferences.getBoolean(appContext.getString(R.string.easylist_key), true) + val easyPrivacy = sharedPreferences.getBoolean(appContext.getString(R.string.easyprivacy_key), true) + val fanboyAnnoyanceList = sharedPreferences.getBoolean(appContext.getString(R.string.fanboys_annoyance_list_key), true) + val fanboySocialBlockingList = sharedPreferences.getBoolean(appContext.getString(R.string.fanboys_social_blocking_list_key), true) + val ultraList = sharedPreferences.getBoolean(appContext.getString(R.string.ultralist_key), true) + val ultraPrivacy = sharedPreferences.getBoolean(appContext.getString(R.string.ultraprivacy_key), true) + val blockAllThirdPartyRequests = sharedPreferences.getBoolean(appContext.getString(R.string.block_all_third_party_requests_key), false) // Create entries for the database fields. The ID is created automatically. The pinned SSL certificate information is not created unless added by the user. domainContentValues.put(DOMAIN_NAME, domainName) @@ -343,7 +343,7 @@ class DomainsDatabaseHelper(private val appContext: Context) : SQLiteOpenHelper( domainContentValues.put(ULTRALIST, ultraList) domainContentValues.put(ENABLE_ULTRAPRIVACY, ultraPrivacy) domainContentValues.put(BLOCK_ALL_THIRD_PARTY_REQUESTS, blockAllThirdPartyRequests) - domainContentValues.put(USER_AGENT, "System default user agent") + domainContentValues.put(USER_AGENT, appContext.getString(R.string.user_agent_default_value)) domainContentValues.put(X_REQUESTED_WITH_HEADER, 0) domainContentValues.put(FONT_SIZE, 0) domainContentValues.put(SWIPE_TO_REFRESH, 0) diff --git a/app/src/main/res/layout/save_dialog.xml b/app/src/main/res/layout/save_dialog.xml index d83f96d6..c11ee8b9 100644 --- a/app/src/main/res/layout/save_dialog.xml +++ b/app/src/main/res/layout/save_dialog.xml @@ -1,7 +1,7 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/settings_top_appbar.xml b/app/src/main/res/layout/settings_top_appbar.xml new file mode 100644 index 00000000..ec5dc3f3 --- /dev/null +++ b/app/src/main/res/layout/settings_top_appbar.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index b4bded4f..f996c45e 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -433,8 +433,8 @@ MiB EasyList: EasyPrivacy: - Fanboy’s Annoyance Sperrliste: - Fanboy’s Social Blocking Sperrliste: + Fanboy’s Annoyance Sperrliste: + Fanboy’s Social Blocking Sperrliste: UltraList: UltraPrivacy: Paket-Signatur diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 91c76b22..a9ece571 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -430,8 +430,8 @@ MiB EasyList: EasyPrivacy: - Lista molesta de Fanboy: - Lista de bloqueo social de Fanboy: + Lista molesta de Fanboy: + Lista de bloqueo social de Fanboy: UltraList: Ultra Privacidad: Firma del paquete diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index c49910b5..fffcfc11 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -430,8 +430,8 @@ Mio EasyList : EasyPrivacy : - Fanboy’s Annoyance List : - Fanboy’s Social Blocking List : + Fanboy’s Annoyance List : + Fanboy’s Social Blocking List : UltraList : UltraPrivacy : Signature de paquets diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 6fcb5022..f0b7fc9f 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -429,8 +429,8 @@ MiB EasyList: EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: UltraList: UltraPrivacy: Firma del Pacchetto diff --git a/app/src/main/res/values-night-v27/styles.xml b/app/src/main/res/values-night-v27/styles.xml index 3e505dbe..d998db6b 100644 --- a/app/src/main/res/values-night-v27/styles.xml +++ b/app/src/main/res/values-night-v27/styles.xml @@ -1,7 +1,7 @@ - ?android:attr/colorBackground - ?android:attr/colorBackground - ?attr/isLightTheme - ?attr/isLightTheme - - - @color/violet_500 - ?android:attr/colorBackground - - - \ No newline at end of file + diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index 77e1470a..483ab90a 100644 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -1,7 +1,7 @@ - ?android:attr/colorBackground - ?attr/isLightTheme - - - @color/violet_500 - ?android:attr/colorBackground - - - \ No newline at end of file + diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 4330292b..219ec199 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -422,8 +422,8 @@ MiB EasyList: EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: UltraList: UltraPrivacy: Assinatura do Pacote diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index b6589d6d..04744f5e 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -426,8 +426,8 @@ МиБ EasyList: EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: UltraList: UltraPrivacy: Подпись пакета diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 5c3bc78d..7ecc4558 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -367,8 +367,8 @@ OpenKeychain: EasyList: EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: UltraList: UltraPrivacy: Paket İmzası diff --git a/app/src/main/res/values-v27/styles.xml b/app/src/main/res/values-v27/styles.xml index e9833d6f..82b618fb 100644 --- a/app/src/main/res/values-v27/styles.xml +++ b/app/src/main/res/values-v27/styles.xml @@ -1,7 +1,7 @@ - ?android:attr/colorBackground - ?android:attr/colorBackground - ?attr/isLightTheme - ?attr/isLightTheme - - - @color/blue_700 - ?android:attr/colorBackground - - - \ No newline at end of file + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 676f7554..6ff8f675 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -437,8 +437,8 @@ MiB EasyList: EasyPrivacy: - Fanboy’s Annoyance List: - Fanboy’s Social Blocking List: + Fanboy’s Annoyance List: + Fanboy’s Social Blocking List: UltraList: UltraPrivacy: Package Signature @@ -573,6 +573,7 @@ https://search.yahoo.com/mobile/s?p= Custom URL + Custom URL Custom URL Search custom URL Proxy @@ -660,18 +661,44 @@ allow_screenshots amp_redirects + app_theme + block_all_third_party_requests bottom_app_bar cookies + clear_and_exit + clear_cache + clear_cookies + clear_dom_storage + clear_everything + clear_form_data clear_logcat custom_user_agent display_additional_app_bar_icons display_webpage_images + dom_storage download_with_external_app + easylist + easyprivacy + fanboys_annoyance_list + fanboys_social_blocking_list font_size + full_screen_browsing_mode + hide_app_bar + homepage + incognito_mode + javascript + open_intents_in_new_tab + privacy + proxy proxy_custom_url + save_form_data scroll_app_bar + search_custom_url + search swipe_to_refresh tracking_queries + ultralist + ultraprivacy user_agent webview_theme wide_viewport diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 6a79f0ba..f3a7411e 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ - ?android:attr/colorBackground - ?attr/isLightTheme - - - @color/blue_700 - ?android:attr/colorBackground - - - \ No newline at end of file + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 4957727c..6bb415e2 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -22,11 +22,11 @@ xmlns:android="http://schemas.android.com/apk/res/android" > @@ -38,14 +38,14 @@ android:defaultValue="false" /> @@ -72,7 +72,7 @@ android:defaultValue="true" /> @@ -89,43 +89,43 @@ android:title="@string/blocklists" > @@ -153,7 +153,7 @@ android:title="@string/search" > @@ -172,7 +172,7 @@ android:title="@string/proxy" > @@ -238,7 +238,7 @@ android:defaultValue="true" /> @@ -249,7 +249,7 @@ android:title="@string/general" > @@ -300,7 +300,7 @@ android:defaultValue="false" />