Improve ads blocker
This commit is contained in:
parent
a4adef24ed
commit
7e8d4749f8
|
@ -352,6 +352,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
|
|||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main_webview, menu);
|
||||
menu.findItem(R.id.action_go).setVisible(false);
|
||||
menu.findItem(R.id.action_block).setVisible(false);
|
||||
menu.findItem(R.id.action_comment).setVisible(true);
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
|
|
|
@ -183,7 +183,7 @@ public class WebviewActivity extends BaseActivity {
|
|||
|
||||
|
||||
public void setCount(Context context, String count) {
|
||||
if( defaultMenu != null) {
|
||||
if( defaultMenu != null && !peertubeLink) {
|
||||
MenuItem menuItem = defaultMenu.findItem(R.id.action_block);
|
||||
LayerDrawable icon = (LayerDrawable) menuItem.getIcon();
|
||||
|
||||
|
@ -205,7 +205,8 @@ public class WebviewActivity extends BaseActivity {
|
|||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
setCount(this, "0");
|
||||
if(!peertubeLink)
|
||||
setCount(this, "0");
|
||||
defaultMenu = menu;
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.webkit.WebView;
|
|||
import android.webkit.WebViewClient;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -56,7 +57,7 @@ public class MastalabWebViewClient extends WebViewClient {
|
|||
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
|
||||
URI uri = null;
|
||||
URI uri;
|
||||
try {
|
||||
uri = new URI(url);
|
||||
String domain = uri.getHost();
|
||||
|
@ -69,11 +70,30 @@ public class MastalabWebViewClient extends WebViewClient {
|
|||
domains.add(url);
|
||||
((WebviewActivity)activity).setCount(activity, String.valueOf(count));
|
||||
}
|
||||
return null;
|
||||
ByteArrayInputStream nothing = new ByteArrayInputStream("".getBytes());
|
||||
return new WebResourceResponse("text/plain", "utf-8", nothing);
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
url = url.substring(0,50);
|
||||
uri = new URI(url);
|
||||
String domain = uri.getHost();
|
||||
if( domain != null) {
|
||||
domain = domain.startsWith("www.") ? domain.substring(4) : domain;
|
||||
}
|
||||
if (domain != null && WebviewActivity.trackingDomains.contains(domain)) {
|
||||
if( activity instanceof WebviewActivity){
|
||||
count++;
|
||||
domains.add(url);
|
||||
((WebviewActivity)activity).setCount(activity, String.valueOf(count));
|
||||
}
|
||||
ByteArrayInputStream nothing = new ByteArrayInputStream("".getBytes());
|
||||
return new WebResourceResponse("text/plain", "utf-8", nothing);
|
||||
|
||||
}
|
||||
} catch (URISyntaxException ignored) {
|
||||
ignored.printStackTrace();
|
||||
} }
|
||||
return super.shouldInterceptRequest(view, url);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue