mirror of
https://github.com/etesync/android
synced 2025-01-25 15:10:55 +00:00
WebView: correctly handle checking if a url should open in app or browser.
There was an issue that for the first load it would only check the url after a redirect (if there is one), which meant that for example, the dashboard, would open in app because you'd be redirected to the login page.
This commit is contained in:
parent
a9eba1af4e
commit
10095bd4ee
@ -33,9 +33,13 @@ public class WebViewActivity extends AppCompatActivity {
|
|||||||
private ActionBar mToolbar;
|
private ActionBar mToolbar;
|
||||||
|
|
||||||
public static void openUrl(Context context, Uri uri) {
|
public static void openUrl(Context context, Uri uri) {
|
||||||
Intent intent = new Intent(context, WebViewActivity.class);
|
if (isAllowedUrl(uri)) {
|
||||||
intent.putExtra(WebViewActivity.KEY_URL, uri);
|
Intent intent = new Intent(context, WebViewActivity.class);
|
||||||
context.startActivity(intent);
|
intent.putExtra(WebViewActivity.KEY_URL, uri);
|
||||||
|
context.startActivity(intent);
|
||||||
|
} else {
|
||||||
|
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -138,12 +142,12 @@ public class WebViewActivity extends AppCompatActivity {
|
|||||||
mWebView.invalidate();
|
mWebView.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean uriEqual(Uri uri1, Uri uri2) {
|
private static boolean uriEqual(Uri uri1, Uri uri2) {
|
||||||
return uri1.getHost().equals(uri2.getHost()) &&
|
return uri1.getHost().equals(uri2.getHost()) &&
|
||||||
uri1.getPath().equals(uri2.getPath());
|
uri1.getPath().equals(uri2.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean allowedUris(Uri allowedUris[], Uri uri2) {
|
private static boolean allowedUris(Uri allowedUris[], Uri uri2) {
|
||||||
for (Uri uri : allowedUris) {
|
for (Uri uri : allowedUris) {
|
||||||
if (uriEqual(uri, uri2)) {
|
if (uriEqual(uri, uri2)) {
|
||||||
return true;
|
return true;
|
||||||
@ -152,7 +156,7 @@ public class WebViewActivity extends AppCompatActivity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldOverrideUrl(Uri uri) {
|
private static boolean isAllowedUrl(Uri uri) {
|
||||||
final Uri allowedUris[] = new Uri[]{
|
final Uri allowedUris[] = new Uri[]{
|
||||||
Constants.faqUri,
|
Constants.faqUri,
|
||||||
Constants.helpUri,
|
Constants.helpUri,
|
||||||
@ -162,10 +166,14 @@ public class WebViewActivity extends AppCompatActivity {
|
|||||||
};
|
};
|
||||||
final Uri accountsUri = Constants.webUri.buildUpon().appendEncodedPath("accounts/").build();
|
final Uri accountsUri = Constants.webUri.buildUpon().appendEncodedPath("accounts/").build();
|
||||||
|
|
||||||
if (allowedUris(allowedUris, uri) ||
|
return (allowedUris(allowedUris, uri) ||
|
||||||
(uri.getHost().equals(accountsUri.getHost()) &&
|
(uri.getHost().equals(accountsUri.getHost()) &&
|
||||||
(uri.getPath().startsWith(accountsUri.getPath())))
|
(uri.getPath().startsWith(accountsUri.getPath())))
|
||||||
) {
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldOverrideUrl(Uri uri) {
|
||||||
|
if (isAllowedUrl(uri)) {
|
||||||
if (uri.getQueryParameter(QUERY_KEY_EMBEDDED) != null) {
|
if (uri.getQueryParameter(QUERY_KEY_EMBEDDED) != null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@ -173,7 +181,6 @@ public class WebViewActivity extends AppCompatActivity {
|
|||||||
mWebView.loadUrl(uri.toString());
|
mWebView.loadUrl(uri.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user