From 7db44ba42c42745594e96b198be77c29c586920e Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 18 May 2016 17:40:31 -0700 Subject: [PATCH] Remove unneeded Snackbars. --- app/src/free/res/layout/main_webview.xml | 2 +- .../privacybrowser/MainWebViewActivity.java | 158 +++++++----------- app/src/main/res/values/strings.xml | 6 - 3 files changed, 66 insertions(+), 100 deletions(-) diff --git a/app/src/free/res/layout/main_webview.xml b/app/src/free/res/layout/main_webview.xml index c7bf4b0f..2b878190 100644 --- a/app/src/free/res/layout/main_webview.xml +++ b/app/src/free/res/layout/main_webview.xml @@ -28,7 +28,7 @@ android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize" tools:context="com.stoutner.privacybrowser.MainWebViewActivity" - tools:showIn="@layout/activity_webview"> + tools:showIn="@layout/coordinator_layout"> = 21) { - if (thirdPartyCookiesEnabled) { - thirdPartyCookiesEnabled = false; - menuItem.setChecked(false); - cookieManager.setAcceptThirdPartyCookies(mainWebView, false); - mainWebView.reload(); + // Switch the status of thirdPartyCookiesEnabled. + thirdPartyCookiesEnabled = !thirdPartyCookiesEnabled; - Snackbar.make(findViewById(R.id.mainWebView), R.string.third_party_cookies_disabled, Snackbar.LENGTH_SHORT).show(); - } else { - thirdPartyCookiesEnabled = true; - menuItem.setChecked(true); - cookieManager.setAcceptThirdPartyCookies(mainWebView, true); - mainWebView.reload(); + // Update the menu checkbox. + menuItem.setChecked(thirdPartyCookiesEnabled); - Snackbar.make(findViewById(R.id.mainWebView), R.string.third_party_cookies_enabled, Snackbar.LENGTH_SHORT).show(); - } + // Apply the new cookie status. + cookieManager.setAcceptThirdPartyCookies(mainWebView, thirdPartyCookiesEnabled); + + // Reload the WebView. + mainWebView.reload(); } // Else do nothing because SDK < 21. return true; case R.id.toggleDomStorage: - if (domStorageEnabled) { - domStorageEnabled = false; - menuItem.setChecked(false); - mainWebView.getSettings().setDomStorageEnabled(false); - mainWebView.reload(); + // Switch the status of domStorageEnabled. + domStorageEnabled = !domStorageEnabled; - // Update the toggleJavaScript icon if appropriate and display a snackbar. - if (!javaScriptEnabled) { - if (firstPartyCookiesEnabled) { - toggleJavaScript.setIcon(R.drawable.warning); - Snackbar.make(findViewById(R.id.mainWebView), R.string.dom_storage_disabled, Snackbar.LENGTH_SHORT).show(); - } else { - toggleJavaScript.setIcon(R.drawable.privacy_mode); - Snackbar.make(findViewById(R.id.mainWebView), R.string.privacy_mode, Snackbar.LENGTH_SHORT).show(); - } - }else { - Snackbar.make(findViewById(R.id.mainWebView), R.string.dom_storage_disabled, Snackbar.LENGTH_SHORT).show(); - } - } else { - domStorageEnabled = true; - menuItem.setChecked(true); - mainWebView.getSettings().setDomStorageEnabled(true); - mainWebView.reload(); + // Update the menu checkbox. + menuItem.setChecked(domStorageEnabled); - // Update the toggleJavaScript icon if appropriate. - if (!javaScriptEnabled) { - toggleJavaScript.setIcon(R.drawable.warning); - } // Else Do nothing because JavaScript is enabled. + // Apply the new DOM Storage status. + mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled); - Snackbar.make(findViewById(R.id.mainWebView), R.string.dom_storage_enabled, Snackbar.LENGTH_SHORT).show(); - } + // Update the privacy icon. + updatePrivacyIcon(); + + // Reload the WebView. + mainWebView.reload(); return true; case R.id.clearCookies: @@ -836,4 +796,16 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0); } + + private void updatePrivacyIcon() { + if (javaScriptEnabled) { + privacyIcon.setIcon(R.drawable.javascript_enabled); + } else { + if (domStorageEnabled || firstPartyCookiesEnabled) { + privacyIcon.setIcon(R.drawable.warning); + } else { + privacyIcon.setIcon(R.drawable.privacy_mode); + } + } + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ff644305..a47e02fc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,12 +28,6 @@ Privacy Mode JavaScript enabled JavaScript disabled - DOM Storage enabled - DOM Storage disabled - First-Party Cookies enabled - First-Party Cookies disabled - Third-Party Cookies enabled - Third-Party Cookies disabled Cookies deleted DOM Storage deleted Open Navigation Drawer -- 2.43.0