- // Only set the user agent if the webpage is not currently loading. Otherwise, changing the user agent on redirects can cause the original website to reload.
- // <https://redmine.stoutner.com/issues/160>
- if (nestedScrollWebView.getProgress() == 100) { // A URL is not loading.
- // Set the user agent.
- if (userAgentName.equals(getString(R.string.system_default_user_agent))) { // Use the system default user agent.
- // Get the array position of the default user agent name.
- int defaultUserAgentArrayPosition = userAgentNamesArray.getPosition(defaultUserAgentName);
-
- // Set the user agent according to the system default.
- switch (defaultUserAgentArrayPosition) {
- case UNRECOGNIZED_USER_AGENT: // The default 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.
- nestedScrollWebView.getSettings().setUserAgentString(defaultUserAgentName);
- break;
-
- case SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
- // Set the user agent to `""`, which uses the default value.
- nestedScrollWebView.getSettings().setUserAgentString("");
- break;
-
- case SETTINGS_CUSTOM_USER_AGENT:
- // Set the default custom user agent.
- nestedScrollWebView.getSettings().setUserAgentString(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
- break;
-
- default:
- // Get the user agent string from the user agent data array
- nestedScrollWebView.getSettings().setUserAgentString(userAgentDataArray[defaultUserAgentArrayPosition]);
- }
- } else { // Set the user agent according to the stored name.
- // Get the array position of the user agent name.
- int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
-
- switch (userAgentArrayPosition) {
- case UNRECOGNIZED_USER_AGENT: // The user agent name contains a custom user agent.
- nestedScrollWebView.getSettings().setUserAgentString(userAgentName);
- break;
-
- case SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
- // Set the user agent to `""`, which uses the default value.
- nestedScrollWebView.getSettings().setUserAgentString("");
- break;
-
- default:
- // Get the user agent string from the user agent data array.
- nestedScrollWebView.getSettings().setUserAgentString(userAgentDataArray[userAgentArrayPosition]);
- }
+ // Set the user agent.
+ if (userAgentName.equals(getString(R.string.system_default_user_agent))) { // Use the system default user agent.
+ // Get the array position of the default user agent name.
+ int defaultUserAgentArrayPosition = userAgentNamesArray.getPosition(defaultUserAgentName);
+
+ // Set the user agent according to the system default.
+ switch (defaultUserAgentArrayPosition) {
+ case UNRECOGNIZED_USER_AGENT: // The default 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.
+ nestedScrollWebView.getSettings().setUserAgentString(defaultUserAgentName);
+ break;
+
+ case SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
+ // Set the user agent to `""`, which uses the default value.
+ nestedScrollWebView.getSettings().setUserAgentString("");
+ break;
+
+ case SETTINGS_CUSTOM_USER_AGENT:
+ // Set the default custom user agent.
+ nestedScrollWebView.getSettings().setUserAgentString(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
+ break;
+
+ default:
+ // Get the user agent string from the user agent data array
+ nestedScrollWebView.getSettings().setUserAgentString(userAgentDataArray[defaultUserAgentArrayPosition]);
+ }
+ } else { // Set the user agent according to the stored name.
+ // Get the array position of the user agent name.
+ int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
+
+ switch (userAgentArrayPosition) {
+ case UNRECOGNIZED_USER_AGENT: // The user agent name contains a custom user agent.
+ nestedScrollWebView.getSettings().setUserAgentString(userAgentName);
+ break;
+
+ case SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
+ // Set the user agent to `""`, which uses the default value.
+ nestedScrollWebView.getSettings().setUserAgentString("");
+ break;
+
+ default:
+ // Get the user agent string from the user agent data array.
+ nestedScrollWebView.getSettings().setUserAgentString(userAgentDataArray[userAgentArrayPosition]);