Switch from WebView to CustomTabs

pull/30/head
M66B 6 years ago
parent 934e898022
commit f7f3e01b55

@ -64,10 +64,12 @@ dependencies {
// https://developer.android.com/topic/libraries/architecture/adding-components.html // https://developer.android.com/topic/libraries/architecture/adding-components.html
implementation "android.arch.lifecycle:extensions:$lifecycle_version" implementation "android.arch.lifecycle:extensions:$lifecycle_version"
implementation "android.arch.persistence.room:runtime:$room_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.lifecycle:compiler:$lifecycle_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_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/ // https://javaee.github.io/javamail/
implementation "com.sun.mail:android-mail:$javamail_version" implementation "com.sun.mail:android-mail:$javamail_version"
@ -75,4 +77,5 @@ dependencies {
// https://jsoup.org/ // https://jsoup.org/
implementation "org.jsoup:jsoup:$jsoup_version" implementation "org.jsoup:jsoup:$jsoup_version"
} }

@ -24,10 +24,12 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.constraint.Group; import android.support.constraint.Group;
import android.support.customtabs.CustomTabsIntent;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
@ -134,15 +136,26 @@ public class FragmentMessage extends FragmentEx {
URLSpan[] link = buffer.getSpans(off, off, URLSpan.class); URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
if (link.length != 0) { if (link.length != 0) {
Bundle args = new Bundle(); String url = link[0].getURL();
args.putString("link", link[0].getURL());
FragmentWebView fragment = new FragmentWebView(); if (true) {
fragment.setArguments(args); // 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(); CustomTabsIntent customTabsIntent = builder.build();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("webview"); customTabsIntent.launchUrl(getContext(), Uri.parse(url));
fragmentTransaction.commit(); } 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; return true;
} }

Loading…
Cancel
Save