From 9d50ebeec9b481d3a32960165d64fb73f5b9adc8 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 02 四月 2025 18:30:21 +0800
Subject: [PATCH] 2025年04月02日18:24:17

---
 app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java |   93 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 84 insertions(+), 9 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java b/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java
index 7ab4658..32fee9a 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java
@@ -5,6 +5,7 @@
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
+import android.text.TextUtils;
 import android.view.View;
 
 import androidx.recyclerview.widget.LinearLayoutManager;
@@ -12,6 +13,7 @@
 
 import com.google.gson.JsonObject;
 import com.hdl.linkpm.sdk.core.exception.HDLException;
+import com.hdl.linkpm.sdk.user.HDLLinkPMUser;
 import com.hdl.photovoltaic.R;
 import com.hdl.photovoltaic.base.CustomBaseActivity;
 import com.hdl.photovoltaic.config.ConstantManage;
@@ -21,6 +23,7 @@
 import com.hdl.photovoltaic.internet.HttpClient;
 import com.hdl.photovoltaic.listener.CloudCallBeak;
 import com.hdl.photovoltaic.other.HdlCommonLogic;
+import com.hdl.photovoltaic.other.HdlLogLogic;
 import com.hdl.photovoltaic.other.HdlResidenceLogic;
 import com.hdl.photovoltaic.other.HdlThreadLogic;
 import com.hdl.photovoltaic.other.HdlUniLogic;
@@ -38,6 +41,7 @@
 import org.greenrobot.eventbus.ThreadMode;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -67,6 +71,8 @@
         initView();
         //鍒濆鍖栫晫闈㈢洃鍚櫒
         initEvent();
+        //鍚庡彴璇诲彇浣忓畢鍒楄〃
+        downReadData(false);
     }
 
     private void initData() {
@@ -99,7 +105,6 @@
         viewBinding.fragmentHouseSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
             @Override
             public void onRefresh() {
-                HdlResidenceLogic.getInstance().clearHouseList();
                 downReadData(true);
             }
         });
@@ -177,14 +182,20 @@
                             //鍏抽棴涓嬫媺鍒锋柊鐨勫湀鍦�
                             viewBinding.fragmentHouseSrl.setRefreshing(false);
                         }
-                        if (list != null && list.size() > 0) {
-                            //鏇存柊缂撳瓨
-                            HdlResidenceLogic.getInstance().setHouseIdList(list);
-                            if (houseListAdapter != null) {
-                                initData();
-                                setSelectState();
-                                //鏇存柊UI
-                                houseListAdapter.setList(houseListBeanIDList);
+                        if (list != null && !list.isEmpty()) {
+                            if (!comparableList(houseListBeanIDList, list)) {
+                                //鏇存柊缂撳瓨
+                                HdlResidenceLogic.getInstance().setHouseIdList(list, true);
+                                if (houseListAdapter != null) {
+                                    //閲嶆柊鑾峰彇鍒楄〃鏁版嵁
+                                    initData();
+                                    refreshDetails();
+                                    //鏇存柊鐢电珯閫変腑鐘舵��
+                                    setSelectState();
+                                    //鏇存柊鍒楄〃鏁版嵁
+                                    houseListAdapter.setList(houseListBeanIDList);
+                                }
+
                             }
 
                         }
@@ -333,4 +344,68 @@
         }
     }
 
+
+    /**
+     * 姣旇緝浣忓畢鍒楄〃鏁版嵁鏄惁閮戒竴鏍�
+     *
+     * @param oldList 鏃у垪琛�
+     * @param newList 鏂板垪琛�
+     * @return 鐩稿悓杩斿洖true锛屽惁鍒欒繑鍥瀎alse
+     */
+    boolean comparableList(List<HouseIdBean> oldList, List<HouseIdBean> newList) {
+        if (oldList == null || newList == null) return false;
+        if (oldList.size() != newList.size()) return false;
+        List<String> oidStrList = new ArrayList<>();
+        for (int i = 0; i < oldList.size(); i++) {
+            oidStrList.add(oldList.get(i).getHomeId());
+        }
+
+        List<String> newStrList = new ArrayList<>();
+        for (int i = 0; i < newList.size(); i++) {
+            newStrList.add(newList.get(i).getHomeId());
+        }
+        Collections.sort(oidStrList);
+        Collections.sort(newStrList);
+        return oidStrList.equals(newStrList);
+    }
+
+    /**
+     * 閫氱煡uni鏇存柊鏁版嵁
+     * 锛堝湪骞冲彴涓婂垹闄绔綋鍓嶄綇瀹呭悗,鑾峰彇鍒楄〃瀹炴敹瑕侀�氱煡uni閭h竟鏇存柊鐣岄潰鍗$墖锛�
+     */
+    private void refreshDetails() {
+        try {
+            List<HouseIdBean> localHouseIdList = HdlResidenceLogic.getInstance().getHouseIdList();
+            if (localHouseIdList.isEmpty()) {
+                JsonObject jsonObject = new JsonObject();
+                jsonObject.addProperty("homeId", "");
+                HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
+                uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_DETAILS);
+                uniCallBackBaseBean.setData(jsonObject);
+                HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
+            } else {
+                int select_home = -1;
+                for (int i = 0; i < localHouseIdList.size(); i++) {
+                    if (localHouseIdList.get(i).getHomeId().equals(UserConfigManage.getInstance().getHomeId())) {
+                        select_home = i;
+                        break;
+                    }
+                }
+                if (select_home == -1) {
+                    //鎵句笉鍒伴粯璁ょ涓�涓�
+                    HouseIdBean houseIdBean = localHouseIdList.get(0);
+                    HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true);
+                    JsonObject jsonObject = new JsonObject();
+                    jsonObject.addProperty("homeId", houseIdBean.getHomeId());
+                    jsonObject.addProperty("homeName", houseIdBean.getHomeName());
+                    jsonObject.addProperty("powerStationStatus", houseIdBean.getPowerStationStatus() + "");
+                    HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
+                    uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_DETAILS);
+                    uniCallBackBaseBean.setData(jsonObject);
+                    HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
+                }
+            }
+        } catch (Exception e) {
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0