From f7f3e01b550e166fadde19353e178818eddd053f Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 8 Aug 2018 05:02:25 +0000 Subject: [PATCH] Switch from WebView to CustomTabs --- .idea/caches/build_file_checksums.ser | Bin 535 -> 535 bytes app/build.gradle | 5 +++- .../eu/faircode/email/FragmentMessage.java | 27 +++++++++++++----- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index c8b48515cfe14b6e10e2015f71b210241f648762..682a3be78ec057a4b122c5e24e72af333242119b 100644 GIT binary patch delta 33 pcmbQvGM#0@3>NXHO$Hn1WHAbME_MF=^4642MZGvZ6Iq4o3IOKc4P5{L delta 33 pcmbQvGM#0@3>Gnwf15VW$zl|=oa@kEdaqu?W{yqi5}7$F6#(1e4JH5p diff --git a/app/build.gradle b/app/build.gradle index 9a8786cd..d1fec225 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -64,10 +64,12 @@ dependencies { // https://developer.android.com/topic/libraries/architecture/adding-components.html implementation "android.arch.lifecycle:extensions:$lifecycle_version" implementation "android.arch.persistence.room:runtime:$room_version" + implementation "android.arch.paging:runtime:$paging_version" annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version" annotationProcessor "android.arch.persistence.room:compiler:$room_version" - implementation "android.arch.paging:runtime:$paging_version" + // https://developer.android.com/topic/libraries/support-library/packages#custom-tabs + implementation "com.android.support:customtabs:$support_version" // https://javaee.github.io/javamail/ implementation "com.sun.mail:android-mail:$javamail_version" @@ -75,4 +77,5 @@ dependencies { // https://jsoup.org/ implementation "org.jsoup:jsoup:$jsoup_version" + } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessage.java b/app/src/main/java/eu/faircode/email/FragmentMessage.java index 0ddfcd03..c53fdf5b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessage.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessage.java @@ -24,10 +24,12 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Typeface; +import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.constraint.Group; +import android.support.customtabs.CustomTabsIntent; import android.support.design.widget.BottomNavigationView; import android.support.v4.app.FragmentTransaction; import android.support.v4.app.LoaderManager; @@ -134,15 +136,26 @@ public class FragmentMessage extends FragmentEx { URLSpan[] link = buffer.getSpans(off, off, URLSpan.class); if (link.length != 0) { - Bundle args = new Bundle(); - args.putString("link", link[0].getURL()); + String url = link[0].getURL(); - FragmentWebView fragment = new FragmentWebView(); - fragment.setArguments(args); + if (true) { + // https://developer.chrome.com/multidevice/android/customtabs + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); + builder.setToolbarColor(Helper.resolveColor(getContext(), R.attr.colorPrimary)); - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("webview"); - fragmentTransaction.commit(); + CustomTabsIntent customTabsIntent = builder.build(); + customTabsIntent.launchUrl(getContext(), Uri.parse(url)); + } else { + Bundle args = new Bundle(); + args.putString("link", url); + + FragmentWebView fragment = new FragmentWebView(); + fragment.setArguments(args); + + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("webview"); + fragmentTransaction.commit(); + } } return true; }