| | |
| | | package com.hdl.photovoltaic.ui.powerstation; |
| | | |
| | | import android.Manifest; |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Bundle; |
| | | import android.view.View; |
| | |
| | | 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; |
| | | 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 org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | private boolean isClickPowerStationLabel = true;//(电站标签=true,设备标签=false) |
| | | |
| | | private String key = SortValue.all; |
| | | private String value = SortValue.all; |
| | | private String value = SortValue.all;//descending:降序,ascending:升序 |
| | | private String installedCapacityMinValue = "";//最小组串容量(装机容量) |
| | | private String installedCapacityMaxValue = "";//最大组串容量(装机容量) |
| | | private String gridTypeValue = "";//并网状态(全部 不传该过滤参数,FULL_GRID:并网,OFFLINE:离网) |
| | | private String powerStationStatusValue = "";//电站状态(全部 不传该过滤参数,1:正常(运行),2:离线,3:待接入,4:故障) |
| | | |
| | | private long pageSize = 20;//页数 |
| | | private final long pageSize = 20;//页数 |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | //放在这里也对,这里只是被创建一次 |
| | | // loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true); |
| | | // getStatusOverview(); |
| | | initData(); |
| | | //初始化 |
| | | initView(); |
| | |
| | | isClickPowerStationLabel = true; |
| | | viewBinding.powerStationLabel.setTextAppearance(R.style.Text20Style); |
| | | viewBinding.deviceLabel.setTextAppearance(R.style.Text16Style); |
| | | viewBinding.powerStationLabelParent.setVisibility(View.VISIBLE); |
| | | viewBinding.deviceLabelParent.setVisibility(View.GONE);//设备标签隐藏 |
| | | loadNextPageHouseList(true, 1, true); |
| | | 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); |
| | | } |
| | | }); |
| | | //设备标签 |
| | |
| | | viewBinding.powerStationLabel.setTextAppearance(R.style.Text16Style); |
| | | viewBinding.editIv.setVisibility(View.GONE);//编辑图标隐藏 |
| | | viewBinding.addIv.setVisibility(View.GONE);//添加图标隐藏 |
| | | viewBinding.powerStationLabelParent.setVisibility(View.GONE);//电站标签隐藏 |
| | | viewBinding.deviceLabelParent.setVisibility(View.VISIBLE); |
| | | viewBinding.powerStationLabelParent.setVisibility(View.GONE);//电站标签【父容器】隐藏 |
| | | viewBinding.deviceLabelParent.setVisibility(View.VISIBLE);//设备标签【父容器】显示 |
| | | loadNextPageDeviceList(true, 1, true); |
| | | } |
| | | }); |
| | | |
| | | //添加电站 |
| | | //电站添加 |
| | | viewBinding.addIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | |
| | | } |
| | | }); |
| | | //电站搜索 |
| | | viewBinding.powerStationSearchClickCl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | Intent intent = new Intent(); |
| | | intent.setClass(_mActivity, HouseSearchActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | //默认选择参数图标 |
| | | viewBinding.powerStationDefaultConditionIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | DefaultFilteringDialog defaultFilteringDialog = new DefaultFilteringDialog(_mActivity); |
| | | defaultFilteringDialog.show(); |
| | | defaultFilteringDialog.initState(installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue); |
| | | defaultFilteringDialog.setOnClickListener(new DefaultFilteringDialog.OnClickListener() { |
| | | @Override |
| | | public void confirm(String min, String max, String state) { |
| | | installedCapacityMinValue = min;//最小组串容量(装机容量) |
| | | installedCapacityMaxValue = max;//最大组串容量(装机容量) |
| | | gridTypeValue = state;//并网状态(全部 不传该过滤参数,FULL_GRID:并网,OFFLINE:离网) |
| | | loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | //电站设置下拉箭头颜色 |
| | | viewBinding.fragmentHouseSrl.setColorSchemeResources(R.color.text_FF245EC3); |
| | | //电站下拉读取 |
| | |
| | | @Override |
| | | public void onRefresh() { |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | loadNextPageHouseList(true, 1, true); |
| | | loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true); |
| | | } |
| | | }); |
| | | //电站上拉读取 |
| | |
| | | if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) { |
| | | if (!isHouseLoadingMore) { |
| | | // 滑动到了底部,执行相应的操作 |
| | | HdlLogLogic.print("--->滑动到了底部"); |
| | | loadNextPageHouseList(false, ++currentHouseListPage, false); |
| | | HdlLogLogic.print("---滑动到了底部"); |
| | | loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, ++currentHouseListPage, false); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | //进入电站详情,删除电站,移动电站位置 |
| | | //电站详情进入,删除电站,移动电站位置 |
| | | houseInfoAdapter.setNoOnclickListener(new HouseInfoAdapter.OnclickListener() { |
| | | @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); |
| | |
| | | |
| | | } |
| | | }); |
| | | //编辑电站按钮 |
| | | //电站编辑按钮 |
| | | viewBinding.editIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | value = isSelected ? SortValue.ascending : SortValue.descending; |
| | | } |
| | | }); |
| | | //发电功率筛选 |
| | | //电站发电功率筛选 |
| | | viewBinding.stationPowerRl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | value = isSelected ? SortValue.ascending : SortValue.descending; |
| | | } |
| | | }); |
| | | //当日发电量筛选 |
| | | //电站当日发电量筛选 |
| | | viewBinding.stationDayRl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | value = isSelected ? SortValue.ascending : SortValue.descending; |
| | | } |
| | | }); |
| | | //当月发电量筛选 |
| | | //电站当月发电量筛选 |
| | | viewBinding.stationMonthRl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | value = isSelected ? SortValue.ascending : SortValue.descending; |
| | | } |
| | | }); |
| | | //点击设备 |
| | | //设备点击 |
| | | deviceInfoAdapter.setOnclickListener(new DeviceInfoAdapter.OnClickListener() { |
| | | @Override |
| | | public void onClick(int position, DeviceBean deviceBean) { |
| | |
| | | if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) { |
| | | if (!isDeviceLoadingMore) { |
| | | // 滑动到了底部,执行相应的操作 |
| | | HdlLogLogic.print("--->滑动到了底部"); |
| | | HdlLogLogic.print("---滑动到了底部"); |
| | | loadNextPageDeviceList(false, ++currentDeviceListPage, false); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | //设备添搜索 |
| | | viewBinding.deviceSearchCl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | Intent intent = new Intent(); |
| | | intent.setClass(_mActivity, DeviceSearchActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | |
| | |
| | | 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)); |
| | |
| | | this.deviceInfoList.add(new DeviceBean()); |
| | | // this.deviceInfoList.addAll(HdlDeviceLogic.getInstance().getListDevice()); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @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, 1, true); |
| | | loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true); |
| | | if (eventBus.getData() != null) { |
| | | Gson gson = new Gson(); |
| | | String json = eventBus.getData().toString(); |
| | |
| | | |
| | | } |
| | | } 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()); |
| | |
| | | |
| | | } |
| | | } 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(); |
| | | } |
| | | loadNextPageHouseList(false, 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); |
| | | //进去住宅详情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(); |
| | |
| | | } else if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) { |
| | | //接收外部点击事件 |
| | | if (eventBus.getType().equals(HomepageTitleTabSwitch.powerstation.toString())) { |
| | | // 取消粘性事件 |
| | | EventBus.getDefault().removeStickyEvent(eventBus); |
| | | HdlLogLogic.print("正在点击【电站】"); |
| | | loadNextPageHouseList(true, 1, true); |
| | | // 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) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 刷新UI(电站) |
| | | * |
| | | * @param isRefreshing 表示是下拉刷新的 |
| | | * @param isRefreshing 表示是下拉刷新的 |
| | | * @param key 发电功率排序(powerSort); |
| | | * 今日发电量排序(todayElectricitySort); |
| | | * 创建时间排序(createTimeSort); |
| | | * @param keyValue (descending:降序 |
| | | * ascending:升序), |
| | | * @param installedCapacityMin 最小组串容量(装机容量) |
| | | * @param installedCapacityMax 最大组串容量(装机容量) |
| | | * @param gridType 并网状态 (全部 :"";FULL_GRID : 并网;OFFLINE :离网) |
| | | * @param powerStationStatus 电站状态 (全部 :"";1 : 正常;2 : 离线; 3 : 待接入;4 : 故障) |
| | | * @param pageNo 页码 |
| | | * @param isClear 是否清除数据 |
| | | */ |
| | | private void loadNextPageHouseList(boolean isRefreshing, 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(); |
| | | } |
| | |
| | | } |
| | | |
| | | //获取住宅(电站)ID列表 |
| | | HdlResidenceLogic.getInstance().getResidenceIdList(key, value, 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() { |
| | |
| | | if (isRefreshing) { |
| | | hideLoading(); |
| | | } |
| | | |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | | } |
| | |
| | | */ |
| | | private void nullDataUpdateUi() { |
| | | boolean is_data; |
| | | String tipText = ""; |
| | | if (isClickPowerStationLabel) { |
| | | is_data = houseListBeanIDList != null && houseListBeanIDList.size() > 0; |
| | | tipText = getString(R.string.my_power_station_data_null); |
| | | } else { |
| | | is_data = deviceInfoList != null && deviceInfoList.size() > 0; |
| | | tipText = getString(R.string.no_equipment); |
| | | } |
| | | HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.nullDataIc.getRoot(), viewBinding.nullDataIc.nullDataGifAnimationIv, viewBinding.nullDataIc.nullDataTv, getString(R.string.my_power_station_data_null), is_data); |
| | | HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.nullDataIc.getRoot(), viewBinding.nullDataIc.nullDataGifAnimationIv, viewBinding.nullDataIc.nullDataTv, tipText, is_data); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | HdlDeviceLogic.getInstance().initializeGateway(gatewayBean.getDevice_mac(), new LinkCallBack<Boolean>() { |
| | | HdlDeviceLogic.getInstance().initializeInverter(gatewayBean.getDevice_mac(), new LinkCallBack<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | // HdlLogLogic.print("初始化逆变器成功-->mac:" + cloudInverterDeviceBean.getOsn(),true); |
| | |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | hideLoading(); |
| | | //发起初始化指令给逆变器; |
| | | initializeInverter(list); |
| | | HdlResidenceLogic.getInstance().delHouseId(homeId); |
| | | initializeInverter(list); //发起初始化指令给逆变器;(注意:只能是本地发送了(要搜索局域网逆变器列表,建立本地通讯通道),删除电站成功后,云端解绑逆变器的关系) |
| | | HdlResidenceLogic.getInstance().delHouseId(homeId);//删除电站缓存 |
| | | initData();//初始化缓存数据 |
| | | houseInfoAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | nullDataUpdateUi();//检测数据是否为空 |
| | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | hideLoading(); |
| | | |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 申请权限 |
| | | */ |
| | | private void requestPermissions(PermissionsResultCallback permissionsResultCallback) { |
| | | |
| | | |
| | | mPermissionsResultCallback = permissionsResultCallback; |
| | | |
| | | String[] s = new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CAMERA,}; |
| | | String[] ary = PermissionUtils.checkPermission(_mActivity, s); |
| | | if (ary.length > 0) { |
| | | requestPermissions(ary, PermissionUtils.STATUS_SUCCESS); |
| | | } else { |
| | | if (mPermissionsResultCallback != null) { |
| | | mPermissionsResultCallback.succeed(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |