From 09550b253246e3ddf1055e7b69e1e06b2556df15 Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Sat, 14 Sep 2019 10:31:56 +0200 Subject: [PATCH 1/9] first implementation of incognito mode --- .../NewsDetailFragment.java | 31 ++++++++++++++----- .../src/main/res/drawable/incognito.xml | 8 +++++ .../main/res/layout/fragment_news_detail.xml | 7 +++++ .../src/main/res/menu/news_detail.xml | 6 ++++ 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100755 News-Android-App/src/main/res/drawable/incognito.xml diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java index 0d6a2cd4..d2f17eb9 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java @@ -41,6 +41,7 @@ import android.webkit.WebResourceResponse; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; +import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; @@ -84,6 +85,8 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li protected @BindView(R.id.progressBarLoading) ProgressBar mProgressBarLoading; protected @BindView(R.id.progressbar_webview) ProgressBar mProgressbarWebView; protected @BindView(R.id.tv_offline_version) TextView mTvOfflineVersion; + protected @BindView(R.id.btn_disable_incognito) Button mBtnDisableIncognito; + protected @Inject SharedPreferences mPrefs; @@ -184,6 +187,12 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li setUpGestureDetector(); + mBtnDisableIncognito.setOnClickListener(v -> { + mWebView.getSettings().setBlockNetworkLoads(false); + mWebView.getSettings().setBlockNetworkImage(false); + mWebView.reload(); + }); + return rootView; } @@ -285,16 +294,22 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li WebSettings webSettings = mWebView.getSettings(); //webSettings.setPluginState(WebSettings.PluginState.ON); - webSettings.setJavaScriptEnabled(true); - webSettings.setAllowContentAccess(true); - webSettings.setAllowFileAccess(true); - webSettings.setDomStorageEnabled(true); - webSettings.setJavaScriptCanOpenWindowsAutomatically(false); - webSettings.setSupportMultipleWindows(false); - webSettings.setSupportZoom(false); + webSettings.setJavaScriptEnabled(true); + webSettings.setAllowContentAccess(true); + webSettings.setAllowFileAccess(true); + webSettings.setDomStorageEnabled(true); + webSettings.setJavaScriptCanOpenWindowsAutomatically(false); + webSettings.setSupportMultipleWindows(false); + webSettings.setSupportZoom(false); webSettings.setAppCacheEnabled(true); webSettings.setMediaPlaybackRequiresUserGesture(true); + //if(true) { + //webSettings.setLoadsImagesAutomatically(false); + webSettings.setBlockNetworkImage(true); + webSettings.setBlockNetworkLoads(true); + //} + registerForContextMenu(mWebView); mWebView.setWebChromeClient(new ProgressBarWebChromeClient(mProgressbarWebView)); @@ -305,6 +320,8 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { + //Log.d(TAG, "shouldInterceptRequest: " + url); + boolean isAd; if (!loadedUrls.containsKey(url)) { isAd = AdBlocker.isAd(url); diff --git a/News-Android-App/src/main/res/drawable/incognito.xml b/News-Android-App/src/main/res/drawable/incognito.xml new file mode 100755 index 00000000..2ecfa742 --- /dev/null +++ b/News-Android-App/src/main/res/drawable/incognito.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/News-Android-App/src/main/res/layout/fragment_news_detail.xml b/News-Android-App/src/main/res/layout/fragment_news_detail.xml index d44fa22f..9aa5407e 100644 --- a/News-Android-App/src/main/res/layout/fragment_news_detail.xml +++ b/News-Android-App/src/main/res/layout/fragment_news_detail.xml @@ -42,5 +42,12 @@ android:background="@color/material_red_600" android:visibility="gone" /> +