Skip to content
Permalink
Browse files

Respect browser preference in internal WebView's (#711)

  • Loading branch information
Cguy7777 committed Feb 22, 2020
1 parent 0b1246b commit 56924aea4d67c93c25a3d6bda4796eec86f55f97
@@ -18,6 +18,7 @@
package org.quantumbadger.redreader.common;

import android.Manifest;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
@@ -173,31 +174,16 @@ public void run() {
}

case INTERNAL_BROWSER: {
final Intent intent = new Intent();
if (PrefsUtility.pref_behaviour_usecustomtabs(activity, sharedPreferences) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Bundle bundle = new Bundle();
bundle.putBinder("android.support.customtabs.extra.SESSION", null);
intent.putExtras(bundle);

intent.putExtra("android.support.customtabs.extra.SHARE_MENU_ITEM", true);

TypedValue typedValue = new TypedValue();
activity.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);

intent.putExtra("android.support.customtabs.extra.TOOLBAR_COLOR", typedValue.data);

intent.putExtra("android.support.customtabs.extra.ENABLE_URLBAR_HIDING", true);
openCustomTab(activity, Uri.parse(url));
} else {
final Intent intent = new Intent();
intent.setClass(activity, WebViewActivity.class);
intent.putExtra("url", url);
intent.putExtra("post", post);
activity.startActivity(intent);
}
activity.startActivity(intent);
return;
}

@@ -264,32 +250,17 @@ public void run() {
}
}

final Intent intent = new Intent();
if (PrefsUtility.pref_behaviour_usecustomtabs(activity, sharedPreferences)
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Bundle bundle = new Bundle();
bundle.putBinder("android.support.customtabs.extra.SESSION", null);
intent.putExtras(bundle);

intent.putExtra("android.support.customtabs.extra.SHARE_MENU_ITEM", true);

TypedValue typedValue = new TypedValue();
activity.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);

intent.putExtra("android.support.customtabs.extra.TOOLBAR_COLOR", typedValue.data);

intent.putExtra("android.support.customtabs.extra.ENABLE_URLBAR_HIDING", true);
openCustomTab(activity, Uri.parse(url));
} else {
final Intent intent = new Intent();
intent.setClass(activity, WebViewActivity.class);
intent.putExtra("url", url);
intent.putExtra("post", post);
activity.startActivity(intent);
}

activity.startActivity(intent);
}

public static void onLinkLongClicked(AppCompatActivity activity, String uri){
@@ -438,6 +409,29 @@ public static boolean openWebBrowser(AppCompatActivity activity, Uri uri, final
return false;
}

@TargetApi(18)
public static void openCustomTab(AppCompatActivity activity, Uri uri) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Bundle bundle = new Bundle();
bundle.putBinder("android.support.customtabs.extra.SESSION", null);
intent.putExtras(bundle);

intent.putExtra("android.support.customtabs.extra.SHARE_MENU_ITEM", true);

TypedValue typedValue = new TypedValue();
activity.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);

intent.putExtra("android.support.customtabs.extra.TOOLBAR_COLOR", typedValue.data);

intent.putExtra("android.support.customtabs.extra.ENABLE_URLBAR_HIDING", true);

activity.startActivity(intent);
}

public static final Pattern imgurPattern = Pattern.compile(".*[^A-Za-z]imgur\\.com/(\\w+).*"),
imgurAlbumPattern = Pattern.compile(".*[^A-Za-z]imgur\\.com/(a|gallery)/(\\w+).*"),
qkmePattern1 = Pattern.compile(".*[^A-Za-z]qkme\\.me/(\\w+).*"),
@@ -21,6 +21,7 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
@@ -276,8 +277,19 @@ public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
if (RedditURLParser.parse(Uri.parse(url)) != null) {
LinkHandler.onLinkClicked(mActivity, url, false);
} else {
webView.loadUrl(url);
currentUrl = url;
if (! PrefsUtility.pref_behaviour_useinternalbrowser(
getActivity(),
PreferenceManager.getDefaultSharedPreferences(getActivity()))) {
LinkHandler.openWebBrowser((AppCompatActivity)getActivity(), Uri.parse(url), true);
} else if (PrefsUtility.pref_behaviour_usecustomtabs(
getActivity(),
PreferenceManager.getDefaultSharedPreferences(getActivity())) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
LinkHandler.openCustomTab((AppCompatActivity)getActivity(),Uri.parse(url));
} else {
webView.loadUrl(url);
currentUrl = url;
}
}
}

0 comments on commit 56924ae

Please sign in to comment.
You can’t perform that action at this time.