From 2f5411b86c59706d31f6ec7de629d8f860725e46 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 26 十一月 2025 19:56:56 +0800
Subject: [PATCH] 2025年11月26日19:56:45 集成谷歌推送

---
 app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java |  239 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 217 insertions(+), 22 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java
index 4b2c5cb..733934b 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java
@@ -6,12 +6,16 @@
 import android.content.Intent;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.Process;
 import android.os.SystemClock;
 import android.text.TextUtils;
+import android.util.Log;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.google.gson.Gson;
+import com.google.gson.JsonObject;
 import com.google.gson.reflect.TypeToken;
 import com.hdl.linkpm.sdk.core.exception.HDLException;
 import com.hdl.linkpm.sdk.home.type.HomeType;
@@ -25,21 +29,29 @@
 import com.hdl.photovoltaic.databinding.ActivityCpowerStationBinding;
 import com.hdl.photovoltaic.enums.NetworkType;
 import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.other.HdlCommonLogic;
 import com.hdl.photovoltaic.other.HdlDeviceLogic;
 import com.hdl.photovoltaic.other.HdlESLocalJsonLogic;
 import com.hdl.photovoltaic.other.HdlLogLogic;
 import com.hdl.photovoltaic.other.HdlMqttLogic;
 import com.hdl.photovoltaic.other.HdlOtaLogic;
+import com.hdl.photovoltaic.other.HdlPushLogic;
 import com.hdl.photovoltaic.other.HdlResidenceLogic;
 import com.hdl.photovoltaic.other.HdlThreadLogic;
 import com.hdl.photovoltaic.other.HdlUniLogic;
+import com.hdl.photovoltaic.push.PushMessageInfoBean;
 import com.hdl.photovoltaic.services.ForeService;
 import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo;
 import com.hdl.photovoltaic.ui.bean.HouseIdBean;
+import com.hdl.photovoltaic.ui.bean.MessageBean;
 import com.hdl.photovoltaic.ui.bean.OidBean;
+import com.hdl.photovoltaic.ui.message.MessageInfoActivity;
+import com.hdl.photovoltaic.ui.newC.PowerStationsListActivity;
+import com.hdl.photovoltaic.ui.newC.PowerStationsMoveActivity;
 import com.hdl.photovoltaic.uni.HDLUniMP;
 import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
 import com.hdl.photovoltaic.utils.AppManagerUtils;
+import com.hdl.photovoltaic.utils.BadgeUtils;
 import com.hdl.sdk.link.HDLLinkLocalSdk;
 import com.hdl.sdk.link.common.event.EventListener;
 import com.hdl.sdk.link.core.bean.LinkResponse;
@@ -55,6 +67,7 @@
 
 import java.lang.reflect.Type;
 import java.util.List;
+import java.util.Objects;
 
 import cn.jpush.android.api.JPushInterface;
 
@@ -67,6 +80,8 @@
 
     private EventListener allTopicsListener;
     private int backPressTimes;
+
+    private volatile boolean isRunning = false;
 
     @Override
     public Object getContentView() {
@@ -84,8 +99,12 @@
         this.registerAllTopicsListener();
         //鍒濆鍖杕qtt瀹㈡埛绔�
         this.initMqttClient();
-        //涓婁紶鏋佸厜娉ㄥ唽ID鍒颁簯绔�
-        this.pushTokens();
+//        //涓婁紶鏋佸厜娉ㄥ唽ID鍒颁簯绔�
+//        this.pushTokens();
+        //涓婁紶鎺ㄥ姩浠ょ墝鍒颁簯绔紙璋锋瓕FCM鎺ㄩ�侊級
+        this.sendPushTokenToServer(UserConfigManage.getInstance().getPushToken());
+        //鐐瑰嚮閫氱煡鏍忔秷鎭繘鏉�
+        this.OpenSpecifiedPage(getIntent(), "onBindView");
         //鑾峰彇浜戠鑴氭湰
         HdlESLocalJsonLogic.getInstance().getAllHdlESLocalJson();
 //        mForegroundService= new Intent(this, ForeService.class);
@@ -111,6 +130,44 @@
 //        this.portConflictDialog();
     }
 
+    @Override
+    protected void onNewIntent(Intent intent) {
+        super.onNewIntent(intent);
+        //AndroidManifest.xml 闇�瑕佹坊鍔犲惎鍔ㄦā寮廰ndroid:launchMode="singleTask"鎵嶆墽琛岃繖涓柟娉�
+        OpenSpecifiedPage(intent, "onNewIntent");
+    }
+
+    /**
+     * 鐐瑰嚮閫氱煡鏍忔秷鎭繘鏉�
+     */
+    private void OpenSpecifiedPage(Intent intent, String tag) {
+        Log.d("==========", tag);
+        try {
+            String data = getIntentExpantData(intent);
+            if (TextUtils.isEmpty(data)) {
+                return;
+            }
+            PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing("", "", data);
+            if (TextUtils.isEmpty(pushMessageInfoBean.getMsgId())) {
+                return;
+            }
+            HDLUniMPSDKManager.uinEnabled = false;
+            if (tag.equals("onNewIntent")) {
+                HDLUniMPSDKManager.uinEnabled = false;
+                //C绔惎鍔ˋpp鑷姩鎵撳紑灏忕▼搴忕數绔欒鎯呯晫闈�
+                if (null != HDLUniMPSDKManager.getInstance().getUniMP()) {
+                    HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP();
+                }
+                startAppAutomaticallyOpenUni();
+            }
+            CheckUniOn(pushMessageInfoBean);
+
+
+        } catch (Exception e) {
+            Log.d("閿欒", " " + e.getMessage());
+        }
+    }
+
     public void startAppAutomaticallyOpenUni() {
         new Thread(new Runnable() {
             @Override
@@ -132,6 +189,42 @@
         }).start();
     }
 
+    /**
+     * 妫�娴媢ni鏄惁鎵撳紑锛屾娴嬫渶闀挎椂闂翠负5s锛屾娴嬫垚鍔熷悗鎵撳紑鍘熺敓娑堟伅鐣岄潰锛屽叧闂繑鍥炰富鐣岄潰
+     */
+    public void CheckUniOn(PushMessageInfoBean pushMessageInfoBean) {
+        if (pushMessageInfoBean == null) return;
+        final long startTime = System.currentTimeMillis();
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                while (System.currentTimeMillis() - startTime < 5 * 1000) {
+                    if (HDLUniMPSDKManager.uinEnabled) {
+                        runOnUiThread(new Runnable() {
+                            @Override
+                            public void run() {
+                                if (pushMessageInfoBean.isAiPrompt()) {
+                                    HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_open_ai_push_message, new HDLUniMP.UniCallBackBaseBean());
+                                } else {
+                                    MessageBean messageBean = new MessageBean();
+                                    messageBean.setMsgId(Long.valueOf(pushMessageInfoBean.getMsgId()));
+                                    Intent intentMessageInfoActivity = new Intent();
+                                    intentMessageInfoActivity.setClass(_mActivity, MessageInfoActivity.class);
+                                    intentMessageInfoActivity.putExtra("messageBean", JSONObject.toJSONString(messageBean));
+                                    startActivity(intentMessageInfoActivity);
+                                }
+
+                            }
+                        });
+                        break;
+                    }
+                    SystemClock.sleep(1000);
+                }
+
+            }
+        }).start();
+    }
+
     @Subscribe(threadMode = ThreadMode.MAIN)
     public void onEventMessage(BaseEventBus event) {
 
@@ -149,7 +242,7 @@
                 return;
             }
             int index = -1;
-            List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId(), null);
+            List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId());
             for (int i = 0; i < list.size(); i++) {
                 GatewayBean gatewayBean = list.get(i);
                 if (gatewayBean.getGatewayId().equals(topics[2])) {
@@ -223,8 +316,8 @@
             }
             String homeId = event.getData().toString();
             //杩涘幓浣忓畢璇︽儏uni璇诲彇閫嗗彉鍣ㄥ垪琛ㄦ垚鍔熷悗閫氱煡
-            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId, null).size(); i++) {
-                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId, null).get(i).getGatewayId();
+            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).size(); i++) {
+                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).get(i).getGatewayId();
                 //瀛楃涓叉槸鑷繁鎸夎鍒欐嫾鎺ョ殑,閲岄潰娉ㄥ唽涓婚鏃朵細瑙f瀽瀛楃涓�,鍙嬁getGatewayId()鍊�;
                 String topic = "/user/" + gatewayId + "/#";
                 //杩涘幓浣忓畢璇︽儏寮�濮嬭闃呬富棰�
@@ -235,6 +328,9 @@
             MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topicHome);//璁㈤槄銆愮數绔欍�戞秷鎭�
 
 
+        } else if (event.getTopic().contains(ConstantManage.refresh_push_token)) {
+            //pushToken鏇存柊
+            sendPushTokenToServer(UserConfigManage.getInstance().getPushToken());
         }
     }
 
@@ -255,20 +351,25 @@
         UserConfigManage.getInstance().setUniBottomSafeDistanceBackgroundColor(0);
         List<HouseIdBean> HouseIdList = HdlResidenceLogic.getInstance().getHouseIdList();
         if (HouseIdList.isEmpty()) {
-            if (TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) {
-                String path = HDLUniMP.UNI_EVENT_OPEN_HOME_Null_C;
-                HdlUniLogic.getInstance().openUniMP(path, null);
-            } else {
-                //瑙e喅闂鎵嬫満娌℃湁缃戣嚜鍔ㄧ櫥褰曡繘鏉ワ紝榛樿浼犱笂涓�娆$殑浣忓畢id
-                String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS_C + "?homeId=" + UserConfigManage.getInstance().getHomeId() + "&homeName=" + UserConfigManage.getInstance().getHomeName();
-                HdlUniLogic.getInstance().openUniMP(path, null);
-            }
+//            if (TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) {
+            String path = HDLUniMP.UNI_EVENT_OPEN_HOME_Null_C;
+            HdlUniLogic.getInstance().openUniMP(path, null);
+//            } else {
+//                //鏆傛椂涓嶈�冭檻杩欑鎯呭喌
+//                //1锛岃В鍐虫墜鏈烘病鏈夊缃戯紝鑾峰彇涓嶅埌鐢电珯鍒楄〃锛岃嚜鍔ㄧ櫥褰曡繘鏉ワ紝榛樿浼犱笂涓�娆$殑浣忓畢id锛�
+//                //2锛屼箣鍓嶇數绔欏垪琛ㄥ彧鏈変竴涓數绔欙紝鐒跺悗鍒犻櫎鎺夌數绔欙紝杩欐椂浣忓畢id杩樼紦瀛樼潃锛屽啀涓�娆¤繘鏉ワ紝榛樿浼犱笂涓�娆$殑浣忓畢id锛�
+//                String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS_C + "?homeId=" + UserConfigManage.getInstance().getHomeId() + "&homeName=" + UserConfigManage.getInstance().getHomeName();
+//                HdlUniLogic.getInstance().openUniMP(path, null);
+//            }
         } else {
+
             int select_home = 0;
-            for (int i = 0; i < HouseIdList.size(); i++) {
-                if (HouseIdList.get(i).getHomeId().equals(UserConfigManage.getInstance().getHomeId())) {
-                    select_home = i;
-                    break;
+            if (!TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) {//鏈湴缂撳瓨浣忓畢id涓嶄负绌哄啀閬嶅巻鏌ユ壘
+                for (int i = 0; i < HouseIdList.size(); i++) {
+                    if (HouseIdList.get(i).getHomeId().equals(UserConfigManage.getInstance().getHomeId())) {
+                        select_home = i;
+                        break;
+                    }
                 }
             }
             HouseIdBean houseIdBean = HouseIdList.get(select_home);
@@ -325,7 +426,7 @@
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack();
+//        HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack();
         //绉婚櫎鐩戝惉
         HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener);
 //        stopService(mForegroundService);
@@ -357,14 +458,15 @@
                     }
                 }
                 if (!TextUtils.isEmpty(registrationID)) {
-                    UserConfigManage.getInstance().setRegistrationID(registrationID);
-                    UserConfigManage.getInstance().Save();
+//                    UserConfigManage.getInstance().setRegistrationID(registrationID);
+//                    UserConfigManage.getInstance().Save();
                     String finalRegistrationID = registrationID;
                     HdlResidenceLogic.getInstance().pushAdd(new CloudCallBeak<String>() {
                         @Override
                         public void onSuccess(String pushId) {
 
                             if (!TextUtils.isEmpty(pushId)) {
+                                UserConfigManage.getInstance().setPushToken(finalRegistrationID);
                                 UserConfigManage.getInstance().setPushId(pushId);
                                 UserConfigManage.getInstance().Save();
                             }
@@ -383,6 +485,34 @@
                 }
 
 
+            }
+        });
+    }
+
+    /**
+     * 涓婁紶 token 鍒版湇鍔″櫒
+     *
+     * @param token 浠ょ墝
+     */
+    private void sendPushTokenToServer(final String token) {
+        if (TextUtils.isEmpty(token)) {
+            return;
+        }
+        HdlResidenceLogic.getInstance().pushAdd(new CloudCallBeak<String>() {
+            @Override
+            public void onSuccess(String pushId) {
+
+                if (!TextUtils.isEmpty(pushId)) {
+                    UserConfigManage.getInstance().setToken(token);
+                    UserConfigManage.getInstance().setPushId(pushId);
+                    UserConfigManage.getInstance().Save();
+                }
+                HdlLogLogic.print("娣诲姞浠ょ墝鍒颁簯绔� PushToken:" + UserConfigManage.getInstance().getPushToken() + " pushId:" + pushId, true);
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                HdlLogLogic.print("娣诲姞浠ょ墝鍒颁簯绔け璐� PushToken:" + UserConfigManage.getInstance().getPushToken() + " 閿欒锛�" + e.getMessage(), true);
             }
         });
     }
@@ -492,7 +622,50 @@
 //                        uniCallBackBaseBean.setData(linkResponse.getData());
 //                        HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
                         HdlLogLogic.print(linkResponse.getTopic() + new Gson().toJson(linkResponse.getData()), true);
-                        HdlDeviceLogic.getInstance().searchAllNetworkGateway(null);//閫嗗彉鍣╳ifi鐘舵��-閲嶆柊鎼滅储涓�涓嬮�嗗彉鍣�-閲嶆柊鏇存柊杩炴帴鐘舵��
+//                        HdlDeviceLogic.getInstance().searchAllNetworkGateway(null);//閫嗗彉鍣╳ifi鐘舵��-閲嶆柊鎼滅储涓�涓嬮�嗗彉鍣�-閲嶆柊鏇存柊杩炴帴鐘舵��
+                    } else if (linkResponse.getTopic().endsWith("/app/thing/event/appHomeDeliverRollbackRefresh/up")) {
+                        try {
+                            //浣忓畢浜や粯鐘舵�佸洖婊氶�氱煡
+                            String[] topicArray = linkResponse.getTopic().split("/");
+                            if (topicArray.length < 2) {
+                                return;
+                            }
+                            final String HomeId = topicArray[2];
+                            //鍏堝垹闄ょ數绔�
+                            HdlResidenceLogic.getInstance().delHouseId(HomeId);
+                            List<HouseIdBean> localHouseIdList = HdlResidenceLogic.getInstance().getHouseIdList();
+                            if (localHouseIdList.isEmpty()) {
+                                JsonObject jsonObject = new JsonObject();
+                                jsonObject.addProperty("homeId", "");
+                                HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
+                                uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_DETAILS);
+                                uniCallBackBaseBean.setData(jsonObject);
+                                HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
+                                UserConfigManage.getInstance().setHomeId("");
+                                UserConfigManage.getInstance().Save();
+                            } else {
+                                if (HomeId.equals(UserConfigManage.getInstance().getHomeId()) || TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) {
+                                    HouseIdBean houseIdBean = localHouseIdList.get(0);
+                                    HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true);
+                                    JsonObject jsonObject = new JsonObject();
+                                    jsonObject.addProperty("homeId", houseIdBean.getHomeId());
+                                    jsonObject.addProperty("homeName", houseIdBean.getHomeName());
+                                    jsonObject.addProperty("powerStationStatus", houseIdBean.getPowerStationStatus() + "");
+                                    HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
+                                    uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_DETAILS);
+                                    uniCallBackBaseBean.setData(jsonObject);
+                                    HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
+                                }
+                            }
+
+                        } catch (Exception e) {
+                            HdlLogLogic.print("鍥炴粴寮傚父", false);
+                        }
+                        if (AppManagerUtils.getAppManager().existsTopActivity(PowerStationsListActivity.class, PowerStationsMoveActivity.class)) {
+                            //瀛樺湪鏍堥噷鍐嶉�氱煡鏇存柊
+                            HdlCommonLogic.getInstance().postEventBus(ConstantManage.REFRESH_HOME_LIST, ConstantManage.REFRESH_HOME_LIST);
+                        }
+                        HdlLogLogic.print(linkResponse.getTopic() + new Gson().toJson(linkResponse.getData()), true);
                     }
 
                 }
@@ -501,5 +674,27 @@
         HDLLinkLocalSdk.getInstance().registerAllTopicsListener(allTopicsListener);
     }
 
-
+    /**
+     * 澶勭悊浠庨�氱煡鐐瑰嚮甯︽潵鐨勬暟鎹紝杩欓噷鑾峰彇鏁版嵁锛岀劧鍚庨�忎紶缁欎富鐣岄潰鍋氬鐞�
+     *
+     * @return 杩斿洖闄勫姞鏁版嵁
+     */
+    private String getIntentExpantData(Intent intent) {
+        try {
+            if (intent == null) {
+                return "";
+            }
+            // 澶勭悊浠庨�氱煡鐐瑰嚮甯︽潵鐨勬暟鎹紝杩欓噷鑾峰彇鏁版嵁锛岀劧鍚庨�忎紶缁欎富鐣岄潰鍋氬鐞�
+            if (intent.getExtras() != null) {
+                for (String key : intent.getExtras().keySet()) {
+                    if (key.equals("pushData")) {
+                        return Objects.requireNonNull(intent.getExtras().get(key)).toString();
+                    }
+                }
+            }
+        } catch (Exception e) {
+            return "";
+        }
+        return "";
+    }
 }

--
Gitblit v1.8.0