From 989b4cf5a84e898e9682f8d9723a8ba1ff20c23b Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 28 六月 2023 16:55:57 +0800
Subject: [PATCH] Merge branch 'hxb' into wjc
---
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 188 ++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 169 insertions(+), 19 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
index 86bd98f..f362488 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -1,10 +1,25 @@
package com.hdl.photovoltaic.other;
+import android.text.TextUtils;
+
+import com.google.gson.Gson;
+import com.hdl.photovoltaic.HDLApp;
+import com.hdl.photovoltaic.bean.BaseEventBus;
+import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
+import com.hdl.photovoltaic.utils.WifiUtils;
+import com.hdl.sdk.link.HDLLinkLocalSdk;
+import com.hdl.sdk.link.common.exception.HDLLinkException;
+import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
+import com.hdl.sdk.link.core.callback.GatewayCallBack;
+import com.hdl.sdk.link.core.callback.HDLLinkCallBack;
+import com.hdl.sdk.link.core.config.HDLLinkConfig;
+import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
+import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;
@@ -34,7 +49,7 @@
}
/**
- * 鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�
+ * 鍘熺敓鎺ユ敹鍒皍ni鍙戞潵鐨勬暟鎹�
*
* @param appId -uni灏忕▼搴忔寚瀹氱殑appId
* @param event -uni灏忕▼搴忓彂鏉ユ暟鎹�
@@ -43,17 +58,97 @@
*/
@Override
public void onOtherUniMPEventReceive(String appId, String event, Object data, DCUniMPJSCallback callback) {
- if (!HDLUniMP.UNI_APP_ID.equals(appId)) {
- return;
- }
try {
- org.json.JSONObject jsonObject = null;
- if (data != null) {
- jsonObject = new org.json.JSONObject(data.toString());
+ if (!HDLUniMP.UNI_APP_ID.equals(appId)) {
+ return;
}
- if (HDLUniMP.UNI_EVENT_HOME_CREATION.equals(event)) {
+ org.json.JSONObject jsonObject = getJSONObject(data);
+ String type_value = "";
+ String oid="";
+ if (jsonObject.has("type")) {
+ type_value = jsonObject.getString("type");
+ }
+ if (jsonObject.has("oid")) {
+ oid = jsonObject.getString("oid");
+ }
+
+ if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(event)) {
+ //浣忓畢妯″潡
+ switch (type_value) {
+ case HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION: {
+ //鍒涘缓
+ //eventbus閫氱煡
+ BaseEventBus baseEventBus = new BaseEventBus();
+ baseEventBus.setType(ConstantManage.EVENTBUS_POST_HOME_CREATED);
+ EventBus.getDefault().post(baseEventBus);
+
+ }
+ break;
+ case HDLUniMP.UNI_EVENT_REPLY_HOME_DETAILS: {
+ //璇︽儏
+ }
+ break;
+
+ }
if (callback != null) {
- callback.invoke(null);
+ uniCallbackData(null, "0", "", callback);
+ }
+ } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(event)) {
+ //璁惧妯″潡
+ switch (type_value) {
+ case HDLUniMP.UNI_EVENT_REPLY_DEVICE_ADD: {
+ //娣诲姞
+ }
+ break;
+ case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: {
+ //缃戝叧鎼滅储
+ HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() {
+ @Override
+ public void onSuccess(List<GatewayBean> gatewayBeanList) {
+ HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
+ callBackBaseBean.setTopic(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL);
+ callBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_LIST);
+ callBackBaseBean.setData(gatewayBeanList);
+ sendUni(callBackBaseBean);
+ }
+
+
+ @Override
+ public void onError(HDLLinkException e) {
+ //鍙戦�佸け璐�
+ }
+ });
+ }
+ break;
+ case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND:{
+ //鍙戦�乵odbus鍗忚
+
+ }
+ }
+
+ } else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(event)) {
+ WifiUtils wifiUtils = new WifiUtils(HDLApp.getInstance());
+ //wifi妯″潡
+ switch (type_value) {
+ case HDLUniMP.UNI_EVENT_REPLY_WIFI_LIST: {
+ //鑾峰彇wifi鍒楄〃
+ if (callback != null) {
+ uniCallbackData(wifiUtils.getScanResult(), "0", "", callback);
+ }
+ }
+ break;
+ case HDLUniMP.UNI_EVENT_REPLY_WIFI_INFO: {
+ //褰撳墠wifi璇︽儏
+ if (callback != null) {
+ uniCallbackData(wifiUtils.getCurrentConnectWifiInfo(), "0", "", callback);
+ }
+ }
+ break;
+ case HDLUniMP.UNI_EVENT_REPLY_WIFI_CONNECT: {
+ //wifi杩炴帴
+ }
+ break;
+
}
}
HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�", event + "\r\n" + data);
@@ -66,11 +161,13 @@
/**
* 鍘熺敓鎵撳紑uni鎸囧畾椤甸潰
*
- * @param path 鎵撳紑璺緞
+ * @param path 鎵撳紑鍏ㄨ矾寰�
* @param jsonObject 闄勪欢鏁版嵁(娌℃湁鏁版嵁濉玭ull)
*/
public void openUniMP(String path, JSONObject jsonObject) {
- JSONObject json = this.createdJsonDate(jsonObject);
+
+ JSONObject json = this.createdJsonDate(jsonObject, true);
+ HdlLogLogic.print("uni===缁勮uni鍙戦�佹暟鎹牸寮�", json.toString());
HDLUniMPSDKManager.getInstance().openUniMP(HDLUniMP.UNI_APP_ID, path, json, HdlUniLogic.this);
}
@@ -78,15 +175,16 @@
* 鍘熺敓銆愪富鍔ㄣ�戝悜灏忕▼搴忓彂閫侀�氱煡浜嬩欢
* 娉ㄦ剰锛氶渶瑕佹彁鍓嶅皬绋嬪簭鍦ㄨ繍琛屾墠鍙垚鍔�
*
- * @param topic 涓婚
+ * @param topic 涓婚澶х被
+ * @param type 鍔熻兘绫�
* @param body 闄勪欢鏁版嵁(娌℃湁鏁版嵁濉玭ull)
*/
- public void sendUni(String topic, String body) {
+ public void sendUni(String topic, String type, String body) {
try {
HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
- callBackBaseBean.setTopic(topic);
+ callBackBaseBean.setType(type);
callBackBaseBean.setData(body);
- HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.UNI_APP_ID, callBackBaseBean.getJSONObject());
+ HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, topic, getJSONObject(callBackBaseBean));
} catch (Exception e) {
HdlLogLogic.print("uni===鍘熺敓涓诲姩鍚戝皬绋嬪簭鍙戦�侀�氱煡浜嬩欢", e.getMessage());
}
@@ -102,21 +200,73 @@
/**
* 缁勮uni鍙戦�佹暟鎹牸寮�
*
- * @param data -闄勪欢鏁版嵁(娌℃湁鏁版嵁濉玭ull)
+ * @param data -闄勪欢鏁版嵁(娌℃湁鏁版嵁濉玭ull)
+ * @param isTokenAndRefreshToken (true=搴曞眰榛樿娣诲姞token鍜宺efreshToken;false=涓嶅姞)
* @return JSONObject
*/
- public JSONObject createdJsonDate(JSONObject data) {
+ private JSONObject createdJsonDate(JSONObject data, boolean isTokenAndRefreshToken) {
HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
try {
if (data == null) {
data = new JSONObject();
}
- data.put("token", UserConfigManage.getInstance().getToken());
+ if (isTokenAndRefreshToken) {
+ data.put("token", UserConfigManage.getInstance().getToken());
+ data.put("refreshToken", UserConfigManage.getInstance().getRefreshToken());
+ }
uniCallBackBaseBean.setData(data);
- return uniCallBackBaseBean.getJSONObject();
+ return getJSONObject(uniCallBackBaseBean);
} catch (Exception e) {
HdlLogLogic.print("uni===缁勮uni鍙戦�佹暟鎹牸寮�", e.getMessage());
}
return new JSONObject();
}
+
+
+ /**
+ * 缁勮uni鍙戦�佹暟鎹牸寮�
+ * 鍥炶皟鏁版嵁缁檜ni灏忕▼搴�,缁熶竴鍦ㄨ繖閲屽鐞�;
+ *
+ * @param obj 闄勫姞鏁版嵁
+ * @param code 鐘舵�佺爜-鎴愬姛锛�0锛夋垨鑰呭け璐ワ紙-2锛�
+ * @param msg 缁撴灉鎻忚堪鐨勪俊鎭�
+ * @param callback 鍥炶皟
+ */
+ private void uniCallbackData(Object obj, String code, String msg, DCUniMPJSCallback callback) {
+ HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
+ try {
+ uniCallBackBaseBean.setCode(code);
+ uniCallBackBaseBean.setMes(msg);
+ uniCallBackBaseBean.setData(obj);
+ if (callback != null) {
+ callback.invoke(getJSONObject(uniCallBackBaseBean));
+ }
+ } catch (Exception e) {
+ HdlLogLogic.print("uni===缁勮uni鍙戦�佹暟鎹牸寮�", e.getMessage());
+ }
+
+
+ }
+
+ /**
+ * 褰撳墠瀵硅薄杞� JSONObject
+ *
+ * @return JSONObject
+ */
+ private JSONObject getJSONObject(Object obj) {
+ try {
+ if (obj == null) {
+ return new JSONObject();
+ }
+ if (TextUtils.isEmpty(obj.toString())) {
+ return new JSONObject();
+ }
+ String json = new Gson().toJson(obj);
+
+ return new JSONObject(json);
+ } catch (Exception e) {
+ return new JSONObject();
+ }
+ }
}
+
--
Gitblit v1.8.0