mac
2024-05-17 6266d263e91a6e90c64fb3e6f2be348146371cc8
app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java
@@ -34,6 +34,7 @@
import com.hdl.photovoltaic.ui.adapter.HouseInfoAdapter;
import com.hdl.photovoltaic.ui.bean.DeviceBean;
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.widget.DefaultFilteringDialog;
@@ -42,6 +43,10 @@
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 org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;
@@ -87,6 +92,9 @@
    @Override
    public void onBindView(Bundle savedInstanceState) {
        //放在这里也对,这里只是被创建一次
//        loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
//        getStatusOverview();
        initData();
        //初始化
        initView();
@@ -106,6 +114,8 @@
                isClickPowerStationLabel = true;
                viewBinding.powerStationLabel.setTextAppearance(R.style.Text20Style);
                viewBinding.deviceLabel.setTextAppearance(R.style.Text16Style);
                viewBinding.editIv.setVisibility(View.VISIBLE);//编辑图标隐藏
                viewBinding.addIv.setVisibility(View.VISIBLE);//添加图标隐藏
                viewBinding.powerStationLabelParent.setVisibility(View.VISIBLE);//电站标签【父容器】显示
                viewBinding.deviceLabelParent.setVisibility(View.GONE);//设备标签【父容器】隐藏
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
@@ -191,7 +201,7 @@
                if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) {
                    if (!isHouseLoadingMore) {
                        // 滑动到了底部,执行相应的操作
                        HdlLogLogic.print("--->滑动到了底部");
                        HdlLogLogic.print("---滑动到了底部");
                        loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, ++currentHouseListPage, false);
                    }
                }
@@ -202,7 +212,7 @@
            @Override
            public void onClick(int position, HouseIdBean houseIdBean) {
                //点击住宅详情
                HdlLogLogic.print("点击住宅详情--->" + new Gson().toJson(houseIdBean), false);
                HdlLogLogic.print("点击住宅详情---" + new Gson().toJson(houseIdBean), false);
                HdlResidenceLogic.getInstance().switchHouse(houseIdBean);
                String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId() + "&homeName=" + houseIdBean.getHomeName() + "&powerStationStatus=" + houseIdBean.getPowerStationStatus();
                HdlUniLogic.getInstance().openUniMP(path, null);
@@ -377,7 +387,7 @@
                if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) {
                    if (!isDeviceLoadingMore) {
                        // 滑动到了底部,执行相应的操作
                        HdlLogLogic.print("--->滑动到了底部");
                        HdlLogLogic.print("---滑动到了底部");
                        loadNextPageDeviceList(false, ++currentDeviceListPage, false);
                    }
                }
@@ -398,6 +408,11 @@
    private void initView() {
        viewBinding.powerStationLabelParent.setVisibility(View.VISIBLE);
        viewBinding.deviceLabelParent.setVisibility(View.GONE);
        viewBinding.powerStationAllIl.stationTitleTv.setText(getString(R.string.message_all));
        viewBinding.powerStationFaultsIl.stationTitleTv.setText(getString(R.string.my_power_station_malfunction));
        viewBinding.hpowerStationOfflineIl.stationTitleTv.setText(getString(R.string.my_power_station_off_line));
        viewBinding.powerStationConnectedIl.stationTitleTv.setText(getString(R.string.to_be_added));
        //电站标签
        houseInfoAdapter = new HouseInfoAdapter(_mActivity);
        viewBinding.fragmentHouseSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity));
@@ -422,6 +437,8 @@
            this.deviceInfoList.add(new DeviceBean());
//            this.deviceInfoList.addAll(HdlDeviceLogic.getInstance().getListDevice());
        }
    }
    /**
@@ -429,11 +446,13 @@
     *
     * @param eventBus 数据
     */
    @Override
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEventMessage(BaseEventBus eventBus) {
        super.onEventMessage(eventBus);
        if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(eventBus.getTopic())) {
            if (HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION.equals(eventBus.getType())) {
                // 取消粘性事件
                EventBus.getDefault().removeStickyEvent(eventBus);
                //uin创建电站成功后通知
                loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
                if (eventBus.getData() != null) {
@@ -444,6 +463,8 @@
                }
            } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT.equals(eventBus.getType())) {
                // 取消粘性事件
                EventBus.getDefault().removeStickyEvent(eventBus);
                //todo 现在默认刷新全部
                //uin编辑住宅通知
//                String homeId = HdlUniLogic.getInstance().getKeyValue("homeId", eventBus.getData());
@@ -470,6 +491,8 @@
            }
        } 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();
@@ -477,6 +500,8 @@
            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);
            //进去住宅详情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();
@@ -488,10 +513,43 @@
        } else if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) {
            //接收外部点击事件
            if (eventBus.getType().equals(HomepageTitleTabSwitch.powerstation.toString())) {
                // 取消粘性事件
                EventBus.getDefault().removeStickyEvent(eventBus);
                HdlLogLogic.print("正在点击【电站】");
//                HdlThreadLogic.runSubThread(new Runnable() {
//                    @Override
//                    public void run() {
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
                getStatusOverview();
//                    }
//                });
            }
        }
    }
    /**
     * 电站状态概览
     */
    private void getStatusOverview() {
        HdlResidenceLogic.getInstance().getStatusOverview(new CloudCallBeak<StatusOverviewBean>() {
            @Override
            public void onSuccess(StatusOverviewBean statusOverviewBean) {
                if (statusOverviewBean == null) {
                    return;
                }
                viewBinding.powerStationAllIl.stationTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getTotal()));
                viewBinding.powerStationFaultsIl.stationTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getFault()));
                viewBinding.hpowerStationOfflineIl.stationTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getOffline()));
                viewBinding.powerStationConnectedIl.stationTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getConnecting()));
            }
            @Override
            public void onFailure(HDLException e) {
            }
        });
    }
@@ -511,15 +569,7 @@
     * @param pageNo               页码
     * @param isClear              是否清除数据
     */
    private void loadNextPageHouseList(boolean isRefreshing,
                                       String key,
                                       String keyValue,
                                       String installedCapacityMin,
                                       String installedCapacityMax,
                                       String gridType,
                                       String powerStationStatus,
                                       long pageNo,
                                       boolean isClear) {
    private void loadNextPageHouseList(boolean isRefreshing, String key, String keyValue, String installedCapacityMin, String installedCapacityMax, String gridType, String powerStationStatus, long pageNo, boolean isClear) {
        if (isClear) {
            clearData();
        }
@@ -535,57 +585,50 @@
        }
        //获取住宅(电站)ID列表
        HdlResidenceLogic.getInstance().getResidenceIdList(
                key,
                keyValue,
                installedCapacityMin,
                installedCapacityMax,
                gridType,
                powerStationStatus,
                pageNo, pageSize, new CloudCallBeak<HdlResidenceLogic.HouseBeanClass>() {
        HdlResidenceLogic.getInstance().getResidenceIdList(key, keyValue, installedCapacityMin, installedCapacityMax, gridType, powerStationStatus, pageNo, pageSize, new CloudCallBeak<HdlResidenceLogic.HouseBeanClass>() {
            @Override
            public void onSuccess(HdlResidenceLogic.HouseBeanClass houseBeanClass) {
                HdlThreadLogic.runMainThread(new Runnable() {
                    @Override
                    public void onSuccess(HdlResidenceLogic.HouseBeanClass houseBeanClass) {
                        HdlThreadLogic.runMainThread(new Runnable() {
                            @Override
                            public void run() {
                                if (isRefreshing) {
                                    hideLoading();
                                }
                                isHouseLoadingMore = false;
                                if (houseBeanClass != null) {
                                    currentHouseListTotal = (int) houseBeanClass.getTotalPage();
                                    currentHouseListPage = (int) houseBeanClass.getPageNo();
                                    //更新缓存
                                    HdlResidenceLogic.getInstance().setHouseIdList(houseBeanClass.getList());
                                    if (houseInfoAdapter != null) {
                                        initData();
                                        //更新UI
                                        houseInfoAdapter.setList(houseListBeanIDList);
                                    }
                                }
                                nullDataUpdateUi();
                    public void run() {
                        if (isRefreshing) {
                            hideLoading();
                        }
                        isHouseLoadingMore = false;
                        if (houseBeanClass != null) {
                            currentHouseListTotal = (int) houseBeanClass.getTotalPage();
                            currentHouseListPage = (int) houseBeanClass.getPageNo();
                            //更新缓存
                            HdlResidenceLogic.getInstance().setHouseIdList(houseBeanClass.getList());
                            if (houseInfoAdapter != null) {
                                initData();
                                //更新UI
                                houseInfoAdapter.setList(houseListBeanIDList);
                            }
                        }, _mActivity, ShowErrorMode.YES);
                        }
                        nullDataUpdateUi();
                    }
                }, _mActivity, ShowErrorMode.YES);
            }
            @Override
            public void onFailure(HDLException e) {
                HdlThreadLogic.runMainThread(new Runnable() {
                    @Override
                    public void run() {
                        if (currentHouseListPage > 1) {
                            --currentHouseListPage;
                        }
                        isHouseLoadingMore = false;
                        if (isRefreshing) {
                            hideLoading();
                        }
                    }
                    @Override
                    public void onFailure(HDLException e) {
                        HdlThreadLogic.runMainThread(new Runnable() {
                            @Override
                            public void run() {
                                if (currentHouseListPage > 1) {
                                    --currentHouseListPage;
                                }
                                isHouseLoadingMore = false;
                                if (isRefreshing) {
                                    hideLoading();
                                }
                            }
                        }, _mActivity, ShowErrorMode.YES);
                    }
                });
                }, _mActivity, ShowErrorMode.YES);
            }
        });
    }
    /**