Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect browser preference in internal WebView's #711

Merged
merged 1 commit into from
Feb 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 30 additions & 36 deletions src/main/java/org/quantumbadger/redreader/common/LinkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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+).*"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}

Expand Down