From 4598b51c90c695c9ccbe5350a84e4a46b9d8e587 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期三, 22 五月 2024 20:19:02 +0800
Subject: [PATCH] 2024年05月22日20:18:54

---
 app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListEditActivity.java |   89 +++++++++++++++++++++++++-------------------
 1 files changed, 51 insertions(+), 38 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListEditActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListEditActivity.java
index 5a97c8e..511f6e9 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListEditActivity.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListEditActivity.java
@@ -27,6 +27,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 org.greenrobot.eventbus.EventBus;
 
@@ -72,16 +73,23 @@
         }
     }
 
+    @Override
+    public void onBackPressed() {
+        super.onBackPressed();
+        sendEventBus();
+    }
+
+    private void sendEventBus() {
+        HdlCommonLogic.getInstance().postEventBus(ConstantManage.homepage_title_tab_switch, ConstantManage.station_edit);
+        finish();
+    }
+
     private void initEvent() {
         //杩斿洖鎸夐挳
-        viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setOnClickListener(new View.OnClickListener() {
+        viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                BaseEventBus baseEventBus = new BaseEventBus();
-                baseEventBus.setTopic(ConstantManage.homepage_title_tab_switch);
-                baseEventBus.setType(HomepageTitleTabSwitch.powerstation.toString());
-                EventBus.getDefault().post(baseEventBus);
-                finish();
+                sendEventBus();
             }
         });
 
@@ -100,11 +108,12 @@
                 @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 > 1) {
-                        frontHomeId = houseListBeanIDList.get(position - 1).getHomeId();
+                        frontHomeId = houseListBeanIDList.get(position - 2).getHomeId();
                     }
                     HdlResidenceLogic.getInstance().moveResidence(houseIdBean.getHomeId(), frontHomeId, new CloudCallBeak<Boolean>() {
                         @Override
@@ -134,12 +143,24 @@
                     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());
+                                    initializeInverter(list);
+                                }
+
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    deleteResidence(houseIdBean.getHomeId());
+                                }
+                            });
 //                            //鍒犻櫎浣忓畢
 //                            HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() {
 //                                @Override
@@ -172,7 +193,7 @@
 
     private void initView() {
         viewBinding.toolbarTopFragmentHouseListRl.getRoot().setBackgroundColor(getColor(R.color.text_FFFFFFFF));
-        viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setVisibility(View.VISIBLE);
+        viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setVisibility(View.VISIBLE);
         viewBinding.toolbarTopFragmentHouseListRl.topLeftIv.setImageResource(R.drawable.back_c);
         viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.power_station_editing);
         LinearLayoutManager linearLayout = new LinearLayoutManager(_mActivity);
@@ -185,38 +206,28 @@
 
     /**
      * 鍒犻櫎鐢电珯,閫嗗彉鍣�
-     * (鍏堣幏鍙栦簯绔笂閫嗗彉鍣ㄥ垪琛�,寮�濮嬪垹闄ょ數绔欙紝鍚屾椂锛屽悜閫嗗彉鍣ㄥ彂閫佸垵濮嬪寲閫嗗彉鍣ㄦ寚浠�)
+     * (寮�濮嬪垹闄ょ數绔欙紝鍚屾椂锛屽悜閫嗗彉鍣ㄥ彂閫佸垵濮嬪寲閫嗗彉鍣ㄦ寚浠�,鏃犻』澶勭悊缁撴灉)
      *
-     * @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) {
-
-                            }
-
-                            @Override
-                            public void onError(HDLLinkException e) {
-
-                            }
-                        });
-                    }
+    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().initializeInverter(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);
+                }
+            });
+        }
     }
 
     /**
@@ -229,6 +240,7 @@
         HdlResidenceLogic.getInstance().delResidence(homeId, new CloudCallBeak<Boolean>() {
             @Override
             public void onSuccess(Boolean obj) {
+                hideLoading();
                 HdlResidenceLogic.getInstance().delHouseId(homeId);
                 initData();//鍒濆鍖栫紦瀛樻暟鎹�
                 houseListAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
@@ -237,6 +249,7 @@
 
             @Override
             public void onFailure(HDLException e) {
+                hideLoading();
                 HdlThreadLogic.toast(_mActivity, e);
             }
         });

--
Gitblit v1.8.0