Browse Source

增加学生端商城加载失败提示页

Pq 1 year ago
parent
commit
ed94dab229

+ 42 - 1
student/src/main/java/com/cooleshow/student/ui/main/MallFragment.java

@@ -46,6 +46,7 @@ import com.cooleshow.base.constanst.Constants;
 import com.cooleshow.base.data.net.RetrofitClientNoToken;
 import com.cooleshow.base.ui.fragment.BaseMVPFragment;
 import com.cooleshow.base.utils.AppUtils;
+import com.cooleshow.base.utils.LOG;
 import com.cooleshow.base.utils.MyFileUtils;
 import com.cooleshow.base.utils.PermissionUtils;
 import com.cooleshow.base.utils.ToastUtil;
@@ -129,6 +130,8 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
     RelativeLayout rl_activity_html;
     LinearLayout ll_activity_html;
 
+    private boolean isLoadError = false;
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -794,12 +797,16 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
         public void onPageStarted(WebView view, String url, Bitmap favicon) {
             super.onPageStarted(view, url, favicon);
             webViewUrl = url;
+            isLoadError = false;
         }
 
         //页面载入结束时调用
         @Override
         public void onPageFinished(WebView view, String url) {
             super.onPageFinished(view, url);
+            if (!isLoadError) {
+                showWebView();
+            }
             webViewUrl = url;
             if (!TextUtils.isEmpty(authorization)) {
                 String js = "window.localStorage.setItem('Authorization','" + authorization + "');";
@@ -836,11 +843,45 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
         //处理报错信息
         @Override
         public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
-            super.onReceivedError(view, request, error);
+//            super.onReceivedError(view, request, error);
+            if (error != null) {
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+                    LOG.i("onReceivedError:" + error.getErrorCode());
+                    LOG.i("onReceivedError:" + error.getDescription());
+                    if (error.getErrorCode() == WebViewClient.ERROR_HOST_LOOKUP || error.getErrorCode() == WebViewClient.ERROR_CONNECT) {
+                        showLoadErrorView();
+                    }
+                }
+            }
         }
     }
 
 
+    private void showWebView() {
+        viewParent.setVisibility(View.VISIBLE);
+    }
+
+    private void hideErrorView() {
+        mViewBinding.flError.setVisibility(View.GONE);
+    }
+
+    private void showLoadErrorView() {
+        isLoadError = true;
+        viewParent.setVisibility(View.GONE);
+        mViewBinding.flError.setVisibility(View.VISIBLE);
+        mViewBinding.errorView.hideBack();
+        mViewBinding.errorView.setIcon(com.cooleshow.base.R.drawable.icon_error_tip);
+        mViewBinding.errorView.setOnRefreshClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                if (webView != null) {
+                    webView.reload();
+                    hideErrorView();
+                }
+            }
+        });
+    }
+
     public void clickBack() {
         if (webView.canGoBack()) {
             webView.goBack();

+ 16 - 0
student/src/main/res/layout/fragment_mall.xml

@@ -19,6 +19,22 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:scrollbars="none" />
+
+    <FrameLayout
+        android:background="@color/white"
+        android:id="@+id/fl_error"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:visibility="gone">
+
+        <com.cooleshow.base.widgets.ErrorView
+            android:id="@+id/error_view"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center" />
+
+    </FrameLayout>
+
     <LinearLayout
         android:id="@+id/ll_activity_html"
         android:layout_width="match_parent"