From 4f12f1e3543fce41e71ae9e21a782f8d9cb41947 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期一, 07 七月 2025 10:45:11 +0800
Subject: [PATCH] Merge branch '1.3.1' into dev

---
 app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListActivity.java |  195 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 176 insertions(+), 19 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/PowerStationsListActivity.java
similarity index 68%
rename from app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java
rename to app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListActivity.java
index efa0636..1c17dc3 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListActivity.java
@@ -5,17 +5,14 @@
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
-import android.os.SystemClock;
-import android.text.TextUtils;
-import android.util.Log;
+import android.os.Handler;
+import android.os.Looper;
 import android.view.View;
 
 import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
 
 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;
@@ -24,8 +21,9 @@
 import com.hdl.photovoltaic.enums.ShowErrorMode;
 import com.hdl.photovoltaic.internet.HttpClient;
 import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.listener.LinkCallBack;
 import com.hdl.photovoltaic.other.HdlCommonLogic;
-import com.hdl.photovoltaic.other.HdlLogLogic;
+import com.hdl.photovoltaic.other.HdlDeviceLogic;
 import com.hdl.photovoltaic.other.HdlResidenceLogic;
 import com.hdl.photovoltaic.other.HdlThreadLogic;
 import com.hdl.photovoltaic.other.HdlUniLogic;
@@ -33,11 +31,15 @@
 import com.hdl.photovoltaic.ui.device.ScanActivity;
 import com.hdl.photovoltaic.ui.newC.adapter.HouseListAdapter;
 import com.hdl.photovoltaic.uni.HDLUniMP;
-import com.hdl.photovoltaic.utils.LocalManageUtil;
 import com.hdl.photovoltaic.utils.PermissionUtils;
 import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
+import com.hdl.photovoltaic.widget.DelayedConfirmationCancelDialog;
 import com.hdl.photovoltaic.widget.PermissionExplanationDialog;
+import com.hdl.photovoltaic.widget.refreshlayout.BGARefreshLayout;
+import com.hdl.photovoltaic.widget.refreshlayout.HDLRefreshViewHolder;
+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.Subscribe;
 import org.greenrobot.eventbus.ThreadMode;
@@ -49,7 +51,9 @@
 /**
  * C绔數绔欏垪琛ㄧ紪杈�
  */
-public class PowerStationsListEdit extends CustomBaseActivity {
+public class PowerStationsListActivity extends CustomBaseActivity {
+    private Handler handler;
+    private Runnable delayedRunnable;
     private ActivityPowerStationsListBinding viewBinding;//鏄惁鍦ㄧ紪杈戠姸鎬�
 
     private HouseListAdapter houseListAdapter;
@@ -101,16 +105,8 @@
             }
         });
 
-        //璁剧疆涓嬫媺绠ご棰滆壊
-        viewBinding.fragmentHouseSrl.setColorSchemeResources(R.color.text_FF245EC3);
-        //鍒楄〃涓嬫媺鎸夐挳
-        viewBinding.fragmentHouseSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
-            @Override
-            public void onRefresh() {
-                downReadData(true);
-            }
-        });
         if (houseListAdapter != null) {
+            //閫変腑鐢电珯浜嬩欢
             houseListAdapter.setOnItemClickListener(new HouseListAdapter.OnItemClickListener() {
                 @Override
                 public void onItemClick(int position, HouseIdBean houseBean) {
@@ -125,6 +121,53 @@
                         return;
                     }
                     houseSelectionDialog(houseBean);
+                }
+            });
+            //鍒犻櫎鐢电珯浜嬩欢
+            houseListAdapter.setDelOnclickListener(new HouseListAdapter.OnDelClickListener() {
+                @Override
+                public void onDelClick(int position, HouseIdBean houseIdBean) {
+                    if (houseIdBean.isOtherShare()) {
+                        //鍒嗕韩杩囨潵鐨勭數绔欎笉鑳藉垹闄�
+                        HdlThreadLogic.toast(_mActivity, getString(R.string.no_permission_delete_home));
+                        return;
+                    }
+
+                    DelayedConfirmationCancelDialog delayedConfirmationCancelDialog = new DelayedConfirmationCancelDialog(_mActivity);
+                    delayedConfirmationCancelDialog.show();
+                    delayedConfirmationCancelDialog.isHideTitle(true);
+                    String del_home = getString(R.string.confirm_deletion) + "\"" + houseIdBean.getHomeName() + "\"" + "?";
+                    delayedConfirmationCancelDialog.setContent(del_home);
+
+//                    delayedConfirmationCancelDialog.startCountdown(4);
+                    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);
+
+                                }
+
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    //鍙戣捣鍒犻櫎鐢电珯鎸囦护
+                                    deleteResidence(houseIdBean.getHomeId(), null);
+                                }
+                            });
+
+                        }
+                    });
+                    delayedConfirmationCancelDialog.setNoOnclickListener(new DelayedConfirmationCancelDialog.onNoOnclickListener() {
+                        @Override
+                        public void Cancel() {
+                            delayedConfirmationCancelDialog.dismiss();
+                        }
+                    });
                 }
             });
         }
@@ -165,6 +208,52 @@
         viewBinding.fragmentHouseSrlListRc.setAdapter(houseListAdapter);
         houseListAdapter.setList(this.houseListBeanIDList);
         this.nullDataUpdateUi(houseListBeanIDList);
+        pullToRefresh();
+    }
+
+    /**
+     * 涓嬫媺鍒锋柊鐨勯�昏緫
+     */
+    protected void pullToRefresh() {
+        viewBinding.fragmentHouseSrl.setDelegate(new BGARefreshLayout.BGARefreshLayoutDelegate() {
+            @Override
+            public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) {
+                handler = new Handler(Looper.getMainLooper());
+
+                delayedRunnable = new Runnable() {
+                    @Override
+                    public void run() {
+                        viewBinding.fragmentHouseSrl.endRefreshing();
+                        downReadData(false);
+                    }
+                };
+                // 寤惰繜 5 绉掓墽琛�
+                handler.postDelayed(delayedRunnable, 1000);
+            }
+
+
+            @Override
+            public boolean onBGARefreshLayoutBeginLoadingMore(BGARefreshLayout refreshLayout) {
+
+                handler = new Handler(Looper.getMainLooper());
+                delayedRunnable = new Runnable() {
+                    @Override
+                    public void run() {
+                        viewBinding.fragmentHouseSrl.endLoadingMore();
+
+                    }
+                };
+                // 寤惰繜 5 绉掓墽琛�
+                handler.postDelayed(delayedRunnable, 10);
+
+                return true;
+            }
+        });
+        HDLRefreshViewHolder hdlRefreshViewHolder = new HDLRefreshViewHolder(_mActivity, true);
+        hdlRefreshViewHolder.setPullDownImageResource(R.mipmap.loading_44);
+        hdlRefreshViewHolder.setChangeToReleaseRefreshAnimResId(R.drawable.loading_refresh);
+        hdlRefreshViewHolder.setRefreshingAnimResId(R.drawable.loading_refresh_end);
+        viewBinding.fragmentHouseSrl.setRefreshViewHolder(hdlRefreshViewHolder);
     }
 
     /**
@@ -173,6 +262,9 @@
      * @param isRefreshing 琛ㄧず鏄笅鎷夊埛鏂扮殑
      */
     private void downReadData(boolean isRefreshing) {
+        if (isRefreshing) {
+            showLoading();
+        }
         //鑾峰彇浣忓畢(鐢电珯)ID鍒楄〃
         HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() {
             @Override
@@ -182,7 +274,7 @@
                     public void run() {
                         if (isRefreshing) {
                             //鍏抽棴涓嬫媺鍒锋柊鐨勫湀鍦�
-                            viewBinding.fragmentHouseSrl.setRefreshing(false);
+                            hideLoading();
                         }
                         if (list != null && !list.isEmpty()) {
                             if (!comparableList(houseListBeanIDList, list)) {
@@ -214,7 +306,7 @@
                     public void run() {
                         if (isRefreshing) {
                             //鍏抽棴涓嬫媺鍒锋柊鐨勫湀鍦�
-                            viewBinding.fragmentHouseSrl.setRefreshing(false);
+                            hideLoading();
                         }
 
                         HdlThreadLogic.toast(_mActivity, e.getMsg() + "(" + e.getCode() + ")");
@@ -308,6 +400,63 @@
                 houseListAdapter.notifyDataSetChanged();
             }
         });
+    }
+
+    /**
+     * 鍒犻櫎鐢电珯
+     *
+     * @param homeId 鐢电珯id
+     * @param list   閫嗗彉鍣ㄥ垪琛�
+     */
+    private void deleteResidence(String homeId, List<GatewayBean> list) {
+
+        //鍒犻櫎浣忓畢
+        HdlResidenceLogic.getInstance().delResidence(homeId, new CloudCallBeak<Boolean>() {
+            @Override
+            public void onSuccess(Boolean obj) {
+                hideLoading();
+                initializeInverter(list); //鍙戣捣鍒濆鍖栨寚浠ょ粰閫嗗彉鍣�;锛堟敞鎰�:鍓嶉潰宸插厛瑙g粦浜戠閫嗗彉鍣紝mqtt閫氶亾宸叉柇寮�锛屽垵濮嬪寲鍙兘鏄湰鍦板彂閫�(鍏堟悳绱㈠眬鍩熺綉閫嗗彉鍣ㄥ垪琛紝寤虹珛鏈湴閫氳閫氶亾)锛�
+                HdlResidenceLogic.getInstance().delHouseId(homeId);//鍒犻櫎鐢电珯缂撳瓨
+                initData();//鍒濆鍖栫紦瀛樻暟鎹�
+                refreshDetails();
+                //鏇存柊鐢电珯閫変腑鐘舵��
+                setSelectState();
+                houseListAdapter.setList(houseListBeanIDList); //鏇存柊鍒楄〃鏁版嵁
+                nullDataUpdateUi(houseListBeanIDList);//妫�娴嬫暟鎹槸鍚︿负绌�
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                hideLoading();
+                HdlThreadLogic.toast(_mActivity, e);
+            }
+        });
+    }
+
+    /**
+     * 鍒犻櫎鐢电珯,閫嗗彉鍣�
+     * (寮�濮嬪垹闄ょ數绔欙紝鍚屾椂锛屽悜閫嗗彉鍣ㄥ彂閫佸垵濮嬪寲閫嗗彉鍣ㄦ寚浠�,鏃犻』澶勭悊缁撴灉)
+     *
+     * @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);
+                }
+            });
+        }
     }
 
 
@@ -410,4 +559,12 @@
         } catch (Exception e) {
         }
     }
+
+    @Override
+    protected void onDestroy() {
+        if (handler != null && delayedRunnable != null) {
+            handler.removeCallbacks(delayedRunnable);
+        }
+        super.onDestroy();
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0