diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java b/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java index 8d3bb655..8ae76fea 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java @@ -359,6 +359,10 @@ public class AppSettings extends SharedPreferencesPropertyBackend { return getBool(R.string.pref_key__topbar_stream_shortcut, false); } + public boolean isOpenYoutubeExternalEnabled() { + return getBool(R.string.pref_key__open_youtube_external_enabled, true); + } + public String getScreenRotation() { return getString(R.string.pref_key__screen_rotation, R.string.rotation_val_system); } 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 8a19fb85..848e1b65 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 @@ -40,10 +40,7 @@ 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 + AppSettings appSettings = AppSettings.get(); public CustomWebViewClient(App app, WebView webView) { this.app = app; @@ -63,13 +60,10 @@ public class CustomWebViewClient extends WebViewClient { || url.startsWith("http://" + host)))) { return false; }//make youtube links open external-->never customtab - 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 if (appSettings.isOpenYoutubeExternalEnabled()&&(url.startsWith("https://youtube.com/") || url.startsWith("https://www.youtube.com/") || url.startsWith("https://m.youtube.com/") || url.startsWith("https://youtu.be/"))){ + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + view.getContext().startActivity(intent); + return true; } else { Intent i = new Intent(MainActivity.ACTION_OPEN_EXTERNAL_URL); i.putExtra(MainActivity.EXTRA_URL, url); diff --git a/app/src/main/res/drawable/ic_open_yt_external_black_24px.xml b/app/src/main/res/drawable/ic_open_yt_external_black_24px.xml new file mode 100644 index 00000000..14e620e1 --- /dev/null +++ b/app/src/main/res/drawable/ic_open_yt_external_black_24px.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/values/strings-not_translatable.xml b/app/src/main/res/values/strings-not_translatable.xml index aaa5137a..543ee52e 100644 --- a/app/src/main/res/values/strings-not_translatable.xml +++ b/app/src/main/res/values/strings-not_translatable.xml @@ -148,4 +148,5 @@ pref_key__show_title PDF gsantner + pref_key__open_youtube_external_enabled//make youtube open external diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d61d659c..6c542f21 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -253,5 +253,7 @@ The following libraries are used: We took some inspiration and code from LeafPic. Go check it out, it\'s free software as well! Tell me more + Enable to open Youtube links on external app + Youtube links diff --git a/app/src/main/res/xml/preferences__master.xml b/app/src/main/res/xml/preferences__master.xml index 7bb330f9..c1ab7939 100644 --- a/app/src/main/res/xml/preferences__master.xml +++ b/app/src/main/res/xml/preferences__master.xml @@ -73,6 +73,13 @@ android:summary="@string/open_external_links_with_chrome_custom_tabs_description" android:title="@string/pref_title__chrome_custom_tabs_enabled"/> + +