Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1160 from edx/farhan/LEARNER-6596
Browse files Browse the repository at this point in the history
Fix redirection issue exists in course discovery web view.
  • Loading branch information
farhan authored Oct 31, 2018
2 parents 7079818 + d881342 commit 80159f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
2 changes: 1 addition & 1 deletion OpenEdXMobile/res/layout/activity_find_course_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">>
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<RelativeLayout
android:id="@+id/content_error_root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,19 @@ public void showLoadingProgress() {
if (progressWheel != null) {
progressWheel.setVisibility(View.VISIBLE);
}
if (webView != null) {
webView.setVisibility(View.GONE);
}
}

@Override
public void hideLoadingProgress() {
if (progressWheel != null) {
progressWheel.setVisibility(View.GONE);
}
if (webView != null) {
webView.setVisibility(View.VISIBLE);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ public class URLInterceptorWebViewClient extends WebViewClient {
/**
* Tells if the page loading has been finished or not.
*/
private boolean loadingFinished = true;
/**
* Url will be considered as redirected if it will not be the initial page url requested to load.
* For example, in case the server redirects us to another URL or the user clicks a link
* on the web-page, it will be considered as a redirect.
*/
private boolean redirect = false;
private boolean loadingFinished = false;
/**
* Tells if the currently loading url is the initial page url requested to load.
*/
Expand Down Expand Up @@ -102,13 +96,8 @@ private void setupWebView(WebView webView) {
//We need to hide the loading progress if the Page starts rendering.
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if (progress > 25) {
/*
* 'loadingInitialUrl is marked to false on 25% progress of initial page load
* to avoid any problematic scenarios e.g. user presses some link available on
* a web page before 'onPageFinished' has been called.
*/
loadingInitialUrl = false;
if (progress < 100) {
loadingFinished = false;
}
if (pageStatusListener != null) {
pageStatusListener.onPageLoadProgressChanged(view, progress);
Expand Down Expand Up @@ -136,13 +125,8 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);

loadingInitialUrl = false;
if (!redirect) {
loadingFinished = true;
}
redirect = false;

loadingFinished = true;
// Page loading has finished.
if (pageStatusListener != null) {
pageStatusListener.onPageFinished();
Expand All @@ -167,14 +151,8 @@ public void onReceivedHttpError(WebView view, WebResourceRequest request, WebRes
}
}


@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!loadingFinished) {
redirect = true;
}
loadingFinished = false;

if (actionListener == null) {
logger.warn("you have not set IActionLister to this WebViewClient, " +
"you might miss some event");
Expand All @@ -183,11 +161,10 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (parseRecognizedLinkAndCallListener(url)) {
// we handled this URL
return true;
} else if (redirect && loadingInitialUrl) {
} else if (loadingInitialUrl && !loadingFinished) {
// Server has redirected the initial url to other hosting url, in this case no need to
// redirect the user to external browser.
// Inspiration of this solution has been taken from: https://stackoverflow.com/questions/3149216/how-to-listen-for-a-webview-finishing-loading-a-url/5172952#5172952
loadingInitialUrl = false;
// For more details see LEARNER-6596
// Return false means the current WebView handles the url.
return false;
} else if (isAllLinksExternal || isExternalLink(url)) {
Expand Down

0 comments on commit 80159f3

Please sign in to comment.