From e604e1797744977f599dad9f543db3e7477fe115 Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期三, 12 七月 2023 14:35:58 +0800 Subject: [PATCH] 2023年07月12日14:35:48 --- app/src/main/java/com/hdl/photovoltaic/listener/BaseFailureCallBack.java | 4 .gradle/buildOutputCleanup/buildOutputCleanup.lock | 0 app/src/main/java/com/hdl/photovoltaic/listener/LinkCallBack.java | 10 + .gradle/buildOutputCleanup/outputFiles.bin | 0 app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java | 196 +++++++++---------- app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 26 +- HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java | 2 app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java | 28 +- .idea/workspace.xml | 46 ++- app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java | 2 app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java | 59 +---- app/src/main/java/com/hdl/photovoltaic/other/HdlMqttLogic.java | 9 app/src/main/java/com/hdl/photovoltaic/ui/HomeLoginActivity.java | 6 app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java | 3 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java | 200 +++++++++---------- 15 files changed, 287 insertions(+), 304 deletions(-) diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 8eb7f83..0be4447 100644 --- a/.gradle/buildOutputCleanup/buildOutputCleanup.lock +++ b/.gradle/buildOutputCleanup/buildOutputCleanup.lock Binary files differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 1429825..197fcf4 100644 --- a/.gradle/buildOutputCleanup/outputFiles.bin +++ b/.gradle/buildOutputCleanup/outputFiles.bin Binary files differ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0500206..b1e5a98 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -12,7 +12,23 @@ <option name="autoReloadType" value="NONE" /> </component> <component name="ChangeListManager"> - <list default="true" id="263c1e85-a8b8-438a-bde2-e35109721369" name="Default Changelist" comment="" /> + <list default="true" id="263c1e85-a8b8-438a-bde2-e35109721369" name="Default Changelist" comment=""> + <change afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/listener/LinkCallBack.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/.gradle/buildOutputCleanup/buildOutputCleanup.lock" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/buildOutputCleanup/buildOutputCleanup.lock" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/.gradle/buildOutputCleanup/outputFiles.bin" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/buildOutputCleanup/outputFiles.bin" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java" beforeDir="false" afterPath="$PROJECT_DIR$/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/listener/BaseFailureCallBack.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/listener/BaseFailureCallBack.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlMqttLogic.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlMqttLogic.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/ui/HomeLoginActivity.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/ui/HomeLoginActivity.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java" afterDir="false" /> + </list> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> @@ -23,6 +39,13 @@ <projectState path="$PROJECT_DIR$"> <ProjectState /> </projectState> + </component> + <component name="FileTemplateManagerImpl"> + <option name="RECENT_TEMPLATES"> + <list> + <option value="Interface" /> + </list> + </option> </component> <component name="Git.Settings"> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> @@ -139,24 +162,9 @@ <breakpoint-manager> <breakpoints> <line-breakpoint enabled="true" suspend="THREAD" type="java-line"> - <url>file://$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java</url> - <line>156</line> - <option name="timeStamp" value="28" /> - </line-breakpoint> - <line-breakpoint enabled="true" suspend="THREAD" type="java-line"> - <url>file://$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java</url> - <line>77</line> - <option name="timeStamp" value="33" /> - </line-breakpoint> - <line-breakpoint enabled="true" suspend="THREAD" type="java-line"> - <url>file://$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java</url> - <line>85</line> - <option name="timeStamp" value="34" /> - </line-breakpoint> - <line-breakpoint enabled="true" suspend="THREAD" type="java-line"> - <url>file://$PROJECT_DIR$/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java</url> - <line>68</line> - <option name="timeStamp" value="35" /> + <url>file://$PROJECT_DIR$/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/core/api/HDLCloudUserApi.java</url> + <line>48</line> + <option name="timeStamp" value="40" /> </line-breakpoint> </breakpoints> </breakpoint-manager> diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java index 4bdf82f..200b35e 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java @@ -5,6 +5,6 @@ * * @Description : HDLLinkCallBack */ -public interface HDLLinkCallBack extends BaseCallBack{ +public interface HDLLinkCallBack extends BaseCallBack { void onSuccess(String msg); } diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java index 850f6cb..69222d3 100644 --- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java +++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java @@ -20,6 +20,7 @@ import com.hdl.photovoltaic.config.AppConfigManage; import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak; +import com.hdl.photovoltaic.listener.CloudCallBeak; import com.hdl.photovoltaic.other.HdlLogLogic; import com.hdl.photovoltaic.utils.HDLMD5Utils; @@ -65,18 +66,18 @@ * @param callBack 鍥炶皟 * @return - */ - private Disposable request(String api, String body, BaseSuccessFailureCallBeak callBack) { + private Disposable request(String api, String body, CloudCallBeak<String> callBack) { String requestUrl = HDLCloudUserApi.getRequestUrl(api); return HxHttp.builder() .url(requestUrl) .raw(body) .build() .post() - .subscribeWith(new HDLResponse<HttpResponsePack>() { + .subscribeWith(new HDLResponse<String>() { @Override - public void onResponse(HttpResponsePack response) { + public void onResponse(String str) { if (callBack != null) { - callBack.onSuccess(response); + callBack.onSuccess(str); } } @@ -98,32 +99,35 @@ * @param body 璇锋眰鍙傛暟(json) * @param callBack 鍥炶皟 */ - public Disposable requestHttp(String api, String body, BaseSuccessFailureCallBeak callBack) { + public Disposable requestHttp(String api, String body, CloudCallBeak<String> callBack) { return request(api, body, callBack); } /** - * 璇锋眰鏈嶅姟鍣ㄧ殑鏂规硶 + * 璇锋眰鏈嶅姟鍣ㄧ殑鏂规硶(宸插純鐢�) * * @param requestUrl 璇锋眰鎺ュ彛 * @param json 璇锋眰鏁版嵁 * @param isBasicService 鏄惁鏄熀纭�鏈嶅姟鐨勬帴鍙�(鍩虹鏈嶅姟鐨勬帴鍙i渶瑕� appKey,timestamp,sign杩欎笁涓弬鏁�,褰撲负true鏃�,鍐呴儴浼氳嚜鍔ㄦ坊鍔�) * @param isExecute 鏄惁鏄悓姝�(true=鍚屾,false=寮傛) */ - public void requestHttp(String requestUrl, String json, boolean isBasicService, boolean isExecute, BaseSuccessFailureCallBeak baseSuccessCallBeak) { + @Deprecated + private void requestHttp(String requestUrl, String json, boolean isBasicService, boolean isExecute, BaseSuccessFailureCallBeak baseSuccessCallBeak) { String fullUrl = AppConfigManage.getUserRegionUrl() + requestUrl; this.requestHttps(fullUrl, json, isBasicService, isExecute, baseSuccessCallBeak); } /** - * 璇锋眰鏈嶅姟鍣ㄧ殑鏂规硶(鐩墠鍙敤鍦ㄨ幏鍙栬幏鍙栬处鍙峰尯鍩熶俊鎭�) + * 璇锋眰鏈嶅姟鍣ㄧ殑鏂规硶(宸插純鐢�) + * 鐩墠鍙敤鍦ㄨ幏鍙栬幏鍙栬处鍙峰尯鍩熶俊鎭� * * @param fullUrl 缁濆鍦板潃(鍦板潃+鎺ュ彛) * @param json 璇锋眰鏁版嵁 * @param isBasicService 鏄惁鏄熀纭�鏈嶅姟鐨勬帴鍙�(鍩虹鏈嶅姟鐨勬帴鍙i渶瑕� appKey,timestamp,sign杩欎笁涓弬鏁�,褰撲负true鏃�,鍐呴儴浼氳嚜鍔ㄦ坊鍔�) * @param isExecute 鏄惁鏄悓姝�(true=鍚屾,false=寮傛) */ - public void requestFullHttp(String fullUrl, String json, boolean isBasicService, boolean isExecute, BaseSuccessFailureCallBeak baseSuccessCallBeak) { + @Deprecated + private void requestFullHttp(String fullUrl, String json, boolean isBasicService, boolean isExecute, BaseSuccessFailureCallBeak baseSuccessCallBeak) { this.requestHttps(fullUrl, json, isBasicService, isExecute, baseSuccessCallBeak); } @@ -158,7 +162,7 @@ } else { //throw new IOException("Unexpected code " + response); - baseSuccessCallBeak.onFailure(new Exception()); + baseSuccessCallBeak.onFailure(new HDLException(response.code(), response.message())); } } else { @@ -178,13 +182,13 @@ baseSuccessCallBeak.onSuccess(httpResponsePack); HdlLogLogic.print("http->鍥炲->", "\r\n" + s); } else { - baseSuccessCallBeak.onFailure(new Exception()); + baseSuccessCallBeak.onFailure(new HDLException(response.code(), response.message())); } } }); } } catch (Exception e) { - baseSuccessCallBeak.onFailure(e); + baseSuccessCallBeak.onFailure(new HDLException(-100, e.getMessage())); HdlLogLogic.print("http->鍥炲->", "\r\n" + e.getMessage()); } diff --git a/app/src/main/java/com/hdl/photovoltaic/listener/BaseFailureCallBack.java b/app/src/main/java/com/hdl/photovoltaic/listener/BaseFailureCallBack.java index d287803..b0bcc6f 100644 --- a/app/src/main/java/com/hdl/photovoltaic/listener/BaseFailureCallBack.java +++ b/app/src/main/java/com/hdl/photovoltaic/listener/BaseFailureCallBack.java @@ -1,8 +1,10 @@ package com.hdl.photovoltaic.listener; +import com.hdl.linkpm.sdk.core.exception.HDLException; + public interface BaseFailureCallBack { /** * 澶辫触 */ - void onFailure(Exception exception); + void onFailure(HDLException e); } diff --git a/app/src/main/java/com/hdl/photovoltaic/listener/LinkCallBack.java b/app/src/main/java/com/hdl/photovoltaic/listener/LinkCallBack.java new file mode 100644 index 0000000..1e0e398 --- /dev/null +++ b/app/src/main/java/com/hdl/photovoltaic/listener/LinkCallBack.java @@ -0,0 +1,10 @@ +package com.hdl.photovoltaic.listener; + +import com.hdl.sdk.link.core.callback.BaseCallBack; + +public interface LinkCallBack<T> extends BaseCallBack { + /** + * 鎴愬姛鍥炶皟 + */ + void onSuccess(T obj); +} diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java index fae5e98..136372c 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java @@ -9,15 +9,9 @@ import com.hdl.linkpm.sdk.user.bean.HDLUserRegionBean; import com.hdl.linkpm.sdk.user.callback.ILoginCallBack; import com.hdl.linkpm.sdk.user.callback.IRegionByAccountCallBack; -import com.hdl.linkpm.sdk.user.controller.HDLPMUserController; -import com.hdl.photovoltaic.ui.bean.LoginUserBean; -import com.hdl.photovoltaic.ui.bean.LoginUserRegionBean; -import com.hdl.photovoltaic.bean.HttpResponsePack; -import com.hdl.photovoltaic.config.AppConfigManage; import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.internet.HttpClient; import com.hdl.photovoltaic.internet.api.HttpApi; -import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak; import com.hdl.photovoltaic.listener.CloudCallBeak; import java.util.regex.Matcher; @@ -54,7 +48,7 @@ * @param i_account 璐﹀彿 */ public void regionByAccount(String i_account, CloudCallBeak<HDLUserRegionBean> cloudCallBeak) { - HDLPMUserController.getInstance().regionByAccount(i_account, new IRegionByAccountCallBack() { + HDLLinkPMUser.getInstance().regionByAccount(i_account, new IRegionByAccountCallBack() { @Override public void onSuccess(HDLUserRegionBean regionBean) { if (cloudCallBeak != null) { @@ -86,11 +80,12 @@ json.addProperty("loginPwd", loginPwd); // json.addProperty("platform", "APP"); json.addProperty("grantType", "password"); - HDLPMUserController.getInstance().loginByPassword(account, loginPwd, new ILoginCallBack() { + HDLLinkPMUser.getInstance().loginByPassword(account, loginPwd, new ILoginCallBack() { @Override public void onSuccess(HDLLoginBean loginBean) { if (callBack != null) { + saveUserData(loginBean); callBack.onSuccess(loginBean); } } @@ -102,27 +97,7 @@ } } }); -// HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { -// @Override -// public void onSuccess(HttpResponsePack httpResponsePack) { -// if (httpResponsePack != null && httpResponsePack.getData() != null) { -// Gson gson = new Gson(); -// String json = gson.toJson(httpResponsePack.getData()); -// LoginUserBean loginUserBean = new Gson().fromJson(json, LoginUserBean.class); -// saveUserData(loginUserBean); -// if (cloudCallBeak != null) { -// cloudCallBeak.onSuccess(loginUserBean); -// } -// } -// } -// -// @Override -// public void onFailure(Exception exception) { -// if (cloudCallBeak != null) { -// cloudCallBeak.onFailure(exception); -// } -// } -// }); + } /** @@ -132,30 +107,26 @@ * @param loginPwd 瀵嗙爜 * @param cloudCallBeak - */ - public void refreshToken(String account, String loginPwd, CloudCallBeak<LoginUserBean> cloudCallBeak) { + public void refreshToken(String account, String loginPwd, CloudCallBeak<HDLLoginBean> cloudCallBeak) { String requestUrl = HttpApi.POST_Login; JsonObject json = new JsonObject(); json.addProperty("grantType", "refresh_token"); // json.addProperty("refreshToken", UserConfigManage.getInstance().getRefreshToken()); - - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { - if (httpResponsePack != null && httpResponsePack.getData() != null) { - Gson gson = new Gson(); - String json = gson.toJson(httpResponsePack.getData()); - LoginUserBean loginUserBean = new Gson().fromJson(json, LoginUserBean.class); - saveUserData(loginUserBean); - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(loginUserBean); - } + public void onSuccess(String jsonStr) { + Gson gson = new Gson(); + HDLLoginBean loginBean = gson.fromJson(jsonStr, HDLLoginBean.class); +// saveUserData(loginBean); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(loginBean); } } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -184,7 +155,7 @@ /** * 鐧诲綍鎴愬姛淇濆瓨鐧诲綍淇℃伅 */ - private void saveUserData(LoginUserBean obj) { + private void saveUserData(HDLLoginBean obj) { if (obj != null) { UserConfigManage.getInstance().setLogin(true);//鏄惁鐧诲綍 UserConfigManage.getInstance().setAcceiptPolicy(true);//鏄惁閫夋嫨闅愮鏀跨瓥 diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java index 08d8f54..a0ca15f 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java @@ -7,6 +7,7 @@ import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.hdl.hdlhttp.HxHttp; +import com.hdl.linkpm.sdk.core.exception.HDLException; import com.hdl.photovoltaic.bean.HttpResponsePack; import com.hdl.photovoltaic.config.AppConfigManage; import com.hdl.photovoltaic.config.UserConfigManage; @@ -16,6 +17,7 @@ import com.hdl.photovoltaic.internet.api.TopicApi; import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak; import com.hdl.photovoltaic.listener.CloudCallBeak; +import com.hdl.photovoltaic.listener.LinkCallBack; import com.hdl.photovoltaic.ui.bean.CloudInverterChildDeviceBean; import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; import com.hdl.photovoltaic.ui.bean.InverterDeviceBean; @@ -80,18 +82,18 @@ json.addProperty("name", name); // json.addProperty("zoneType", "password");//鍖哄煙 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String str) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); } } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -109,29 +111,24 @@ json.addProperty("homeId", homeId); // json.addProperty("zoneType", "password");//鍖哄煙 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { - try { - if (httpResponsePack != null && httpResponsePack.getData() != null) { - Gson gson = new Gson(); - String json = gson.toJson(httpResponsePack.getData()); - Type type = new TypeToken<List<CloudInverterDeviceBean>>() { - }.getType(); - List<CloudInverterDeviceBean> list = new Gson().fromJson(json, type); - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); - } - } - } catch (Exception e) { + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(e); + cloudCallBeak.onSuccess(null); } + } + Type type = new TypeToken<List<CloudInverterDeviceBean>>() { + }.getType(); + List<CloudInverterDeviceBean> list = new Gson().fromJson(jsonStr, type); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); } } @Override - public void onFailure(Exception e) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { cloudCallBeak.onFailure(e); } @@ -153,18 +150,18 @@ json.addProperty("deviceId", deviceId); // json.addProperty("zoneType", "password");//鍖哄煙 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String str) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); } } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -183,25 +180,28 @@ json.addProperty("parentOid", parentOid); // json.addProperty("zoneType", "password");//鍖哄煙 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { - if (httpResponsePack != null && httpResponsePack.getData() != null) { - Gson gson = new Gson(); - String json = gson.toJson(httpResponsePack.getData()); - Type typeOfT = new TypeToken<List<CloudInverterChildDeviceBean>>() { - }.getType(); - List<CloudInverterChildDeviceBean> list = gson.fromJson(json, typeOfT); + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); + cloudCallBeak.onSuccess(null); } + return; + } + Gson gson = new Gson(); + Type typeOfT = new TypeToken<List<CloudInverterChildDeviceBean>>() { + }.getType(); + List<CloudInverterChildDeviceBean> list = gson.fromJson(jsonStr, typeOfT); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); } } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -236,9 +236,9 @@ json.add("devices", jsonArray); // json.addProperty("zoneType", "password");//鍖哄煙 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String str) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); @@ -247,9 +247,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -260,10 +260,10 @@ /** * 璁剧疆缃戝叧杩滅▼鍙傛暟 * - * @param mac 璁惧mac - * @param cloudCallBeak 鍥炶皟update + * @param mac 璁惧mac + * @param linkCallBack 鍥炶皟update */ - public void steGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) { + public void steGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) { String requestUrl = TopicApi.SET_GATEWAY_REMOTE_EDIT; JsonObject json = new JsonObject(); json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); @@ -279,16 +279,16 @@ gatewayBean.setLocalEncrypt(true); } } - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(true); + if (linkCallBack != null) { + linkCallBack.onSuccess(true); } } @Override public void onError(HDLLinkException e) { - if (cloudCallBeak != null) { - cloudCallBeak.onFailure(e); + if (linkCallBack != null) { + linkCallBack.onError(e); } } }); @@ -297,25 +297,25 @@ /** * 缂栬緫缃戝叧鍙傛暟 * - * @param mac 璁惧mac - * @param cloudCallBeak 鍥炶皟update + * @param mac 璁惧mac + * @param linkCallBack 鍥炶皟update */ - public void editGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) { + public void editGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) { String requestUrl = TopicApi.SET_GATEWAY_EDIT; JsonObject json = new JsonObject(); json.addProperty("master", "true"); TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { @Override public void onSuccess(String msg) { - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(true); + if (linkCallBack != null) { + linkCallBack.onSuccess(true); } } @Override public void onError(HDLLinkException e) { - if (cloudCallBeak != null) { - cloudCallBeak.onFailure(e); + if (linkCallBack != null) { + linkCallBack.onError(e); } } }); @@ -326,39 +326,31 @@ /** * 鑾峰彇缃戝叧璇︽儏淇℃伅 * - * @param mac 缃戝叧mac - * @param cloudCallBeak 鍥炶皟 + * @param mac 缃戝叧mac + * @param linkCallBack 鍥炶皟 */ - public void getGatewayInfo(String mac, CloudCallBeak<GatewayBean> cloudCallBeak) { + public void getGatewayInfo(String mac, LinkCallBack<GatewayBean> linkCallBack) { String requestUrl = TopicApi.GET_GATEWAY_INFO; TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() { @Override - public void onSuccess(String msg) { - try { - if (!TextUtils.isEmpty(msg)) { - Gson gson = new Gson(); - String json = gson.toJson(msg); - GatewayBean gatewayBean = gson.fromJson(json, GatewayBean.class); - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(gatewayBean); - } - } else { - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(new GatewayBean()); - } + public void onSuccess(String json) { + if (TextUtils.isEmpty(json)) { + if (linkCallBack != null) { + linkCallBack.onSuccess(null); } - - } catch (Exception e) { - if (cloudCallBeak != null) { - cloudCallBeak.onFailure(e); - } + return; + } + Gson gson = new Gson(); + GatewayBean gatewayBean = gson.fromJson(json, GatewayBean.class); + if (linkCallBack != null) { + linkCallBack.onSuccess(gatewayBean); } } @Override public void onError(HDLLinkException e) { - if (cloudCallBeak != null) { - cloudCallBeak.onFailure(e); + if (linkCallBack != null) { + linkCallBack.onError(e); } } }); @@ -368,41 +360,33 @@ /** * 鑾峰彇缃戝叧oid鍒楄〃 * - * @param mac 缃戝叧mac - * @param cloudCallBeak 鍥炶皟 + * @param mac 缃戝叧mac + * @param linkCallBack 鍥炶皟 */ - public void getGatewayOidList(String mac, CloudCallBeak<List<OidBean>> cloudCallBeak) { + public void getGatewayOidList(String mac, LinkCallBack<List<OidBean>> linkCallBack) { String requestUrl = TopicApi.GET_GATEWAY_OID_LIST; TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() { @Override - public void onSuccess(String msg) { - try { - if (!TextUtils.isEmpty(msg)) { - Gson gson = new Gson(); - String json = gson.toJson(msg); - Type typeOfT = new TypeToken<List<OidBean>>() { - }.getType(); - List<OidBean> list = gson.fromJson(json, typeOfT); - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); - } - } else { - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(new ArrayList<>()); - } + public void onSuccess(String json) { + if (TextUtils.isEmpty(json)) { + if (linkCallBack != null) { + linkCallBack.onSuccess(null); } - - } catch (Exception e) { - if (cloudCallBeak != null) { - cloudCallBeak.onFailure(e); - } + return; + } + Gson gson = new Gson(); + Type typeOfT = new TypeToken<List<OidBean>>() { + }.getType(); + List<OidBean> list = gson.fromJson(json, typeOfT); + if (linkCallBack != null) { + linkCallBack.onSuccess(list); } } @Override public void onError(HDLLinkException e) { - if (cloudCallBeak != null) { - cloudCallBeak.onFailure(e); + if (linkCallBack != null) { + linkCallBack.onError(e); } } }); @@ -422,9 +406,9 @@ HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { @Override public void onSuccess(List<CloudInverterDeviceBean> list) { - if (list == null) { - //浜戠娌℃湁缁戝畾閫嗗彉鍣�,娓呯┖鏈湴鍒楄〃; - HDLLinkLocalGateway.getInstance().getGatewayList().clear(); + if (list == null || list.size() == 0) { +// //浜戠娌℃湁缁戝畾閫嗗彉鍣�,娓呯┖鏈湴鍒楄〃; +// HDLLinkLocalGateway.getInstance().getGatewayList().clear(); if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); } @@ -454,9 +438,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -500,9 +484,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlMqttLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlMqttLogic.java index 35720bf..233b542 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlMqttLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlMqttLogic.java @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.hdl.hdlhttp.HxHttp; +import com.hdl.linkpm.sdk.core.exception.HDLException; import com.hdl.photovoltaic.bean.HttpResponsePack; import com.hdl.photovoltaic.internet.HttpClient; import com.hdl.photovoltaic.internet.api.HttpApi; @@ -53,9 +54,9 @@ json.addProperty("homeId", homeId); json.addProperty("spk", spk); json.addProperty("mac", mac); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String jsonStr) { // if (httpResponsePack != null && httpResponsePack.getData() != null) { // Gson gson = new Gson(); // String json = gson.toJson(httpResponsePack.getData()); @@ -68,9 +69,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java index 674b46e..73e33cb 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java @@ -1,9 +1,12 @@ package com.hdl.photovoltaic.other; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.text.TextUtils; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.hdl.linkpm.sdk.core.exception.HDLException; import com.hdl.photovoltaic.bean.HttpResponsePack; import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.internet.HttpClient; @@ -19,6 +22,7 @@ import com.hdl.sdk.link.core.config.HDLLinkConfig; import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -128,12 +132,12 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { atomicInteger.set(atomicInteger.get() + 1); if (atomicInteger.get() == houseIdList.size()) { //鏈�鍚庝竴鏉¢��鍑� if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } } @@ -148,9 +152,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -160,8 +164,11 @@ /** * 鑾峰彇浣忓畢(鐢电珯)ID鍒楄〃 * - * @param key 鍙戠數鍔熺巼鎺掑簭(powerSort);浠婃棩鍙戠數閲忔帓搴�(todayElectricitySort);鍒涘缓鏃堕棿鎺掑簭(createTimeSort); - * @param keyValue (descending:闄嶅簭ascending:鍗囧簭), + * @param key 鍙戠數鍔熺巼鎺掑簭(powerSort); + * 浠婃棩鍙戠數閲忔帓搴�(todayElectricitySort); + * 鍒涘缓鏃堕棿鎺掑簭(createTimeSort); + * @param keyValue (descending:闄嶅簭 + * ascending:鍗囧簭), */ public void getResidenceIdList(String key, String keyValue, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { @@ -170,72 +177,66 @@ if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(keyValue)) { json.addProperty(key, keyValue);//鍙戠數鍔熺巼鎺掑簭(descending:闄嶅簭ascending:鍗囧簭) } -// json.addProperty("powerSort", "descending");//鍙戠數鍔熺巼鎺掑簭(descending:闄嶅簭ascending:鍗囧簭) -// json.addProperty("todayElectricitySort", "descending");//浠婃棩鍙戠數閲忔帓搴� -// json.addProperty("createTimeSort", "descending");//鍒涘缓鏃堕棿鎺掑簭 // json.addProperty("zoneType", "password");//鍖哄煙 json.addProperty("pageNo", 1);//椤电爜 json.addProperty("pageSize", pageSize);//椤垫暟 List<HouseIdBean> list = new ArrayList<>(); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { - if (httpResponsePack != null && httpResponsePack.getData() != null) { - Gson gson = new Gson(); - String jsonStr = gson.toJson(httpResponsePack.getData()); - HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); - list.addAll(houseInfoBeanClass.getList()); - //鎬诲叡鏈夊灏戦〉 - long totalPage = houseInfoBeanClass.totalPage; - if (totalPage < 2) { - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); - } - return; - } - //璁板綍璇锋眰鏉℃暟 - AtomicInteger atomicInteger = new AtomicInteger(0); - //浠庣浜岄〉鑾峰彇鏁版嵁 - for (int i = 2; i <= totalPage; i++) { - json.addProperty("pageNo", i);//鏇存柊椤电爜 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { - @Override - public void onSuccess(HttpResponsePack httpResponsePack) { - atomicInteger.set(atomicInteger.get() + 1); - Gson gson = new Gson(); - String jsonStr = gson.toJson(httpResponsePack.getData()); - HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); - list.addAll(houseInfoBeanClass.getList()); - if (atomicInteger.get() == totalPage - 1) { - //鏈�鍚庝竴鏉¢��鍑� - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); - } - } - } - - @Override - public void onFailure(Exception exception) { - atomicInteger.set(atomicInteger.get() + 1); - if (atomicInteger.get() == totalPage - 1) { - //鏈�鍚庝竴鏉¢��鍑� - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); - } - } - } - }); - } - - } else { + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(list); } } + Gson gson = new Gson(); + HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); + list.addAll(houseInfoBeanClass.getList()); + //鎬诲叡鏈夊灏戦〉 + long totalPage = houseInfoBeanClass.totalPage; + if (totalPage < 2) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); + } + return; + } + //璁板綍璇锋眰鏉℃暟 + AtomicInteger atomicInteger = new AtomicInteger(0); + //浠庣浜岄〉鑾峰彇鏁版嵁 + for (int i = 2; i <= totalPage; i++) { + json.addProperty("pageNo", i);//鏇存柊椤电爜 + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { + @Override + public void onSuccess(String jsonStr) { + atomicInteger.set(atomicInteger.get() + 1); + Gson gson = new Gson(); + HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); + list.addAll(houseInfoBeanClass.getList()); + if (atomicInteger.get() == totalPage - 1) { + //鏈�鍚庝竴鏉¢��鍑� + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); + } + } + } + + @Override + public void onFailure(HDLException e) { + atomicInteger.set(atomicInteger.get() + 1); + if (atomicInteger.get() == totalPage - 1) { + //鏈�鍚庝竴鏉¢��鍑� + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); + } + } + } + }); + } + } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException exception) { if (cloudCallBeak != null) { cloudCallBeak.onFailure(exception); } @@ -256,30 +257,25 @@ JsonObject json = new JsonObject(); json.addProperty("homeId", homeId);//鐢电珯id //json.addProperty("zoneType", "password");//鍖哄煙 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { - try { - if (httpResponsePack != null && httpResponsePack.getData() != null) { - Gson gson = new Gson(); - String jsonStr = gson.toJson(httpResponsePack.getData()); - HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class); - - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(houseInfoBean); - } - } - } catch (Exception exception) { + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onSuccess(null); } + } + Gson gson = new Gson(); + HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(houseInfoBean); } } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -319,9 +315,9 @@ json.addProperty("electrovalence", houseInfoBean.getElectrovalence()); json.addProperty("totalCost", houseInfoBean.getTotalCost()); json.addProperty("zoneType", houseInfoBean.getZoneType()); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String str) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); } @@ -329,9 +325,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -348,9 +344,9 @@ JsonObject json = new JsonObject(); json.addProperty("homeId", homeId);//鐢电珯id //json.addProperty("zoneType", "password");//鍖哄煙 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String str) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); } @@ -358,9 +354,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -398,9 +394,9 @@ json.addProperty("electrovalence", houseInfoBean.getElectrovalence()); json.addProperty("totalCost", houseInfoBean.getTotalCost()); json.addProperty("zoneType", houseInfoBean.getZoneType()); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String str) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); } @@ -408,9 +404,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -421,28 +417,28 @@ /** * 鑾峰彇浣忓畢鍥剧墖 */ - public void getResidenceImage(String imageUrl, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { + public void getResidenceImage(String imageUrl, CloudCallBeak<Bitmap> cloudCallBeak) { String requestUrl = imageUrl; JsonObject json = new JsonObject(); - List<HouseIdBean> list = new ArrayList<>(); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { - if (httpResponsePack != null && httpResponsePack.getData() != null) { - Gson gson = new Gson(); - String jsonStr = gson.toJson(httpResponsePack.getData()); - HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); - } else { + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); + cloudCallBeak.onSuccess(null); } + return; + } + Bitmap bitmap = BitmapFactory.decodeByteArray(jsonStr.getBytes(), 0, jsonStr.getBytes().length); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(bitmap); } } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); 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 2e8325e..5837237 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java @@ -4,12 +4,14 @@ import android.text.TextUtils; import com.google.gson.Gson; +import com.hdl.linkpm.sdk.core.exception.HDLException; import com.hdl.photovoltaic.HDLApp; import com.hdl.photovoltaic.bean.BaseEventBus; import com.hdl.photovoltaic.bean.ModBusBean; import com.hdl.photovoltaic.config.ConstantManage; import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.listener.CloudCallBeak; +import com.hdl.photovoltaic.listener.LinkCallBack; import com.hdl.photovoltaic.ui.bean.OidBean; import com.hdl.photovoltaic.uni.HDLUniMP; import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; @@ -96,10 +98,10 @@ case HDLUniMP.UNI_EVENT_REPLY_DEVICE_ADD: { //娣诲姞璁惧鍒颁簯绔� String mac = getKeyValue("mac", getKeyValue("data", data)); - HdlDeviceLogic.getInstance().steGatewayParam(mac, new CloudCallBeak<Boolean>() { + HdlDeviceLogic.getInstance().steGatewayParam(mac, new LinkCallBack<Boolean>() { @Override public void onSuccess(Boolean obj) { - HdlDeviceLogic.getInstance().editGatewayParam(mac, new CloudCallBeak<Boolean>() { + HdlDeviceLogic.getInstance().editGatewayParam(mac, new LinkCallBack<Boolean>() { @Override public void onSuccess(Boolean obj) { GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac); @@ -119,22 +121,22 @@ } @Override - public void onFailure(Exception exception) { - uniCallbackData(null, -100, exception.getMessage(), callback); + public void onFailure(HDLException e) { + uniCallbackData(null, -100, e.getMessage(), callback); } }); } @Override - public void onFailure(Exception exception) { - uniCallbackData(null, -100, exception.getMessage(), callback); + public void onError(HDLLinkException e) { + uniCallbackData(null, -100, e.getMessage(), callback); } }); } @Override - public void onFailure(Exception exception) { - uniCallbackData(null, -100, exception.getMessage(), callback); + public void onError(HDLLinkException e) { + uniCallbackData(null, -100, e.getMessage(), callback); } }); @@ -168,9 +170,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (callback != null) { - uniCallbackData(null, -2, exception.getMessage(), callback); + uniCallbackData(null, -2, e.getMessage(), callback); } } }); @@ -184,7 +186,7 @@ //娣诲姞璁惧鍒颁簯绔� String mac = getKeyValue("mac", getKeyValue("data", data)); //鑾峰彇oid鍒楄〃 - HdlDeviceLogic.getInstance().getGatewayOidList(mac, new CloudCallBeak<List<OidBean>>() { + HdlDeviceLogic.getInstance().getGatewayOidList(mac, new LinkCallBack<List<OidBean>>() { @Override public void onSuccess(List<OidBean> list) { if (callback != null) { @@ -193,7 +195,7 @@ } @Override - public void onFailure(Exception e) { + public void onError(HDLLinkException e) { uniCallbackData(null, -2, e.getMessage(), callback); } }); diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/HomeLoginActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/HomeLoginActivity.java index 30d97f7..f7b224c 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/HomeLoginActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/HomeLoginActivity.java @@ -24,6 +24,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.hdl.linkpm.sdk.core.exception.HDLException; +import com.hdl.linkpm.sdk.user.HDLLinkPMUser; import com.hdl.linkpm.sdk.user.bean.HDLLoginBean; import com.hdl.linkpm.sdk.user.bean.HDLUserRegionBean; import com.hdl.linkpm.sdk.user.callback.ILoginCallBack; @@ -210,6 +211,7 @@ @Override public void onSuccess(HDLUserRegionBean obj) { AppConfigManage.setUserRegionUrl("http://59.41.255.150:7777");//obj.getRegionUrl() + HDLLinkPMUser.getInstance().setUserRegionUrl(AppConfigManage.getUserRegionUrl()); HdlAccountLogic.getInstance().loginByPassword(account, password, new ILoginCallBack() { @Override public void onSuccess(HDLLoginBean obj) { @@ -223,7 +225,7 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { hideLoading(); restoreButtonStyleToInitializeState(); startActivity(MyPowerStationActivity.class); @@ -239,7 +241,7 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { hideLoading(); } }); diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java index c3d01fb..86c279e 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java @@ -23,6 +23,8 @@ import com.hdl.sdk.link.common.event.EventListener; import com.hdl.sdk.link.core.bean.LinkResponse; +import java.nio.charset.StandardCharsets; + public class MyPowerStationActivity extends CustomBaseActivity { diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java index 79b5f4e..15ab92b 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import com.hdl.linkpm.sdk.core.exception.HDLException; import com.hdl.photovoltaic.R; import com.hdl.photovoltaic.bean.BaseEventBus; import com.hdl.photovoltaic.config.ConstantManage; @@ -176,7 +177,7 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { HdlThreadLogic.runMainThread(new Runnable() { @Override public void run() { -- Gitblit v1.8.0