From f6291f8d7ab31427634b2a80a7a967dda11a5948 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 4 Sep 2018 15:06:09 +0000 Subject: [PATCH] Use custom tabs to open links in original message --- .../eu/faircode/email/FragmentWebView.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentWebView.java b/app/src/main/java/eu/faircode/email/FragmentWebView.java index 4ac69fd803..048148742d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentWebView.java +++ b/app/src/main/java/eu/faircode/email/FragmentWebView.java @@ -19,7 +19,10 @@ package eu.faircode.email; Copyright 2018 by Marcel Bokhorst (M66B) */ +import android.content.SharedPreferences; +import android.net.Uri; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -31,6 +34,7 @@ import android.widget.ProgressBar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.browser.customtabs.CustomTabsIntent; // https://developer.android.com/reference/android/webkit/WebView @@ -50,11 +54,22 @@ public class FragmentWebView extends FragmentEx { settings.setJavaScriptEnabled(true); settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + webview.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { - view.loadUrl(url); - setSubtitle(url); - return false; + if (prefs.getBoolean("webview", false)) { + view.loadUrl(url); + setSubtitle(url); + return false; + } else { + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); + builder.setToolbarColor(Helper.resolveColor(getContext(), R.attr.colorPrimary)); + + CustomTabsIntent customTabsIntent = builder.build(); + customTabsIntent.launchUrl(getContext(), Uri.parse(url)); + return true; + } } });