Browse Source

修改首页统计样式

Pq 3 months ago
parent
commit
153c2a28e2

+ 31 - 6
teacher/src/main/java/com/cooleshow/teacher/ui/web/ScHtmlFragment.java

@@ -9,6 +9,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
+import android.view.ViewGroup;
 import android.webkit.GeolocationPermissions;
 import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient;
@@ -28,12 +29,14 @@ import com.cooleshow.base.constanst.LoginStatusConstants;
 import com.cooleshow.base.event.LoginStatusEvent;
 import com.cooleshow.base.ui.fragment.BaseFragment;
 import com.cooleshow.base.utils.LOG;
+import com.cooleshow.base.utils.SizeUtils;
 import com.cooleshow.base.utils.ToastUtil;
 import com.cooleshow.base.utils.helper.LogUploadManager;
 import com.cooleshow.base.widgets.HttpsServerCertWebViewClient;
 import com.cooleshow.teacher.databinding.FgScHomeWebBinding;
 import com.cooleshow.teacher.widgets.LollipopFixedWebView;
 import com.cooleshow.teacher.widgets.helper.JsInterfaceUtils;
+import com.cooleshow.teacher.widgets.helper.ScHtmlJsInterfaceUtils;
 import com.cooleshow.usercenter.helper.UserHelper;
 
 import org.greenrobot.eventbus.EventBus;
@@ -45,7 +48,7 @@ import org.json.JSONObject;
 /**
  * Author by pq, Date on 2024/12/30.
  */
-public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements JsInterfaceUtils.onGetMethodsListener {
+public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements ScHtmlJsInterfaceUtils.OnEventListener {
 
     private WebView webView;
     private boolean isNeedRefresh = false;
@@ -135,8 +138,8 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
         webSettings.setTextZoom(100);//设置字体默认的缩放比例,以避免手机系统的字体修改对页面字体及布局造成影响。
         webView.setHorizontalScrollBarEnabled(false);
         webView.setVerticalScrollBarEnabled(false);
-        JsInterfaceUtils jsInterfaceUtils = new JsInterfaceUtils(getActivity());
-        jsInterfaceUtils.setOnItemClickListener(this);
+        ScHtmlJsInterfaceUtils jsInterfaceUtils = new ScHtmlJsInterfaceUtils(getActivity());
+        jsInterfaceUtils.setOnEventListener(this);
         webView.setWebViewClient(new WebClient());
         webView.setWebChromeClient(new MyWebChromeClient());
         webView.addJavascriptInterface(jsInterfaceUtils, WebConstants.WEB_JS_INTERFACE);
@@ -174,7 +177,9 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
     }
 
     private void showWebView() {
-        mViewBinding.viewParent.setVisibility(View.VISIBLE);
+        if (mViewBinding != null) {
+            mViewBinding.viewParent.setVisibility(View.VISIBLE);
+        }
     }
 
     private void hideErrorView() {
@@ -211,7 +216,7 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
     }
 
     public void onSendMessage(String message) {
-        Log.i("pq", "post message:" + message);
+        LOG.i("pq", "post message:" + message);
         webView.evaluateJavascript("postMessage('" + message + "','*')", new ValueCallback<String>() {
             @Override
             public void onReceiveValue(String s) {
@@ -332,6 +337,25 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
         notifyWebViewOnResume();
     }
 
+    @Override
+    public void onHomeStatisticsHeight(int height) {
+        if (isDetached()) {
+            return;
+        }
+        //为了规避H5页面的错误状态页比如404页面显示在了首页,所以这里在收到相应回调后更高布局样式
+        changeWebViewParentHeight();
+        showWebView();
+    }
+
+    private void changeWebViewParentHeight() {
+        if (mViewBinding != null) {
+            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mViewBinding.viewParent.getLayoutParams();
+            layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+            layoutParams.topMargin =SizeUtils.dp2px(12);
+            mViewBinding.viewParent.setLayoutParams(layoutParams);
+        }
+    }
+
     private class WebClient extends HttpsServerCertWebViewClient {
         //页面开始载入时调用
 
@@ -348,7 +372,8 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
             super.onPageFinished(view, url);
             if (!isLoadError) {
                 isLoadCompleted = true;
-                showWebView();
+                LOG.i("onPageFinished:url" + url);
+//                showWebView();
             }
         }
 

+ 1 - 0
teacher/src/main/java/com/cooleshow/teacher/widgets/helper/JsInterfaceUtils.java

@@ -429,6 +429,7 @@ public class JsInterfaceUtils extends Object {
                 }
 
             } catch (Exception e) {
+                e.printStackTrace();
             }
         });
 

+ 61 - 0
teacher/src/main/java/com/cooleshow/teacher/widgets/helper/ScHtmlJsInterfaceUtils.java

@@ -0,0 +1,61 @@
+package com.cooleshow.teacher.widgets.helper;
+
+import android.app.Activity;
+import android.text.TextUtils;
+import android.webkit.JavascriptInterface;
+
+import com.cooleshow.base.utils.LOG;
+import com.cooleshow.base.utils.ThreadUtils;
+import com.cooleshow.chatmodule.utils.helper.ChatHelper;
+
+import org.json.JSONObject;
+
+/**
+ * Author by pq, Date on 2025/1/2.
+ */
+public class ScHtmlJsInterfaceUtils extends JsInterfaceUtils {
+    public static final String HOME_STATISTICS_HEIGHT_KEY = "homeStatisticsHeight";
+    private OnEventListener mEventListener;
+
+    public ScHtmlJsInterfaceUtils(Activity activity) {
+        super(activity);
+    }
+
+    @Override
+    @JavascriptInterface
+    public void postMessage(String message) {
+        super.postMessage(message);
+        ThreadUtils.runOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    JSONObject jsonObject = new JSONObject(message);
+                    String api = jsonObject.getString("api");
+                    LOG.i("postMessage:" + jsonObject.toString());
+                    if (TextUtils.equals(api, HOME_STATISTICS_HEIGHT_KEY)) {
+                        JSONObject contentBean = jsonObject.getJSONObject("content");
+                        if (null != contentBean) {
+                            double height = contentBean.optDouble("height", 0);
+                            if (mEventListener != null) {
+                                mEventListener.onHomeStatisticsHeight((int) height);
+                            }
+                        }
+                        return;
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+    }
+
+    public void setOnEventListener(OnEventListener listener) {
+        setOnItemClickListener(listener);
+        this.mEventListener = listener;
+    }
+
+    public interface OnEventListener extends onGetMethodsListener {
+        void onHomeStatisticsHeight(int height);
+    }
+
+}

+ 0 - 1
teacher/src/main/res/layout/fg_new_home_v2_layout.xml

@@ -432,7 +432,6 @@
                     android:id="@+id/cl_home_statistics"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:layout_marginTop="@dimen/dp_12"
                     android:paddingStart="14dp"
                     android:paddingEnd="14dp"
                     app:layout_constraintTop_toBottomOf="@+id/top_help_line"

+ 2 - 1
teacher/src/main/res/layout/fg_sc_home_web.xml

@@ -3,10 +3,11 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
+
     <FrameLayout
         android:id="@+id/view_parent"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"/>
+        android:layout_height="0px"/>
 
     <FrameLayout
         android:paddingBottom="12dp"