From 971a24a9e58a21bc306897fd3ad63012a399f7db Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期五, 23 五月 2025 14:07:18 +0800 Subject: [PATCH] Merge branch '1.2.1' into 1.2.0_google --- app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java | 127 +++++++++++++++++++++++++++++++++--------- 1 files changed, 100 insertions(+), 27 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 97eea5a..0d91bbe 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java @@ -1,19 +1,21 @@ package com.hdl.photovoltaic.ui; +import android.app.ActivityManager; +import android.content.Context; +import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.os.Process; import android.os.SystemClock; import android.text.TextUtils; -import android.util.Log; - -import androidx.annotation.Nullable; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.hdl.linkpm.sdk.core.exception.HDLException; import com.hdl.linkpm.sdk.home.type.HomeType; +import com.hdl.linkpm.sdk.user.HDLLinkPMUser; import com.hdl.photovoltaic.HDLApp; import com.hdl.photovoltaic.R; import com.hdl.photovoltaic.base.CustomBaseActivity; @@ -24,20 +26,20 @@ import com.hdl.photovoltaic.enums.NetworkType; import com.hdl.photovoltaic.listener.CloudCallBeak; 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.HdlResidenceLogic; import com.hdl.photovoltaic.other.HdlThreadLogic; import com.hdl.photovoltaic.other.HdlUniLogic; +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.OidBean; import com.hdl.photovoltaic.uni.HDLUniMP; import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; import com.hdl.photovoltaic.utils.AppManagerUtils; -import com.hdl.photovoltaic.widget.ConfirmationCancelDialog; -import com.hdl.photovoltaic.widget.ConfirmationTipDialog; import com.hdl.sdk.link.HDLLinkLocalSdk; import com.hdl.sdk.link.common.event.EventListener; import com.hdl.sdk.link.core.bean.LinkResponse; @@ -45,8 +47,8 @@ import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; import com.hdl.sdk.link.core.bean.gateway.GatewayBean; import com.hdl.sdk.link.core.config.HDLLinkConfig; -import com.hdl.sdk.link.core.connect.HDLUdpConnect; import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; +//import com.umeng.analytics.MobclickAgent; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; @@ -74,8 +76,8 @@ @Override public void onBindView(Bundle savedInstanceState) { - setNotificationBarBackgroundColor(CustomColor.white); - setStatusBarTextColor(); + setStatusBarTranslucent(); + getWindow().setNavigationBarColor(getColor(R.color.text_FF000000)); //C绔惎鍔ˋpp鑷姩鎵撳紑灏忕▼搴忕數绔欒鎯呯晫闈� startAppAutomaticallyOpenUni(); //娉ㄥ唽鐩戝惉 @@ -84,6 +86,21 @@ this.initMqttClient(); //涓婁紶鏋佸厜娉ㄥ唽ID鍒颁簯绔� this.pushTokens(); + //鑾峰彇浜戠鑴氭湰 + HdlESLocalJsonLogic.getInstance().getAllHdlESLocalJson(); +// mForegroundService= new Intent(this, ForeService.class); +// startService(); + } + + Intent mForegroundService; + + private void startService() { + // Android 8.0浣跨敤startForegroundService鍦ㄥ墠鍙板惎鍔ㄦ柊鏈嶅姟 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(mForegroundService); + } else { + startService(mForegroundService); + } } @Override @@ -102,12 +119,13 @@ runOnUiThread(new Runnable() { @Override public void run() { - //浣庝簬瀹夊崜14鐗堟湰 - if (android.os.Build.VERSION.SDK_INT < 34) { - startAppAutomaticallyOpenUni(false); - } else { - startAppAutomaticallyOpenUni(true); - } + startAppAutomaticallyOpenUni(false); +// //浣庝簬瀹夊崜14鐗堟湰 +// if (android.os.Build.VERSION.SDK_INT < 34) { +// startAppAutomaticallyOpenUni(false); +// } else { +// startAppAutomaticallyOpenUni(false); +// } } }); } @@ -169,7 +187,7 @@ HdlLogLogic.print(event.getTopic() + new Gson().toJson(event.getData()), true); } else if (event.getTopic().contains(ConstantManage.network_change_post)) { // String wifi_ssid = WifiUtils.getInstance().getCurrentConnectWifiSsid();//鑾峰彇WiFi鐨剆sid闇�瑕佷綅缃潈闄愮殑 - HdlLogLogic.print("鐩戝惉缃戠粶鐘舵��--->" + event.getData().toString() + "(" + event.getType() + ")", true); + HdlLogLogic.print("鐩戝惉缃戠粶鐘舵��---" + event.getData().toString() + "(" + event.getType() + ")", true); //绗竴娆″惎鍔ˋpp,浠ュ強鍒囨崲缃戠粶鐨勬椂鍊欐洿鏂� if (TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) { return; @@ -199,6 +217,24 @@ } else if (event.getTopic().contains(HDLUniMP.UNI_EVENT_REPLY_OTHER_MODEL) && event.getType().contains(HDLUniMP.UNI_EVENT_REPLY_OTHER_BACK)) { //鐗╃悊鎸夐敭杩斿洖浜嬩欢(鍖呮嫭宸︽粦绉婚櫎浜嬩欢) killProcessApp(); + } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(event.getType())) { + if (MqttRecvClient.getInstance() != null) { + MqttRecvClient.getInstance().removeAllTopic(); + } + String homeId = event.getData().toString(); + //杩涘幓浣忓畢璇︽儏uni璇诲彇閫嗗彉鍣ㄥ垪琛ㄦ垚鍔熷悗閫氱煡 + 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 + "/#"; + //杩涘幓浣忓畢璇︽儏寮�濮嬭闃呬富棰� + MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topic);//璁㈤槄銆愰�嗗彉鍣ㄣ�戞秷鎭� + + } + String topicHome = "/user/" + homeId + "/#"; + MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topicHome);//璁㈤槄銆愮數绔欍�戞秷鎭� + + } } @@ -208,13 +244,25 @@ */ private void startAppAutomaticallyOpenUni(boolean delay) { - if (delay) { - SystemClock.sleep(2000); +// if (delay) { +// SystemClock.sleep(2000); +// } + if (TextUtils.isEmpty(HDLLinkPMUser.getInstance().getAccessToken())) { + //鍏跺疄鍒锋柊token澶辫触宸查�氱煡閫�鍑虹櫥褰曪紝鏁版嵁宸茬粡娓呯┖锛屽洜涓虹瓑2s uni鍔犺浇鎱㈠鑷磋姹傞摼鎺ョ殑鏃跺�欏嚭鐜皌oken涓虹┖ + HdlLogLogic.print("杩斿洖鍘�---", true); + return; } + UserConfigManage.getInstance().setUniBottomSafeDistanceBackgroundColor(0); List<HouseIdBean> HouseIdList = HdlResidenceLogic.getInstance().getHouseIdList(); - if (HouseIdList.size() == 0) { - String path = HDLUniMP.UNI_EVENT_OPEN_HOME_Null_C; - HdlUniLogic.getInstance().openUniMP(path, null); + 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); + } } else { int select_home = 0; for (int i = 0; i < HouseIdList.size(); i++) { @@ -224,11 +272,13 @@ } } HouseIdBean houseIdBean = HouseIdList.get(select_home); - HdlResidenceLogic.getInstance().switchHouse(houseIdBean); + HdlResidenceLogic.getInstance().switchHouse(houseIdBean, false); String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS_C + "?homeId=" + houseIdBean.getHomeId() + "&homeName=" + houseIdBean.getHomeName() + "&powerStationStatus=" + houseIdBean.getPowerStationStatus(); HdlUniLogic.getInstance().openUniMP(path, null); } + } + // /** // * 鐗╃悊鎸夐敭杩斿洖浜嬩欢(鍖呮嫭宸︽粦绉婚櫎浜嬩欢) @@ -264,6 +314,8 @@ HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP(); } AppManagerUtils.getAppManager().finishAllActivity(); +// //鍙嬬洘sdk濡傛灉寮�鍙戣�呰皟鐢╧ill鎴栬�卐xit涔嬬被鐨勬柟娉曟潃姝昏繘绋嬶紝鎴栬�呭弻鍑籦ack閿細鏉�姝昏繘绋嬶紝璇峰姟蹇呭湪姝や箣鍓嶈皟鐢∕obclickAgent.onKillProcess鏂规硶锛岀敤鏉ヤ繚瀛樼粺璁℃暟鎹�� +// MobclickAgent.onKillProcess(_mActivity); Process.killProcess(Process.myPid()); } } @@ -276,6 +328,7 @@ HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack(); //绉婚櫎鐩戝惉 HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener); +// stopService(mForegroundService); } /** @@ -316,14 +369,14 @@ UserConfigManage.getInstance().Save(); } HDLApp.getInstance().setInfoMap(registrationId_tag, "true");//璁板綍涓�涓嬬姸鎬�,鍚庡彴鏉�姝籥pp浼氭竻绌�; - HdlLogLogic.print("C绔�--->娣诲姞鏋佸厜ID鍒颁簯绔�--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); + HdlLogLogic.print("C绔�---娣诲姞鏋佸厜ID鍒颁簯绔�---registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); } @Override public void onFailure(HDLException e) { HDLApp.getInstance().setInfoMap(registrationId_tag, "false");//璁板綍涓�涓嬬姸鎬�,鍚庡彴鏉�姝籥pp浼氭竻绌�; - HdlLogLogic.print("C绔�--->娣诲姞鏋佸厜ID鍒颁簯绔け璐�--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); + HdlLogLogic.print("C绔�---娣诲姞鏋佸厜ID鍒颁簯绔け璐�---registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); } }); @@ -338,8 +391,8 @@ * 鍒濆鍖杕qtt瀹㈡埛绔� */ public void initMqttClient() { - if (MqttRecvClient.getInstance().isConnected()) { - //妫�鏌ユ柇寮�杩炴帴 + //妫�鏌ユ柇寮�鐘舵�� + if (!MqttRecvClient.getInstance().isConnected()) { MqttRecvClient.getInstance().reConnect(); } if (!MqttRecvClient.getInstance().isInit()) { @@ -349,12 +402,13 @@ if (info != null) { MqttRecvClient.getInstance().setConnectParam(info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord()); MqttRecvClient.getInstance().connect(); + HdlLogLogic.print("mqtt閾炬帴鎴愬姛---ClientId---" + info.getClientId(), true); } } @Override public void onFailure(HDLException e) { - HdlLogLogic.print("璇诲彇mqtt杩滅▼淇℃伅澶辫触--->" + e.getMessage(), e.getCode(), true); + HdlLogLogic.print("璇诲彇mqtt杩滅▼淇℃伅澶辫触---" + e.getMessage(), e.getCode(), true); } }); } @@ -376,7 +430,7 @@ if (response.getTopic() == null) { return; } - HdlLogLogic.print("C绔�--->鐩戝惉鍒癕odbus鏁版嵁--->" + new Gson().toJson(response), false); + HdlLogLogic.print("C绔�---鐩戝惉鍒癕odbus鏁版嵁---" + new Gson().toJson(response), false); // if (response.getTopic().endsWith("custom/native/inverter/up")) { HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); uniCallBackBaseBean.setType(response.getTopic()); @@ -421,7 +475,26 @@ } + } else if (linkResponse.getTopic().endsWith("/app/thing/property/send")) { + //璁惧鐘舵�佸彉鏇磘opic锛�/user/${homeId}/app/thing/property/send + if (linkResponse.getData() == null) { + HdlLogLogic.print("璁惧鐘舵�佸彉鏇�--->鏁版嵁涓虹┖", false); + return; + } + HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); + uniCallBackBaseBean.setType(linkResponse.getTopic()); + uniCallBackBaseBean.setData(linkResponse.getData()); + HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean); + } else if (linkResponse.getTopic().endsWith("custom/wifi/notify")) { + //閫嗗彉鍣ㄨ繛鎺ヨ矾鐢辩姸鎬侀�氱煡 +// HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); +// uniCallBackBaseBean.setType(linkResponse.getTopic()); +// 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鐘舵��-閲嶆柊鎼滅储涓�涓嬮�嗗彉鍣�-閲嶆柊鏇存柊杩炴帴鐘舵�� } + } } }; -- Gitblit v1.8.0