diff --git a/app/src/main/java/com/github/dfa/diaspora_android/web/CustomWebViewClient.java b/app/src/main/java/com/github/dfa/diaspora_android/web/CustomWebViewClient.java index 3e451b0f..8a19fb85 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/web/CustomWebViewClient.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/web/CustomWebViewClient.java @@ -19,6 +19,7 @@ package com.github.dfa.diaspora_android.web; import android.annotation.TargetApi; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; @@ -39,6 +40,10 @@ public class CustomWebViewClient extends WebViewClient { private final App app; private String lastLoadUrl = ""; private boolean isAdBlockEnabled = false; + protected Context _context; + + String newpipe = "org.schabi.newpipe";//for checking if app is installed + String youtube = "com.google.android.youtube";//for checking if app is installed public CustomWebViewClient(App app, WebView webView) { this.app = app; @@ -58,10 +63,13 @@ public class CustomWebViewClient extends WebViewClient { || url.startsWith("http://" + host)))) { return false; }//make youtube links open external-->never customtab - if (url.startsWith("https://youtube")||url.startsWith("https://www.youtube")) { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - view.getContext().startActivity(intent); - return true; + else if (url.startsWith("https://youtube.com/") || url.startsWith("https://www.youtube.com/") || url.startsWith("https://m.youtube.com/") || url.startsWith("https://youtu.be/")){// && checkNewpipie != null || checkYoutube != null) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + //Intent checkNewpipie = new Intent(_context.getPackageManager().getLaunchIntentForPackage(newpipe)); + //Intent checkYoutube = new Intent(_context.getPackageManager().getLaunchIntentForPackage(youtube)); + //if (checkNewpipie!=null || checkYoutube != null){view.getContext().startActivity(intent);} + view.getContext().startActivity(intent); + return true; } else { Intent i = new Intent(MainActivity.ACTION_OPEN_EXTERNAL_URL); i.putExtra(MainActivity.EXTRA_URL, url);