From ef0dba8548e2813beee2af8c8c3db72c3cb56da0 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 30 七月 2025 18:53:07 +0800
Subject: [PATCH] 2025年07月30日18:53:03

---
 app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java |  183 +++++++++++++++++++++++++++++----------------
 1 files changed, 118 insertions(+), 65 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java
index f2c2200..703bf16 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java
@@ -8,7 +8,7 @@
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.provider.Settings;
-import android.util.Log;
+import android.text.TextUtils;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
@@ -18,8 +18,6 @@
 import androidx.annotation.NonNull;
 import androidx.appcompat.content.res.AppCompatResources;
 import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
 
 import com.google.gson.Gson;
 import com.hdl.linkpm.sdk.core.exception.HDLException;
@@ -34,6 +32,7 @@
 import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch;
 import com.hdl.photovoltaic.enums.LowerTagType;
 import com.hdl.photovoltaic.enums.PowerStationStatus;
+import com.hdl.photovoltaic.enums.ProjectOperation;
 import com.hdl.photovoltaic.enums.ShowErrorMode;
 import com.hdl.photovoltaic.enums.SortType;
 import com.hdl.photovoltaic.enums.SortValue;
@@ -56,9 +55,11 @@
 import com.hdl.photovoltaic.utils.GPSManagerUtils;
 import com.hdl.photovoltaic.utils.PermissionUtils;
 import com.hdl.photovoltaic.utils.URLEncodingUtils;
+import com.hdl.photovoltaic.widget.AddPowerStationDialog;
 import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
 import com.hdl.photovoltaic.widget.DefaultFilteringDialog;
 import com.hdl.photovoltaic.widget.DelayedConfirmationCancelDialog;
+import com.hdl.photovoltaic.widget.adapter.PowerStationDialogAdapter;
 import com.hdl.photovoltaic.widget.refreshlayout.BGARefreshLayout;
 import com.hdl.photovoltaic.widget.refreshlayout.HDLRefreshViewHolder;
 import com.hdl.sdk.link.common.exception.HDLLinkException;
@@ -221,12 +222,26 @@
         viewBinding.addIv.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-
-                requestPermissions(new OnCallBeak() {
+                AddPowerStationDialog addPowerStationDialog = new AddPowerStationDialog(_mActivity);
+                addPowerStationDialog.show();
+                addPowerStationDialog.setCanceledOnTouchOutside(true);
+                addPowerStationDialog.setItemOnclickListener(new PowerStationDialogAdapter.OnclickListener() {
                     @Override
-                    public void onClickCallBeak() {
-//                        UserConfigManage.getInstance().setUniBottomSafeDistanceBackgroundColor(1);
-//                        HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null);
+                    public void onClick(int position, String str) {
+                        addPowerStationDialog.dismiss();
+                        UserConfigManage.getInstance().setUniBottomSafeDistanceBackgroundColor(1);
+                        if (_mActivity.getString(R.string.simple_debugging).equals(str)) {
+                            HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION_SIMPLE, null);
+                        } else {
+                            HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null);
+                        }
+//                        requestPermissions(new OnCallBeak() {
+//                            @Override
+//                            public void onClickCallBeak() {
+////                        UserConfigManage.getInstance().setUniBottomSafeDistanceBackgroundColor(1);
+////                        HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null);
+//                            }
+//                        });
                     }
                 });
 
@@ -303,49 +318,59 @@
 
             @Override
             public void onDelClick(int position, HouseIdBean houseIdBean) {
-
+                final boolean isWaitDelivered = houseIdBean.getDebugStatus().equals(DebugStatus.WAIT_DELIVERED);
                 DelayedConfirmationCancelDialog delayedConfirmationCancelDialog = new DelayedConfirmationCancelDialog(_mActivity);
                 delayedConfirmationCancelDialog.show();
                 delayedConfirmationCancelDialog.isHideTitle(true);
                 String homeName = "\"" + houseIdBean.getHomeName() + "\"";
-                delayedConfirmationCancelDialog.setContent(getString(R.string.delete_power_station).replace("%s", homeName));
-
-                delayedConfirmationCancelDialog.startCountdown(4);
+                if (isWaitDelivered) {
+                    //"鏄惁灏嗙數绔欑殑璋冭瘯鐘舵�佸洖閫�鍒拌皟璇曚腑"
+                    delayedConfirmationCancelDialog.setContent(getString(R.string.debug_status_rollback).replace("%s", homeName));
+                } else {
+                    delayedConfirmationCancelDialog.startCountdown(4);
+                    delayedConfirmationCancelDialog.setContent(getString(R.string.delete_power_station).replace("%s", homeName));
+                }
                 delayedConfirmationCancelDialog.setYesOnclickListener(new DelayedConfirmationCancelDialog.onYesOnclickListener() {
                     @Override
                     public void Confirm() {
                         delayedConfirmationCancelDialog.dismiss();
-                        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);
+                        if (isWaitDelivered) {
+                            showLoading();
+                            HdlResidenceLogic.getInstance().setUpdateProjectDebugStatus(houseIdBean.getHomeId(), houseIdBean.getCommunityId(), houseIdBean.getFlowRecordContent(), ProjectOperation.DEBUGGING_AGAIN.toString(), new CloudCallBeak<Boolean>() {
+                                @Override
+                                public void onSuccess(Boolean list) {
+                                    hideLoading();
+                                    if (houseInfoAdapter != null) {
+                                        houseIdBean.setDebugStatus(DebugStatus.Debugging);
+                                        HdlResidenceLogic.getInstance().updateHouseIdBean(houseIdBean);
+                                        initData();
+                                        //鏇存柊UI
+                                        houseInfoAdapter.notifyItemChanged(position);
+                                    }
+                                }
 
-                            }
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    hideLoading();
+                                }
+                            });
+                        } else {
+                            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, position);
 
-                            @Override
-                            public void onFailure(HDLException e) {
-                                //鍙戣捣鍒犻櫎鐢电珯鎸囦护
-                                deleteResidence(houseIdBean.getHomeId(), null);
-                            }
-                        });
+                                }
 
-//                        //鍒犻櫎浣忓畢
-//                        HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() {
-//                            @Override
-//                            public void onSuccess(Boolean obj) {
-//                                HdlResidenceLogic.getInstance().delHouseId(houseIdBean.getHomeId());
-//                                initData();//鍒濆鍖栫紦瀛樻暟鎹�
-//                                houseInfoAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
-//                                nullDataUpdateUi(houseListBeanIDList);//妫�娴嬫暟鎹槸鍚︿负绌�
-//                            }
-//
-//                            @Override
-//                            public void onFailure(HDLException e) {
-//                                HdlThreadLogic.toast(_mActivity, e);
-//                            }
-//                        });
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    //鍙戣捣鍒犻櫎鐢电珯鎸囦护
+                                    deleteResidence(houseIdBean.getHomeId(), null, position);
+                                }
+                            });
+                        }
                     }
                 });
                 delayedConfirmationCancelDialog.setNoOnclickListener(new DelayedConfirmationCancelDialog.onNoOnclickListener() {
@@ -436,7 +461,17 @@
                 HdlDeviceLogic.getInstance().setDeviceRemoteInfo(newList, deviceBean.getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
                     @Override
                     public void onSuccess(List<GatewayBean> obj) {
+
                         GatewayBean newGatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(deviceBean.getOsn());
+                        if (newGatewayBean == null) {
+                            HdlThreadLogic.toast(_mActivity, getString(R.string.device_off));
+                            return;
+                        }
+                        if (TextUtils.isEmpty(newGatewayBean.getGatewayId()) || TextUtils.isEmpty(newGatewayBean.getAesKey())) {
+                            //杩欓噷鍙敮鎸佽繙绋嬭皟璇曪紝杩滅▼鎷夸笉鍒癿qtt閫氳绉橀挜浠ュ強gatewayId锛�
+                            HdlThreadLogic.toast(_mActivity, getString(R.string.device_failed_to_certificate) + "(124004)");
+                            return;
+                        }
                         String jsonEncryption = URLEncodingUtils.encodeURIComponent(new Gson().toJson(newGatewayBean));
                         String path = HDLUniMP.UNI_EVENT_OPEN_DEVICE_DETAILS + "?inverterInfo=" + jsonEncryption;
                         HdlUniLogic.getInstance().openUniMP(path, null);
@@ -514,7 +549,6 @@
         viewBinding.fragmentHouseSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity));
         viewBinding.fragmentHouseSrlListRc.setAdapter(houseInfoAdapter);
         houseInfoAdapter.setList(this.houseListBeanIDList, powerStationStatusValue);
-
         //璁惧鏍囩
         deviceInfoAdapter = new DeviceInfoAdapter(_mActivity);
         viewBinding.fragmentDeviceSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity));
@@ -581,15 +615,18 @@
             if (HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION.equals(eventBus.getType())) {
                 // 鍙栨秷绮樻�т簨浠�
                 EventBus.getDefault().removeStickyEvent(eventBus);
-                //uin鍒涘缓鐢电珯鎴愬姛鍚庨�氱煡
-                loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
-                if (eventBus.getData() != null) {
-                    Gson gson = new Gson();
-                    String json = eventBus.getData().toString();
-                    HouseIdBean houseIdBean = gson.fromJson(json, HouseIdBean.class);
-                    HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true);
-
-                }
+//                HdlLogLogic.print("杩涙潵浜�---11111" + eventBus.getData().toString());
+//                //uin鍒涘缓鐢电珯鎴愬姛鍚庨�氱煡
+//                loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
+//                if (eventBus.getData() != null) {
+//                    HdlLogLogic.print("杩涙潵浜�---" + eventBus.getData().toString());
+//                    Gson gson = new Gson();
+//                    String json = eventBus.getData().toString();
+//                    HouseIdBean houseIdBean = gson.fromJson(json, HouseIdBean.class);
+//                    HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true);
+//                    HdlLogLogic.print("杩涙潵浜�---缁撴潫" + eventBus.getData().toString());
+//
+//                }
             } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT.equals(eventBus.getType())) {
                 // 鍙栨秷绮樻�т簨浠�
                 EventBus.getDefault().removeStickyEvent(eventBus);
@@ -641,8 +678,8 @@
             }
             String homeId = eventBus.getData().toString();
             //杩涘幓浣忓畢璇︽儏uni璇诲彇閫嗗彉鍣ㄥ垪琛ㄦ垚鍔熷悗閫氱煡
-            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId,null).size(); i++) {
-                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId,null).get(i).getGatewayId();
+            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).size(); i++) {
+                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).get(i).getGatewayId();
                 //瀛楃涓叉槸鑷繁鎸夎鍒欐嫾鎺ョ殑,閲岄潰娉ㄥ唽涓婚鏃朵細瑙f瀽瀛楃涓�,鍙嬁getGatewayId()鍊�;
                 String topic = "/user/" + gatewayId + "/#";
                 //杩涘幓浣忓畢璇︽儏寮�濮嬭闃呬富棰�
@@ -948,20 +985,24 @@
     /**
      * 鍒犻櫎鐢电珯
      *
-     * @param homeId 鐢电珯id
-     * @param list   閫嗗彉鍣ㄥ垪琛�
+     * @param homeId   鐢电珯id
+     * @param list     閫嗗彉鍣ㄥ垪琛�
+     * @param position 浣嶇疆
      */
-    private void deleteResidence(String homeId, List<GatewayBean> list) {
+    private void deleteResidence(String homeId, List<GatewayBean> list, int position) {
 
         //鍒犻櫎浣忓畢
         HdlResidenceLogic.getInstance().delResidence(homeId, new CloudCallBeak<Boolean>() {
             @Override
             public void onSuccess(Boolean obj) {
                 hideLoading();
-                initializeInverter(list); //鍙戣捣鍒濆鍖栨寚浠ょ粰閫嗗彉鍣�;锛堟敞鎰�:鍙兘鏄湰鍦板彂閫佷簡(瑕佹悳绱㈠眬鍩熺綉閫嗗彉鍣ㄥ垪琛紝寤虹珛鏈湴閫氳閫氶亾),鍒犻櫎鐢电珯鎴愬姛鍚�,浜戠瑙g粦閫嗗彉鍣ㄧ殑鍏崇郴锛�
+                initializeInverter(list); //鍙戣捣鍒濆鍖栨寚浠ょ粰閫嗗彉鍣�;锛堟敞鎰�:鍓嶉潰宸插厛瑙g粦浜戠閫嗗彉鍣紝mqtt閫氶亾宸叉柇寮�锛屽垵濮嬪寲鍙兘鏄湰鍦板彂閫�(鍏堟悳绱㈠眬鍩熺綉閫嗗彉鍣ㄥ垪琛紝寤虹珛鏈湴閫氳閫氶亾)锛�
                 HdlResidenceLogic.getInstance().delHouseId(homeId);//鍒犻櫎鐢电珯缂撳瓨
                 initData();//鍒濆鍖栫紦瀛樻暟鎹�
-                houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);//閲嶆柊鍒锋柊鍒楄〃
+                if (houseInfoAdapter != null) {
+//                    houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);//閲嶆柊鍒锋柊鍒楄〃
+                    houseInfoAdapter.notifyItemRemoved(position);//鍙埛鏂板綋鍓嶇殑浣嶇疆
+                }
                 getStatusOverview();//鍒犻櫎鎴愬姛鍚庡埛鏂扮數绔欑姸鎬佹瑙�
                 nullDataUpdateUi();//妫�娴嬫暟鎹槸鍚︿负绌�
             }
@@ -1008,12 +1049,24 @@
         if (ary.length > 0) {
             this.requestPermissions(ary, PermissionUtils.STATUS_SUCCESS);
         } else {
-
-            UserConfigManage.getInstance().setUniBottomSafeDistanceBackgroundColor(1);
-            HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null);
-            locationUpdates();
-
-
+            AddPowerStationDialog addPowerStationDialog = new AddPowerStationDialog(_mActivity);
+            addPowerStationDialog.show();
+            addPowerStationDialog.setCanceledOnTouchOutside(true);
+            addPowerStationDialog.setItemOnclickListener(new PowerStationDialogAdapter.OnclickListener() {
+                @Override
+                public void onClick(int position, String str) {
+                    addPowerStationDialog.dismiss();
+//                    UserConfigManage.getInstance().setCurrentAppLanguage(itemData.getLanguage());
+//                    UserConfigManage.getInstance().Save();
+                    UserConfigManage.getInstance().setUniBottomSafeDistanceBackgroundColor(1);
+                    if (_mActivity.getString(R.string.simple_debugging).equals(str)) {
+                        HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION_SIMPLE, null);
+                    } else {
+                        HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null);
+                    }
+                    locationUpdates();
+                }
+            });
         }
 
     }
@@ -1079,7 +1132,7 @@
                         // 鎵ц浠诲姟锛堝鏇存柊UI銆佽烦杞瓑锛�
                         viewBinding.fragmentHouseSrl.endRefreshing();
                         //鍔犺浇鏈�鏂版暟鎹畬鎴�
-                        loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
+                        loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
                         getStatusOverview();
                     }
                 }.execute();
@@ -1142,7 +1195,7 @@
                     @Override
                     protected void onPostExecute(Void aVoid) {
                         viewBinding.fragmentDeviceSrl.endRefreshing();
-                        loadNextPageDeviceList(true, 1, true);
+                        loadNextPageDeviceList(false, 1, true);
                     }
                 }.execute();
             }

--
Gitblit v1.8.0