From f693418d64b4ef3a8775cb118e39eb986c286e2e Mon Sep 17 00:00:00 2001 From: massimilianoLe <44651815+massimilianoLe@users.noreply.github.com> Date: Sat, 1 Dec 2018 17:12:04 +0100 Subject: [PATCH] Make youtube links open external, by @massimilianoLe (#220) --- .../com/github/dfa/diaspora_android/util/AppSettings.java | 4 ++++ .../github/dfa/diaspora_android/web/BrowserFragment.java | 6 +++--- .../dfa/diaspora_android/web/CustomWebViewClient.java | 8 ++++++++ .../main/res/drawable/ic_open_yt_external_black_24px.xml | 5 +++++ app/src/main/res/values/strings-not_translatable.xml | 3 ++- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/preferences__master.xml | 7 +++++++ 7 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/ic_open_yt_external_black_24px.xml 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/BrowserFragment.java b/app/src/main/java/com/github/dfa/diaspora_android/web/BrowserFragment.java index 32a1e83a..d28716d4 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/web/BrowserFragment.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/web/BrowserFragment.java @@ -94,9 +94,9 @@ public class BrowserFragment extends ThemedFragment { this.setRetainInstance(true); //pull to refresh - swipe = view.findViewById(R.id.swipe); - swipe.setOnRefreshListener(() -> reloadUrl()); - swipe.setDistanceToTriggerSync(20000); + swipe = view.findViewById(R.id.swipe); + swipe.setOnRefreshListener(() -> reloadUrl()); + swipe.setDistanceToTriggerSync(2000); } @Override 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 c6af6f85..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 @@ -19,7 +19,9 @@ 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; import android.support.v4.content.LocalBroadcastManager; import android.webkit.CookieManager; @@ -38,6 +40,7 @@ public class CustomWebViewClient extends WebViewClient { private final App app; private String lastLoadUrl = ""; private boolean isAdBlockEnabled = false; + AppSettings appSettings = AppSettings.get(); public CustomWebViewClient(App app, WebView webView) { this.app = app; @@ -56,6 +59,11 @@ public class CustomWebViewClient extends WebViewClient { || (host != null && (url.startsWith("https://" + host) || url.startsWith("http://" + host)))) { return false; + }//make youtube links open external-->never customtab + 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..c66a18d4 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 + 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"/> + +