Commit 2d8eac38 by amateur

1

1 parent 4c8b378e
...@@ -47,6 +47,7 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener { ...@@ -47,6 +47,7 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener {
private AVLoadingIndicatorView mLoading; private AVLoadingIndicatorView mLoading;
private WebviewHandler mWebviewHandler; private WebviewHandler mWebviewHandler;
private ValueCallback<Uri[]> filePathCallback; private ValueCallback<Uri[]> filePathCallback;
private View mErrorLayout;
public static WebViewFragment newInstance(String url) { public static WebViewFragment newInstance(String url) {
Bundle args = new Bundle(); Bundle args = new Bundle();
...@@ -68,6 +69,7 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener { ...@@ -68,6 +69,7 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
this.mWebviewLayout = view.findViewById(R.id.webview_layout); this.mWebviewLayout = view.findViewById(R.id.webview_layout);
this.mLoading = view.findViewById(R.id.webview_loading); this.mLoading = view.findViewById(R.id.webview_loading);
this.mErrorLayout = view.findViewById(R.id.webview_error_layout);
this.initWebView(); this.initWebView();
} }
...@@ -97,9 +99,17 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener { ...@@ -97,9 +99,17 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener {
if (null == menuBean || !this.getTag().equals(map.get("moduleName"))) { if (null == menuBean || !this.getTag().equals(map.get("moduleName"))) {
return; return;
} }
System.out.println(changeRoute);
IWebview webview = this.getWebview(); IWebview webview = this.getWebview();
JSApi.callOnRouteChange(webview.getWebview(), JSON.toJSONString(map)); JSApi.callOnRouteChange(webview.getWebview(), JSON.toJSONString(map));
} else if (type == WebviewLoadListener.TYPE_ERROR) {
this.mLoading.hide();
this.mErrorLayout.setVisibility(View.VISIBLE);
this.mErrorLayout.findViewById(R.id.webview_error_retry).setOnClickListener((v) -> {
X5WebviewUtils.destroy(this.mWebview);
this.mErrorLayout.setVisibility(View.GONE);
this.mLoading.show();
this.initWebView();
});
} }
} }
......
...@@ -5,18 +5,6 @@ ...@@ -5,18 +5,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<!-- <ImageView-->
<!-- android:visibility="gone"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:srcCompat="@mipmap/nav_bg"-->
<!-- tools:ignore="MissingConstraints" />-->
<!-- <include-->
<!-- android:visibility="gone"-->
<!-- android:id="@+id/webview_nav_layout"-->
<!-- layout="@layout/layout_nav" />-->
<LinearLayout <LinearLayout
android:id="@+id/webview_layout" android:id="@+id/webview_layout"
android:layout_width="0dp" android:layout_width="0dp"
...@@ -27,6 +15,21 @@ ...@@ -27,6 +15,21 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></LinearLayout> app:layout_constraintTop_toTopOf="parent"></LinearLayout>
<LinearLayout
android:id="@+id/webview_error_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<include layout="@layout/webview_error_layout" />
</LinearLayout>
<com.wang.avi.AVLoadingIndicatorView <com.wang.avi.AVLoadingIndicatorView
android:id="@+id/webview_loading" android:id="@+id/webview_loading"
style="@style/AVLoadingIndicatorView" style="@style/AVLoadingIndicatorView"
...@@ -41,4 +44,5 @@ ...@@ -41,4 +44,5 @@
app:layout_constraintTop_toTopOf="@+id/webview_layout" app:layout_constraintTop_toTopOf="@+id/webview_layout"
tools:ignore="MissingConstraints" /> tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:scaleType="centerInside"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/icon_webview_error" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="页面加载错误,请重新加载"
android:textColor="#666"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<LinearLayout
android:id="@+id/webview_error_retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
tools:ignore="MissingConstraints">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请点击"
android:textColor="#999"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:paddingRight="20dp"
android:text="@string/retry"
android:textColor="#245fae"
android:textSize="14sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file \ No newline at end of file
...@@ -7,4 +7,5 @@ ...@@ -7,4 +7,5 @@
values-round/strings.xml for round devices. values-round/strings.xml for round devices.
--> -->
<string name="hello_world">Hello Square World!</string> <string name="hello_world">Hello Square World!</string>
<string name="retry"><u>重试</u></string>
</resources> </resources>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!