mac
2024-05-30 7e79979359bf5d3438afac05458e454c4786d50b
app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java
@@ -22,6 +22,7 @@
import com.hdl.photovoltaic.databinding.FragmentHouseListBinding;
import com.hdl.photovoltaic.base.CustomBaseFragment;
import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch;
import com.hdl.photovoltaic.enums.LowerTagType;
import com.hdl.photovoltaic.enums.PowerStationStatus;
import com.hdl.photovoltaic.enums.ShowErrorMode;
import com.hdl.photovoltaic.enums.SortType;
@@ -36,17 +37,19 @@
import com.hdl.photovoltaic.other.HdlUniLogic;
import com.hdl.photovoltaic.ui.adapter.DeviceInfoAdapter;
import com.hdl.photovoltaic.ui.adapter.HouseInfoAdapter;
import com.hdl.photovoltaic.ui.bean.DeviceBean;
import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
import com.hdl.photovoltaic.ui.bean.HouseIdBean;
import com.hdl.photovoltaic.ui.bean.StatusOverviewBean;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.utils.PermissionUtils;
import com.hdl.photovoltaic.utils.URLEncodingUtils;
import com.hdl.photovoltaic.widget.DefaultFilteringDialog;
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 com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient;
import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -67,7 +70,7 @@
    private DeviceInfoAdapter deviceInfoAdapter;
    private List<HouseIdBean> houseListBeanIDList;
    private List<DeviceBean> deviceInfoList;
    private List<CloudInverterDeviceBean> deviceInfoList;
    private int currentHouseListPage = 0; // 当前电站列表页码
    private int currentHouseListTotal = 0; // 电站列表总页码
    private boolean isHouseLoadingMore = false; // 标记电站列表正在加载更多数据
@@ -96,6 +99,7 @@
    @Override
    public void onBindView(Bundle savedInstanceState) {
        getStatusOverview();
        initData();
        //初始化
        initView();
@@ -280,7 +284,7 @@
                        //移动电站位置
                        HdlResidenceLogic.getInstance().moveHouseId(houseIdBean.getHomeId());
                        initData();//初始化缓存数据
                        houseInfoAdapter.setList(houseListBeanIDList);//重新刷新列表
                        houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);//重新刷新列表
                        nullDataUpdateUi();//检测数据是否为空
                    }
@@ -297,10 +301,11 @@
            public void onDelClick(int position, HouseIdBean houseIdBean) {
                DelayedConfirmationCancelDialog delayedConfirmationCancelDialog = new DelayedConfirmationCancelDialog(_mActivity);
                delayedConfirmationCancelDialog.setTitleContent(getString(R.string.loading_title_tip));
                delayedConfirmationCancelDialog.show();
                delayedConfirmationCancelDialog.isHideTitle(true);
                String homeName = "\"" + houseIdBean.getHomeName() + "\"";
                delayedConfirmationCancelDialog.setContent(getString(R.string.delete_power_station).replace("%s", homeName));
                delayedConfirmationCancelDialog.show();
                delayedConfirmationCancelDialog.startCountdown(4);
                delayedConfirmationCancelDialog.setYesOnclickListener(new DelayedConfirmationCancelDialog.onYesOnclickListener() {
                    @Override
@@ -406,8 +411,38 @@
        //设备点击
        deviceInfoAdapter.setOnclickListener(new DeviceInfoAdapter.OnClickListener() {
            @Override
            public void onClick(int position, DeviceBean deviceBean) {
            public void onClick(int position, CloudInverterDeviceBean deviceBean) {
//                GatewayBean gatewayBean = new GatewayBean();
//                gatewayBean.setCategorySecondName(deviceBean.getCategorySecondName());
//                gatewayBean.setDevice_mac(deviceBean.getOsn());
//                gatewayBean.setDevice_model(deviceBean.getOmodel());
//                gatewayBean.setOid(deviceBean.getOid());
//                gatewayBean.setGatewayId(deviceBean.getGatewayId());
//                gatewayBean.setAddresses(deviceBean.getAddresses());
//                gatewayBean.setSid(deviceBean.getSid());
//                gatewayBean.setDeviceId(deviceBean.getDeviceId());
//                gatewayBean.setDevice_name(deviceBean.getName());
//                gatewayBean.setDeviceStatus(deviceBean.getDeviceStatus());
//                gatewayBean.setHomeId(deviceBean.getHomeId());
//                gatewayBean.setSpk(deviceBean.getSpk());
//                gatewayBean.setDeviceType(deviceBean.getDeviceType());
                List<CloudInverterDeviceBean> newList = new ArrayList<>();
                newList.add(deviceBean);
                // //目的是为了获取拿到网关ID,mqtt通讯秘钥等信息,缓存本地逆变器列表里面,发送数据数据时自动去缓存列表里面去查找;
                HdlDeviceLogic.getInstance().setDeviceRemoteInfo(newList, deviceBean.getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
                    @Override
                    public void onSuccess(List<GatewayBean> obj) {
                        GatewayBean newGatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(deviceBean.getOsn());
                        String jsonEncryption = URLEncodingUtils.encodeURIComponent(new Gson().toJson(newGatewayBean));
                        String path = HDLUniMP.UNI_EVENT_OPEN_DEVICE_DETAILS + "?inverterInfo=" + jsonEncryption;
                        HdlUniLogic.getInstance().openUniMP(path, null);
                    }
                    @Override
                    public void onFailure(HDLException e) {
                    }
                });
            }
        });
        //设备设置下拉箭头颜色
@@ -468,7 +503,7 @@
        houseInfoAdapter = new HouseInfoAdapter(_mActivity);
        viewBinding.fragmentHouseSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity));
        viewBinding.fragmentHouseSrlListRc.setAdapter(houseInfoAdapter);
        houseInfoAdapter.setList(this.houseListBeanIDList);
        houseInfoAdapter.setList(this.houseListBeanIDList, powerStationStatusValue);
        //设备标签
        deviceInfoAdapter = new DeviceInfoAdapter(_mActivity);
@@ -578,15 +613,20 @@
        } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE.equals(eventBus.getType())) {
            // 取消粘性事件
            EventBus.getDefault().removeStickyEvent(eventBus);
            //uin关闭住宅详情界面通知
            if (MqttRecvClient.getInstance() != null) {
                MqttRecvClient.getInstance().removeAllTopic();
            //是在电站列表页才进来这里
            if (HdlCommonLogic.lowerTagType == LowerTagType.power_station && isClickPowerStationLabel) {
                //uin关闭住宅详情界面通知
                if (MqttRecvClient.getInstance() != null) {
                    MqttRecvClient.getInstance().removeAllTopic();
                }
                loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
            loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
        } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(eventBus.getType())) {
            // 取消粘性事件
            EventBus.getDefault().removeStickyEvent(eventBus);
//            if (!isClickPowerStationLabel) {
//                return;
//            }
            //进去住宅详情uni读取逆变器列表成功后通知
            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).size(); i++) {
                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).get(i).getGatewayId();
@@ -616,9 +656,14 @@
            } else if (eventBus.getType().equals(PowerStationStatus.connecting)) {
                viewBinding.powerStationConnectedIl.parentLl.performClick();
            } else if (eventBus.getType().equals(ConstantManage.station_edit)) {
                //更新一下住宅
                loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
                //编辑后更新一下住宅列表
                //loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
//                getStatusOverview();
                if (houseInfoAdapter != null) {
                    initData();
                    //更新UI
                    houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);
                }
            }
        }
    }
@@ -699,7 +744,7 @@
                            if (houseInfoAdapter != null) {
                                initData();
                                //更新UI
                                houseInfoAdapter.setList(houseListBeanIDList);
                                houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);
                            }
                        }
                        nullDataUpdateUi();
@@ -749,9 +794,9 @@
            showLoading();
        }
        //获取住宅(电站)ID列表
        HdlDeviceLogic.getInstance().getPowerStationDeviceList("", pageNo, pageSize, new CloudCallBeak<PageNumberObject<DeviceBean>>() {
        HdlDeviceLogic.getInstance().getPowerStationDeviceList("", pageNo, pageSize, new CloudCallBeak<PageNumberObject<CloudInverterDeviceBean>>() {
            @Override
            public void onSuccess(PageNumberObject<DeviceBean> pageNumberObject) {
            public void onSuccess(PageNumberObject<CloudInverterDeviceBean> pageNumberObject) {
                HdlThreadLogic.runMainThread(new Runnable() {
                    @Override
                    public void run() {
@@ -880,7 +925,7 @@
                initializeInverter(list); //发起初始化指令给逆变器;(注意:只能是本地发送了(要搜索局域网逆变器列表,建立本地通讯通道),删除电站成功后,云端解绑逆变器的关系)
                HdlResidenceLogic.getInstance().delHouseId(homeId);//删除电站缓存
                initData();//初始化缓存数据
                houseInfoAdapter.setList(houseListBeanIDList);//重新刷新列表
                houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);//重新刷新列表
                nullDataUpdateUi();//检测数据是否为空
            }