Fixed "Check Your Internet" error which appear unnecessarily sometimes.
@@ -90,6 +90,8 @@ public class CourseUnitWebViewFragment extends CourseUnitFragment {
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
+ // If error occurred for web page request
+ if (failingUrl != null && failingUrl.equals(view.getUrl())) {
didReceiveError = true;
hideLoadingProgress();
pageIsLoaded = false;
@@ -97,11 +99,14 @@ public class CourseUnitWebViewFragment extends CourseUnitFragment {
showErrorMessage(R.string.network_error_message,
FontAwesomeIcons.fa_exclamation_circle);
}
+ }
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onReceivedHttpError(WebView view, WebResourceRequest request,
WebResourceResponse errorResponse) {
+ // If error occurred for web page request
+ if (request.getUrl().toString().equals(view.getUrl())) {
didReceiveError = true;
switch (errorResponse.getStatusCode()) {
case HttpStatus.FORBIDDEN:
@@ -114,6 +119,7 @@ public class CourseUnitWebViewFragment extends CourseUnitFragment {
showErrorMessage(R.string.network_error_message,
FontAwesomeIcons.fa_exclamation_circle);
}
+ }
public void onPageFinished(WebView view, String url) {
if (didReceiveError) {
@@ -124,6 +130,7 @@ public class CourseUnitWebViewFragment extends CourseUnitFragment {
//we load a local empty html page to release the memory
} else {
pageIsLoaded = true;
+ hideErrorMessage();
}
//TODO -disable it for now. as it causes some issues for assessment
@@ -255,12 +262,9 @@ public class CourseUnitWebViewFragment extends CourseUnitFragment {
map.put("Authorization", token);
}
- // Requery the session cookie if unavailable or expired if we are on
- // an API level lesser than Marshmallow (which provides HTTP error
- // codes in the error callback for WebViewClient).
+ // Requery the session cookie if unavailable or expired.
final EdxCookieManager cookieManager = EdxCookieManager.getSharedInstance(getContext());
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M &&
- cookieManager.isSessionCookieMissingOrExpired()) {
+ if (cookieManager.isSessionCookieMissingOrExpired()) {
cookieManager.tryToRefreshSessionCookie();
} else {
webView.loadUrl(unit.getBlockUrl(), map);
