From 30859ca8f2175475d2c666353bc27f3b2ceede53 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 22 八月 2024 13:43:47 +0800
Subject: [PATCH] 2024年08月22日13:43:45

---
 app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListEditActivity.java |  144 ++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 120 insertions(+), 24 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 80f6d0c..d649953 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
@@ -14,17 +14,26 @@
 import com.hdl.photovoltaic.config.UserConfigManage;
 import com.hdl.photovoltaic.databinding.ActivityHouseListEditBinding;
 import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch;
+import com.hdl.photovoltaic.enums.MessageStateType;
 import com.hdl.photovoltaic.enums.ShowErrorMode;
 import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.listener.LinkCallBack;
 import com.hdl.photovoltaic.other.HdlCommonLogic;
+import com.hdl.photovoltaic.other.HdlDeviceLogic;
+import com.hdl.photovoltaic.other.HdlLogLogic;
 import com.hdl.photovoltaic.other.HdlResidenceLogic;
 import com.hdl.photovoltaic.other.HdlThreadLogic;
+import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
 import com.hdl.photovoltaic.ui.bean.HouseIdBean;
 import com.hdl.photovoltaic.ui.newC.adapter.HouseListAdapter;
 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;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -37,7 +46,7 @@
     private ActivityHouseListEditBinding viewBinding;
 
     private HouseListAdapter houseListAdapter;
-    private List<HouseIdBean> houseListBeanIDList;
+    private List<HouseIdBean> houseListBeanIDList = new ArrayList<>();
 
 
     @Override
@@ -56,28 +65,38 @@
         initView();
         //鍒濆鍖栫晫闈㈢洃鍚櫒
         initEvent();
+        if (this.houseListBeanIDList.size() == 0) {
+            downReadData(false);
+        }
     }
 
     private void initData() {
-        this.houseListBeanIDList = new ArrayList<>();
+        this.houseListBeanIDList.clear();
         this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList());
         for (int i = 0; i < this.houseListBeanIDList.size(); i++) {
             this.houseListBeanIDList.get(i).setDelIcon(true);
             this.houseListBeanIDList.get(i).setMove(true);
-
         }
+    }
+
+
+    @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();
             }
         });
 
@@ -95,10 +114,13 @@
             houseListAdapter.setMoveOnclickListener(new HouseListAdapter.OnMoveClickListener() {
                 @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
@@ -118,7 +140,7 @@
                 }
             });
 
-            //鐢电珯绉诲姩浣嶇疆鎸夐挳
+            //鐢电珯鍒犻櫎浣嶇疆鎸夐挳
             houseListAdapter.setDelOnclickListener(new HouseListAdapter.OnDelClickListener() {
                 @Override
                 public void onDelClick(int position, HouseIdBean houseIdBean) {
@@ -128,26 +150,39 @@
                     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() {
-                            //鍒犻櫎浣忓畢
-                            HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() {
+                            delayedConfirmationCancelDialog.dismiss();
+                            showLoading(getString(R.string.deleting_please_wait));
+                            HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(houseIdBean.getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
                                 @Override
-                                public void onSuccess(Boolean obj) {
-                                    HdlResidenceLogic.getInstance().delHouseId(houseIdBean.getHomeId());
-                                    initData();//鍒濆鍖栫紦瀛樻暟鎹�
-                                    houseListAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
-                                    nullDataUpdateUi(houseListBeanIDList);//妫�娴嬫暟鎹槸鍚︿负绌�
-                                    delayedConfirmationCancelDialog.dismiss();
+                                public void onSuccess(List<GatewayBean> list) {
+                                    deleteResidence(houseIdBean.getHomeId());
+                                    initializeInverter(list);
                                 }
 
                                 @Override
                                 public void onFailure(HDLException e) {
-                                    HdlThreadLogic.toast(_mActivity, e);
+                                    deleteResidence(houseIdBean.getHomeId());
                                 }
                             });
+//                            //鍒犻櫎浣忓畢
+//                            HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() {
+//                                @Override
+//                                public void onSuccess(Boolean obj) {
+//                                    HdlResidenceLogic.getInstance().delHouseId(houseIdBean.getHomeId());
+//                                    initData();//鍒濆鍖栫紦瀛樻暟鎹�
+//                                    houseListAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
+//                                    nullDataUpdateUi(houseListBeanIDList);//妫�娴嬫暟鎹槸鍚︿负绌�
+//                                }
+//
+//                                @Override
+//                                public void onFailure(HDLException e) {
+//                                    HdlThreadLogic.toast(_mActivity, e);
+//                                }
+//                            });
                         }
                     });
                     delayedConfirmationCancelDialog.setNoOnclickListener(new DelayedConfirmationCancelDialog.onNoOnclickListener() {
@@ -165,7 +200,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);
@@ -176,12 +211,67 @@
         this.nullDataUpdateUi(houseListBeanIDList);
     }
 
+
+    /**
+     * 鍒犻櫎鐢电珯,閫嗗彉鍣�
+     * (寮�濮嬪垹闄ょ數绔欙紝鍚屾椂锛屽悜閫嗗彉鍣ㄥ彂閫佸垵濮嬪寲閫嗗彉鍣ㄦ寚浠�,鏃犻』澶勭悊缁撴灉)
+     *
+     * @param list 璁惧鍒楄〃
+     */
+    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 onError(HDLLinkException e) {
+//                                HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄥけ璐�-->mac:" + cloudInverterDeviceBean.getOsn(),true);
+                }
+            });
+        }
+    }
+
+    /**
+     * 鍒犻櫎鐢电珯
+     *
+     * @param homeId 鐢电珯id
+     */
+    private void deleteResidence(String homeId) {
+        //鍒犻櫎浣忓畢
+        HdlResidenceLogic.getInstance().delResidence(homeId, new CloudCallBeak<Boolean>() {
+            @Override
+            public void onSuccess(Boolean obj) {
+                hideLoading();
+                HdlResidenceLogic.getInstance().delHouseId(homeId);
+                initData();//鍒濆鍖栫紦瀛樻暟鎹�
+                houseListAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
+                nullDataUpdateUi(houseListBeanIDList);//妫�娴嬫暟鎹槸鍚︿负绌�
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                hideLoading();
+                HdlThreadLogic.toast(_mActivity, e);
+            }
+        });
+    }
+
     /**
      * 鍒锋柊UI
      *
      * @param isRefreshing 琛ㄧず鏄笅鎷夊埛鏂扮殑
      */
     private void downReadData(boolean isRefreshing) {
+        if (!isRefreshing) {
+            showLoading();
+        }
         //鑾峰彇浣忓畢(鐢电珯)ID鍒楄〃
         HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() {
             @Override
@@ -192,6 +282,8 @@
                         if (isRefreshing) {
                             //鍏抽棴涓嬫媺鍒锋柊鐨勫湀鍦�
                             viewBinding.fragmentHouseSrl.setRefreshing(false);
+                        } else {
+                            hideLoading();
                         }
                         if (list != null && list.size() > 0) {
                             //鏇存柊缂撳瓨
@@ -218,7 +310,10 @@
                         if (isRefreshing) {
                             //鍏抽棴涓嬫媺鍒锋柊鐨勫湀鍦�
                             viewBinding.fragmentHouseSrl.setRefreshing(false);
+                        } else {
+                            hideLoading();
                         }
+
 
                     }
                 }, _mActivity, ShowErrorMode.YES);
@@ -237,6 +332,7 @@
         }
     }
 
+
     /**
      * 娌℃湁鐢电珯鍒楄〃鐨勬牱寮�
      */

--
Gitblit v1.8.0