wjc
2025-04-30 f91ef956cf482ed4ce0885dc47794b783c20c415
app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java
@@ -1,14 +1,20 @@
package com.hdl.photovoltaic.ui.powerstation;
import android.Manifest;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
@@ -43,6 +49,7 @@
import com.hdl.photovoltaic.other.HdlDeviceLogic;
import com.hdl.photovoltaic.other.HdlDialogLogic;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlOtaLogic;
import com.hdl.photovoltaic.other.HdlResidenceLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.other.HdlUniLogic;
@@ -54,6 +61,7 @@
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.utils.GPSManagerUtils;
import com.hdl.photovoltaic.utils.PermissionUtils;
import com.hdl.photovoltaic.utils.ProcessManagerUtils;
import com.hdl.photovoltaic.utils.URLEncodingUtils;
import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
import com.hdl.photovoltaic.widget.DefaultFilteringDialog;
@@ -126,7 +134,7 @@
    @Override
    public void onBindView(Bundle savedInstanceState) {
        getStatusOverview();
//        getStatusOverview();
        initData();
        //初始化
        initView();
@@ -171,7 +179,7 @@
                    return;
                }
                powerStationStatusValue = PowerStationStatus.All;
                stationStatusStyle(viewBinding.allLl,viewBinding.allDesTv);
                stationStatusStyle(viewBinding.allLl, viewBinding.allDesTv);
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            }
@@ -184,7 +192,7 @@
                    return;
                }
                powerStationStatusValue = PowerStationStatus.malfunction;
                stationStatusStyle(viewBinding.faultsLl,viewBinding.faultsDesTv);
                stationStatusStyle(viewBinding.faultsLl, viewBinding.faultsDesTv);
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            }
@@ -197,7 +205,7 @@
                    return;
                }
                powerStationStatusValue = PowerStationStatus.off;
                stationStatusStyle(viewBinding.offlineLl,viewBinding.offlineDesTv);
                stationStatusStyle(viewBinding.offlineLl, viewBinding.offlineDesTv);
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            }
@@ -210,7 +218,7 @@
                    return;
                }
                powerStationStatusValue = PowerStationStatus.connecting;
                stationStatusStyle(viewBinding.connectedLl,viewBinding.connectedDesTv);
                stationStatusStyle(viewBinding.connectedLl, viewBinding.connectedDesTv);
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            }
@@ -253,7 +261,6 @@
                        installedCapacityMinValue = min;//最小组串容量(装机容量)
                        installedCapacityMaxValue = max;//最大组串容量(装机容量)
                        screeningConditionStatus = state;//调试状态(全部;调试中;调试完成;已交付;授权调试)
                        getStatusOverview();
                        loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
                    }
                });
@@ -356,7 +363,14 @@
            }
        });
        //PV筛选
//        //电站编辑按钮
//        viewBinding.editIv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                startActivity(HouseListEditActivity.class);
//            }
//        });
        //电站名称筛选
        viewBinding.stationNameRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
@@ -364,11 +378,10 @@
                screeningConditionStyle(viewBinding.stationNameRl, viewBinding.stationNameIv, isSelected);
                key = SortType.installedCapacitySort;
                value = isSelected ? SortValue.ascending : SortValue.descending;
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            }
        });
        //额定功率筛选
        //电站发电功率筛选
        viewBinding.stationPowerRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
@@ -400,7 +413,17 @@
                screeningConditionStyle(viewBinding.stationDayRl, viewBinding.stationDayIv, isSelected);
                key = SortType.todayElectricitySort;
                value = isSelected ? SortValue.ascending : SortValue.descending;
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            }
        });
        //电站电池容量筛选
        viewBinding.stationMonthRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isSelected = !v.isSelected();
                screenIconState(viewBinding.stationMonthRl, viewBinding.stationMonthIv, isSelected);
                key = SortType.batteryCapacitySort;
                value = isSelected ? SortValue.ascending : SortValue.descending;
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            }
        });
@@ -435,7 +458,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())) {
                            //这里只支持远程调试,远程拿不到mqtt通讯秘钥以及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);
@@ -507,7 +540,7 @@
        viewBinding.powerStationLabelParent.setVisibility(View.VISIBLE);
        viewBinding.deviceLabelParent.setVisibility(View.GONE);
        stationStatusStyle(viewBinding.allLl,viewBinding.allDesTv);
        stationStatusStyle(viewBinding.allLl, viewBinding.allDesTv);
        //电站标签
        houseInfoAdapter = new HouseInfoAdapter(_mActivity);
        viewBinding.fragmentHouseSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity));
@@ -625,7 +658,6 @@
//                if (MqttRecvClient.getInstance() != null) {
//                    MqttRecvClient.getInstance().removeAllTopic();
//                }
                loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            }
        } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(eventBus.getType())) {
@@ -640,8 +672,8 @@
            }
            String homeId = eventBus.getData().toString();
            //进去住宅详情uni读取逆变器列表成功后通知
            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).size(); i++) {
                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).get(i).getGatewayId();
            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId, null).size(); i++) {
                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId, null).get(i).getGatewayId();
                //字符串是自己按规则拼接的,里面注册主题时会解析字符串,只拿getGatewayId()值;
                String topic = "/user/" + gatewayId + "/#";
                //进去住宅详情开始订阅主题
@@ -667,27 +699,27 @@
                isClickPowerStationLabel = true;
                selectedTitleLabelStyle();
                initializationState();
                stationStatusStyle(viewBinding.allLl, viewBinding.allDesTv);
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            } else if (eventBus.getType().equals(ConstantManage.station_page)) {
                // 取消粘性事件
                EventBus.getDefault().removeStickyEvent(eventBus);
                isClickPowerStationLabel = true;
                selectedTitleLabelStyle();
                powerStationStatusValue = eventBus.getData() == null ? "" : eventBus.getData().toString();
                //通过首页电站进来的
                if (eventBus.getData().equals(PowerStationStatus.All)) {
                    isClickPowerStationLabel = true;
                    selectedTitleLabelStyle();
                    viewBinding.allLl.performClick();
                    stationStatusStyle(viewBinding.allLl, viewBinding.allDesTv);
                } else if (eventBus.getData().equals(PowerStationStatus.malfunction)) {
                    isClickPowerStationLabel = true;
                    selectedTitleLabelStyle();
                    viewBinding.faultsLl.performClick();
                    stationStatusStyle(viewBinding.faultsLl, viewBinding.faultsDesTv);
                } else if (eventBus.getData().equals(PowerStationStatus.off)) {
                    isClickPowerStationLabel = true;
                    selectedTitleLabelStyle();
                    viewBinding.offlineLl.performClick();
                    stationStatusStyle(viewBinding.offlineLl, viewBinding.offlineDesTv);
                } else if (eventBus.getData().equals(PowerStationStatus.connecting)) {
                    isClickPowerStationLabel = true;
                    selectedTitleLabelStyle();
                    viewBinding.connectedLl.performClick();
                    stationStatusStyle(viewBinding.connectedLl, viewBinding.connectedDesTv);
                }
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, screeningConditionStatus, powerStationStatusValue, 1, true);
            } else if (eventBus.getType().equals(ConstantManage.station_edit)) {
                //编辑后更新一下住宅列表
                //loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
@@ -799,7 +831,7 @@
                        if (isRefreshing) {
                            hideLoading();
                        }
                        HdlThreadLogic.toast(_mActivity, e.getMsg() + "(" + e.getCode() + ")");
                    }
                }, _mActivity, ShowErrorMode.YES);
            }
@@ -868,7 +900,6 @@
                        if (isRefreshing) {
                            hideLoading();
                        }
                        HdlThreadLogic.toast(_mActivity, e.getMsg() + "(" + e.getCode() + ")");
                    }
                }, _mActivity, ShowErrorMode.YES);
            }
@@ -1001,8 +1032,8 @@
    public void requestPermissions(OnCallBeak onCallBeak) {
        //ACCESS_FINE_LOCATION   允许使用GPS定位
        //ACCESS_COARSE_LOCATION   允许使用WIFI热点或基站来获取粗略的定位
        //ACCESS_FINE_LOCATION    允许使用GPS定位
        //ACCESS_COARSE_LOCATION    允许使用WIFI热点或基站来获取粗略的定位
        String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION});
        if (ary.length > 0) {
            this.requestPermissions(ary, PermissionUtils.STATUS_SUCCESS);
@@ -1078,7 +1109,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();
@@ -1141,7 +1172,7 @@
                    @Override
                    protected void onPostExecute(Void aVoid) {
                        viewBinding.fragmentDeviceSrl.endRefreshing();
                        loadNextPageDeviceList(true, 1, true);
                        loadNextPageDeviceList(false, 1, true);
                    }
                }.execute();
            }