Add preference for customizing the user agent.
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / MainWebViewActivity.java
index 78624a8ad3f30d19bb7f9a6f694bf985f64c4740..2333900212aa7638cfce68acfe87aeeffe48cbc9 100644 (file)
@@ -343,6 +343,24 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         domStorageEnabled = savedPreferences.getBoolean("dom_storage_enabled", false);
         mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled);
 
+        // Set the user agent initial status.
+        String userAgentString = savedPreferences.getString("user_agent", "Default user agent");
+        switch (userAgentString) {
+            case "Default user agent":
+                // Do nothing.
+                break;
+
+            case "Custom user agent":
+                // Set the custom user agent on mainWebView,  The default is "PrivacyBrowser/1.0".
+                mainWebView.getSettings().setUserAgentString(savedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"));
+                break;
+
+            default:
+                // Set the selected user agent on mainWebView.  The default is "PrivacyBrowser/1.0".
+                mainWebView.getSettings().setUserAgentString(savedPreferences.getString("user_agent", "PrivacyBrowser/1.0"));
+                break;
+        }
+
         // Set the initial status for the search URLs.
         javaScriptDisabledSearchURL = savedPreferences.getString("javascript_disabled_search", "https://duckduckgo.com/html/?q=");
         javaScriptDisabledSearchCustomURL = savedPreferences.getString("javascript_disabled_search_custom_url", "");
@@ -618,8 +636,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
 
             case R.id.refresh:
                 mainWebView.reload();
+                return true;
 
             default:
+                // Don't consume the event.
                 return super.onOptionsItemSelected(menuItem);
         }
     }