From a034e242fe844a1ca45d2a28710cb7face1f8fe6 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期日, 28 四月 2024 19:07:56 +0800
Subject: [PATCH] 2024年04月28日19:07:49

---
 app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java |   87 ++++++++++++++++++++++++++-----------------
 1 files changed, 52 insertions(+), 35 deletions(-)

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 f896bfc..5c94e11 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
@@ -38,6 +38,7 @@
 import com.hdl.photovoltaic.widget.DelayedConfirmationCancelDialog;
 import com.hdl.sdk.link.common.exception.HDLLinkException;
 import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
+import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
 import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient;
 
 import java.util.ArrayList;
@@ -103,9 +104,13 @@
 
             @Override
             public void onMoveClick(int position, HouseIdBean houseIdBean) {
+                if (position == 0) {
+                    HdlThreadLogic.toast(_mActivity, getString(R.string.already_the_first_one));
+                    return;
+                }
                 String frontHomeId = "";
-                if (position > 0) {
-                    frontHomeId = houseListBeanIDList.get(position - 1).getHomeId();
+                if (position > 1) {
+                    frontHomeId = houseListBeanIDList.get(position - 2).getHomeId();
                 }
                 HdlResidenceLogic.getInstance().moveResidence(houseIdBean.getHomeId(), frontHomeId, new CloudCallBeak<Boolean>() {
                     @Override
@@ -128,17 +133,33 @@
 
             @Override
             public void onDelClick(int position, HouseIdBean houseIdBean) {
+
                 DelayedConfirmationCancelDialog delayedConfirmationCancelDialog = new DelayedConfirmationCancelDialog(_mActivity);
                 delayedConfirmationCancelDialog.setTitleContent(getString(R.string.loading_title_tip));
                 String homeName = "\"" + houseIdBean.getHomeName() + "\"";
                 delayedConfirmationCancelDialog.setContent(getString(R.string.delete_power_station).replace("%s", homeName));
                 delayedConfirmationCancelDialog.show();
-                delayedConfirmationCancelDialog.startCountdown(3);
+                delayedConfirmationCancelDialog.startCountdown(4);
                 delayedConfirmationCancelDialog.setYesOnclickListener(new DelayedConfirmationCancelDialog.onYesOnclickListener() {
                     @Override
                     public void Confirm() {
                         delayedConfirmationCancelDialog.dismiss();
-                        delete(houseIdBean.getHomeId());
+                        showLoading(getString(R.string.deleting_please_wait));
+                        HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(houseIdBean.getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
+                            @Override
+                            public void onSuccess(List<GatewayBean> list) {
+                                //鍙戣捣鍒犻櫎鐢电珯鎸囦护
+                                deleteResidence(houseIdBean.getHomeId(), list);
+
+                            }
+
+                            @Override
+                            public void onFailure(HDLException e) {
+                                //鍙戣捣鍒犻櫎鐢电珯鎸囦护
+                                deleteResidence(houseIdBean.getHomeId(), null);
+                            }
+                        });
+
 //                        //鍒犻櫎浣忓畢
 //                        HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() {
 //                            @Override
@@ -242,7 +263,6 @@
 
             }
         } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE.equals(eventBus.getType())) {
-
             //uin鍏抽棴浣忓畢璇︽儏鐣岄潰閫氱煡
             if (MqttRecvClient.getInstance() != null) {
                 MqttRecvClient.getInstance().removeAllTopic();
@@ -254,7 +274,7 @@
             for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).size(); i++) {
                 String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).get(i).getGatewayId();
                 //瀛楃涓叉槸鑷繁鎸夎鍒欐嫾鎺ョ殑,閲岄潰娉ㄥ唽涓婚鏃朵細瑙f瀽瀛楃涓�,鍙嬁getGatewayId()鍊�;
-                String topic = "/user/" + gatewayId + "/1";
+                String topic = "/user/" + gatewayId + "/#";
                 //杩涘幓浣忓畢璇︽儏寮�濮嬭闃呬富棰�
                 MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topic);
             }
@@ -378,50 +398,45 @@
 
     /**
      * 鍒犻櫎鐢电珯,閫嗗彉鍣�
-     * (鍏堣幏鍙栦簯绔笂閫嗗彉鍣ㄥ垪琛�,寮�濮嬪垹闄ょ數绔欙紝鍚屾椂锛屽悜閫嗗彉鍣ㄥ彂閫佸垵濮嬪寲閫嗗彉鍣ㄦ寚浠�)
+     * (寮�濮嬪垹闄ょ數绔欙紝鍚屾椂锛屽悜閫嗗彉鍣ㄥ彂閫佸垵濮嬪寲閫嗗彉鍣ㄦ寚浠�,鏃犻』澶勭悊缁撴灉)
      *
-     * @param homeId 鐢电珯id
+     * @param list 璁惧鍒楄〃
      */
-    private void delete(String homeId) {
-        HdlDeviceLogic.getInstance().getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
-            @Override
-            public void onSuccess(List<CloudInverterDeviceBean> list) {
-                deleteResidence(homeId);
-                if (list != null) {
-                    for (int i = 0; i < list.size(); i++) {
-                        CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
-                        HdlDeviceLogic.getInstance().initializeGateway(cloudInverterDeviceBean.getOsn(), new LinkCallBack<Boolean>() {
-                            @Override
-                            public void onSuccess(Boolean obj) {
-                                HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄦ垚鍔�-->mac:" + cloudInverterDeviceBean.getOsn());
-                            }
-
-                            @Override
-                            public void onError(HDLLinkException e) {
-                                HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄥけ璐�-->mac:" + cloudInverterDeviceBean.getOsn());
-                            }
-                        });
-                    }
+    private void initializeInverter(List<GatewayBean> list) {
+        if (list == null || list.size() == 0) {
+            return;
+        }
+        for (int i = 0; i < list.size(); i++) {
+            GatewayBean gatewayBean = list.get(i);
+            HdlDeviceLogic.getInstance().initializeGateway(gatewayBean.getDevice_mac(), new LinkCallBack<Boolean>() {
+                @Override
+                public void onSuccess(Boolean obj) {
+//                                HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄦ垚鍔�-->mac:" + cloudInverterDeviceBean.getOsn(),true);
                 }
-            }
 
-            @Override
-            public void onFailure(HDLException e) {
-                deleteResidence(homeId);
-            }
-        });
+                @Override
+                public void onError(HDLLinkException e) {
+//                                HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄥけ璐�-->mac:" + cloudInverterDeviceBean.getOsn(),true);
+                }
+            });
+        }
     }
 
     /**
      * 鍒犻櫎鐢电珯
      *
      * @param homeId 鐢电珯id
+     * @param list   閫嗗彉鍣ㄥ垪琛�
      */
-    private void deleteResidence(String homeId) {
+    private void deleteResidence(String homeId, List<GatewayBean> list) {
+
         //鍒犻櫎浣忓畢
         HdlResidenceLogic.getInstance().delResidence(homeId, new CloudCallBeak<Boolean>() {
             @Override
             public void onSuccess(Boolean obj) {
+                hideLoading();
+                //鍙戣捣鍒濆鍖栨寚浠ょ粰閫嗗彉鍣�;
+                initializeInverter(list);
                 HdlResidenceLogic.getInstance().delHouseId(homeId);
                 initData();//鍒濆鍖栫紦瀛樻暟鎹�
                 houseInfoAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
@@ -430,6 +445,8 @@
 
             @Override
             public void onFailure(HDLException e) {
+                hideLoading();
+
                 HdlThreadLogic.toast(_mActivity, e);
             }
         });

--
Gitblit v1.8.0