| | |
| | | package com.hdl.photovoltaic.ui.powerstation; |
| | | |
| | | import android.Manifest; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageManager; |
| | | import android.hardware.camera2.CameraManager; |
| | | import android.os.Bundle; |
| | | import android.view.View; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.bean.PageNumberObject; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.FragmentHouseListBinding; |
| | | import com.hdl.photovoltaic.base.CustomBaseFragment; |
| | | import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch; |
| | | import com.hdl.photovoltaic.enums.ShowErrorMode; |
| | | import com.hdl.photovoltaic.enums.SortType; |
| | | import com.hdl.photovoltaic.enums.SortValue; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.listener.LinkCallBack; |
| | | import com.hdl.photovoltaic.other.HdlCommonLogic; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlResidenceLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | 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.HouseIdBean; |
| | | 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 java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * (住宅)电站列表-界面 |
| | | * 电站和设备-界面 |
| | | */ |
| | | public class HouseListFragment extends CustomBaseFragment { |
| | | private FragmentHouseListBinding viewBinding; |
| | | private HouseInfoAdapter houseInfoAdapter; |
| | | private CameraManager manager; |
| | | |
| | | private List<HouseIdBean> houseListBeanIDList = null; |
| | | private DeviceInfoAdapter deviceInfoAdapter; |
| | | |
| | | private List<HouseIdBean> houseListBeanIDList; |
| | | private List<DeviceBean> deviceInfoList; |
| | | |
| | | |
| | | private int currentHouseListPage = 0; // 当前电站列表页码 |
| | | private int currentHouseListTotal = 0; // 电站列表总页码 |
| | | private boolean isHouseLoadingMore = false; // 标记电站列表正在加载更多数据 |
| | | |
| | | private int currentDeviceListPage = 0; // 当前设备列表页码 |
| | | private int currentDeviceListTotal = 0; // 设备列表总页码 |
| | | private boolean isDeviceLoadingMore = false; // 标记设备列表正在加载更多数据 |
| | | |
| | | private boolean isClickPowerStationLabel = true;//(电站标签=true,设备标签=false) |
| | | |
| | | private String key = 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 final long pageSize = 20;//页数 |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | manager = (CameraManager) _mActivity.getSystemService(Context.CAMERA_SERVICE); |
| | | initData(); |
| | | //初始化 |
| | | initView(); |
| | |
| | | |
| | | private void initEvent() { |
| | | |
| | | //电站标签 |
| | | viewBinding.powerStationLabel.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (isClickPowerStationLabel) { |
| | | return; |
| | | } |
| | | 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, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true); |
| | | } |
| | | }); |
| | | //设备标签 |
| | | viewBinding.deviceLabel.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (!isClickPowerStationLabel) { |
| | | return; |
| | | } |
| | | isClickPowerStationLabel = false; |
| | | viewBinding.deviceLabel.setTextAppearance(R.style.Text20Style); |
| | | 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);//设备标签【父容器】显示 |
| | | loadNextPageDeviceList(true, 1, true); |
| | | } |
| | | }); |
| | | |
| | | //添加电站 |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setOnClickListener(new View.OnClickListener() { |
| | | //电站添加 |
| | | viewBinding.addIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null); |
| | | |
| | | } |
| | | }); |
| | | //设置下拉箭头颜色 |
| | | //电站搜索 |
| | | 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); |
| | | //电站下拉读取 |
| | | viewBinding.fragmentHouseSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | downReadData(true); |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true); |
| | | } |
| | | }); |
| | | //进入电站详情,删除电站,移动电站位置 |
| | | //电站上拉读取 |
| | | viewBinding.fragmentHouseSrlListRc.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| | | @Override |
| | | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { |
| | | // super.onScrolled(recyclerView, dx, dy); |
| | | |
| | | LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); |
| | | if (layoutManager == null) { |
| | | return; |
| | | } |
| | | int visibleItemCount = layoutManager.getChildCount(); |
| | | int totalItemCount = layoutManager.getItemCount(); |
| | | int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition(); |
| | | if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) { |
| | | if (!isHouseLoadingMore) { |
| | | // 滑动到了底部,执行相应的操作 |
| | | 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) { |
| | |
| | | |
| | | @Override |
| | | public void onMoveClick(int position, HouseIdBean houseIdBean) { |
| | | if (position == 0) { |
| | | HdlThreadLogic.toast(_mActivity, getString(R.string.already_the_first_one)); |
| | | return; |
| | | } |
| | | String frontHomeId = ""; |
| | | if (position > 0) { |
| | | frontHomeId = houseListBeanIDList.get(position - 1).getHomeId(); |
| | | if (position > 1) { |
| | | frontHomeId = houseListBeanIDList.get(position - 2).getHomeId(); |
| | | } |
| | | HdlResidenceLogic.getInstance().moveResidence(houseIdBean.getHomeId(), frontHomeId, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | |
| | | HdlResidenceLogic.getInstance().moveHouseId(houseIdBean.getHomeId()); |
| | | initData();//初始化缓存数据 |
| | | houseInfoAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空 |
| | | nullDataUpdateUi();//检测数据是否为空 |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void onDelClick(int position, HouseIdBean houseIdBean) { |
| | | |
| | | DelayedConfirmationCancelDialog delayedConfirmationCancelDialog = new DelayedConfirmationCancelDialog(_mActivity); |
| | | delayedConfirmationCancelDialog.setTitleContent(getString(R.string.loading_title_tip)); |
| | | String homeName = "\"" + houseIdBean.getHomeName() + "\""; |
| | | delayedConfirmationCancelDialog.setContent(getString(R.string.delete_power_station).replace("XX", homeName)); |
| | | delayedConfirmationCancelDialog.setContent(getString(R.string.delete_power_station).replace("%s", homeName)); |
| | | delayedConfirmationCancelDialog.show(); |
| | | delayedConfirmationCancelDialog.startCountdown(3); |
| | | delayedConfirmationCancelDialog.startCountdown(4); |
| | | delayedConfirmationCancelDialog.setYesOnclickListener(new DelayedConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | //删除住宅 |
| | | HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() { |
| | | delayedConfirmationCancelDialog.dismiss(); |
| | | showLoading(getString(R.string.deleting_please_wait)); |
| | | HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(houseIdBean.getHomeId(), new CloudCallBeak<List<GatewayBean>>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlResidenceLogic.getInstance().delHouseId(houseIdBean.getHomeId()); |
| | | initData();//初始化缓存数据 |
| | | houseInfoAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空 |
| | | delayedConfirmationCancelDialog.dismiss(); |
| | | public void onSuccess(List<GatewayBean> list) { |
| | | //发起删除电站指令 |
| | | deleteResidence(houseIdBean.getHomeId(), list); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | //发起删除电站指令 |
| | | deleteResidence(houseIdBean.getHomeId(), null); |
| | | } |
| | | }); |
| | | |
| | | // //删除住宅 |
| | | // HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() { |
| | | // @Override |
| | | // public void onSuccess(Boolean obj) { |
| | | // HdlResidenceLogic.getInstance().delHouseId(houseIdBean.getHomeId()); |
| | | // initData();//初始化缓存数据 |
| | | // houseInfoAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | // nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空 |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onFailure(HDLException e) { |
| | | // HdlThreadLogic.toast(_mActivity, e); |
| | | // } |
| | | // }); |
| | | } |
| | | }); |
| | | delayedConfirmationCancelDialog.setNoOnclickListener(new DelayedConfirmationCancelDialog.onNoOnclickListener() { |
| | |
| | | |
| | | } |
| | | }); |
| | | |
| | | //编辑电站按钮 |
| | | viewBinding.toolbarTopFragmentHouseListRl.topEditIv.setOnClickListener(new View.OnClickListener() { |
| | | //电站编辑按钮 |
| | | 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) { |
| | | boolean isSelected = !v.isSelected(); |
| | | viewBinding.stationNameRl.setSelected(isSelected); |
| | | viewBinding.stationNameIv.setSelected(isSelected); |
| | | key = SortType.homeNameSort; |
| | | value = isSelected ? SortValue.ascending : SortValue.descending; |
| | | } |
| | | }); |
| | | //电站发电功率筛选 |
| | | viewBinding.stationPowerRl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | boolean isSelected = !v.isSelected(); |
| | | viewBinding.stationPowerRl.setSelected(isSelected); |
| | | viewBinding.stationPowerIv.setSelected(isSelected); |
| | | key = SortType.powerSort; |
| | | value = isSelected ? SortValue.ascending : SortValue.descending; |
| | | } |
| | | }); |
| | | //电站当日发电量筛选 |
| | | viewBinding.stationDayRl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | boolean isSelected = !v.isSelected(); |
| | | viewBinding.stationDayRl.setSelected(isSelected); |
| | | viewBinding.stationDayIv.setSelected(isSelected); |
| | | key = SortType.todayElectricitySort; |
| | | value = isSelected ? SortValue.ascending : SortValue.descending; |
| | | } |
| | | }); |
| | | //电站当月发电量筛选 |
| | | viewBinding.stationMonthRl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | boolean isSelected = !v.isSelected(); |
| | | viewBinding.stationMonthRl.setSelected(isSelected); |
| | | viewBinding.stationMonthIv.setSelected(isSelected); |
| | | key = SortType.monthElectricitySort; |
| | | value = isSelected ? SortValue.ascending : SortValue.descending; |
| | | } |
| | | }); |
| | | //设备点击 |
| | | deviceInfoAdapter.setOnclickListener(new DeviceInfoAdapter.OnClickListener() { |
| | | @Override |
| | | public void onClick(int position, DeviceBean deviceBean) { |
| | | |
| | | } |
| | | }); |
| | | //设备设置下拉箭头颜色 |
| | | viewBinding.fragmentDeviceSrl.setColorSchemeResources(R.color.text_FF245EC3); |
| | | //设备下拉读取 |
| | | viewBinding.fragmentDeviceSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | viewBinding.fragmentDeviceSrl.setRefreshing(false); |
| | | loadNextPageDeviceList(false, 1, true); |
| | | } |
| | | }); |
| | | //设备上拉读取 |
| | | viewBinding.fragmentDeviceSrlListRc.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| | | @Override |
| | | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { |
| | | // super.onScrolled(recyclerView, dx, dy); |
| | | |
| | | LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); |
| | | if (layoutManager == null) { |
| | | return; |
| | | } |
| | | int visibleItemCount = layoutManager.getChildCount(); |
| | | int totalItemCount = layoutManager.getItemCount(); |
| | | int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition(); |
| | | if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) { |
| | | if (!isDeviceLoadingMore) { |
| | | // 滑动到了底部,执行相应的操作 |
| | | 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.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.my_power_station); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topEditIv.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topEditIv.setImageResource(R.drawable.editor_house); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setImageResource(R.drawable.add); |
| | | LinearLayoutManager linearLayout = new LinearLayoutManager(_mActivity); |
| | | viewBinding.powerStationLabelParent.setVisibility(View.VISIBLE); |
| | | viewBinding.deviceLabelParent.setVisibility(View.GONE); |
| | | //电站标签 |
| | | houseInfoAdapter = new HouseInfoAdapter(_mActivity); |
| | | viewBinding.fragmentHouseSrlListRc.setLayoutManager(linearLayout); |
| | | viewBinding.fragmentHouseSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity)); |
| | | viewBinding.fragmentHouseSrlListRc.setAdapter(houseInfoAdapter); |
| | | houseInfoAdapter.setList(this.houseListBeanIDList); |
| | | this.nullDataUpdateUi(houseListBeanIDList); |
| | | |
| | | //设备标签 |
| | | deviceInfoAdapter = new DeviceInfoAdapter(_mActivity); |
| | | viewBinding.fragmentDeviceSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity)); |
| | | viewBinding.fragmentDeviceSrlListRc.setAdapter(deviceInfoAdapter); |
| | | this.nullDataUpdateUi(); |
| | | |
| | | |
| | | } |
| | | |
| | | private void initData() { |
| | | this.houseListBeanIDList = new ArrayList<>(); |
| | | this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList()); |
| | | if (isClickPowerStationLabel) { |
| | | this.houseListBeanIDList = new ArrayList<>(); |
| | | this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList()); |
| | | } else { |
| | | this.deviceInfoList = new ArrayList<>(); |
| | | this.deviceInfoList.add(new DeviceBean()); |
| | | // this.deviceInfoList.addAll(HdlDeviceLogic.getInstance().getListDevice()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(eventBus.getTopic())) { |
| | | if (HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION.equals(eventBus.getType())) { |
| | | //uin创建电站成功后通知 |
| | | downReadData(false); |
| | | 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_CLOSE_HOME_DETAILS_PAGE.equals(eventBus.getType())) { |
| | | |
| | | //uin关闭住宅详情界面通知 |
| | | if (MqttRecvClient.getInstance() != null) { |
| | | MqttRecvClient.getInstance().removeAllTopic(); |
| | | } |
| | | downReadData(false); |
| | | loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true); |
| | | |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(eventBus.getType())) { |
| | | //进去住宅详情uni读取逆变器列表成功后通知 |
| | | // for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList().size(); i++) { |
| | | //String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList().get(i).getGatewayId(); |
| | | //字符串是自己按规则拼接的,里面注册主题时会解析字符串,只拿getGatewayId()值; |
| | | //String topic = "/user/" + gatewayId+"/1"; |
| | | //进去住宅详情开始订阅主题 |
| | | MqttRecvClient.getInstance().checkAndsubscribeAllTopics(""); |
| | | // } |
| | | for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).size(); i++) { |
| | | String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).get(i).getGatewayId(); |
| | | //字符串是自己按规则拼接的,里面注册主题时会解析字符串,只拿getGatewayId()值; |
| | | String topic = "/user/" + gatewayId + "/#"; |
| | | //进去住宅详情开始订阅主题 |
| | | MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topic); |
| | | } |
| | | } else if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) { |
| | | //接收外部点击事件 |
| | | if (eventBus.getType().equals(HomepageTitleTabSwitch.powerstation.toString())) { |
| | | HdlLogLogic.print("正在点击【电站】"); |
| | | initData();//初始化缓存数据 |
| | | houseInfoAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 刷新UI |
| | | * 刷新UI(电站) |
| | | * |
| | | * @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, |
| | | String key, |
| | | String keyValue, |
| | | String installedCapacityMin, |
| | | String installedCapacityMax, |
| | | String gridType, |
| | | String powerStationStatus, |
| | | long pageNo, |
| | | boolean isClear) { |
| | | if (isClear) { |
| | | clearData(); |
| | | } |
| | | //第一页读取数据强制读取 |
| | | if (pageNo > 1 && currentHouseListPage > currentHouseListTotal) { |
| | | --currentHouseListPage; |
| | | //当前页不能大于总页数 |
| | | return; |
| | | } |
| | | isHouseLoadingMore = true;//标记读取状态 |
| | | if (isRefreshing) { |
| | | showLoading(); |
| | | } |
| | | |
| | | //获取住宅(电站)ID列表 |
| | | 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 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(); |
| | | } |
| | | }, _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(); |
| | | } |
| | | |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 刷新UI(设备) |
| | | * |
| | | * @param isRefreshing 表示是下拉刷新的 |
| | | * @param pageNo 页码 |
| | | * @param isClear true表示清空缓存 |
| | | */ |
| | | private void downReadData(boolean isRefreshing) { |
| | | private void loadNextPageDeviceList(boolean isRefreshing, long pageNo, boolean isClear) { |
| | | if (isClear) { |
| | | clearData(); |
| | | } |
| | | //第一页读取数据强制读取 |
| | | if (pageNo > 1 && currentDeviceListPage > currentDeviceListTotal) { |
| | | --currentDeviceListPage; |
| | | //当前页不能大于总页数 |
| | | return; |
| | | } |
| | | isDeviceLoadingMore = true;//标记读取状态 |
| | | if (isRefreshing) { |
| | | showLoading(); |
| | | } |
| | | //获取住宅(电站)ID列表 |
| | | HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { |
| | | HdlDeviceLogic.getInstance().getPowerStationDeviceList("", pageNo, pageSize, new CloudCallBeak<PageNumberObject<DeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<HouseIdBean> list) { |
| | | public void onSuccess(PageNumberObject<DeviceBean> pageNumberObject) { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | hideLoading(); |
| | | } |
| | | if (list != null && list.size() > 0) { |
| | | isDeviceLoadingMore = false; |
| | | if (pageNumberObject != null) { |
| | | currentDeviceListTotal = (int) pageNumberObject.getTotalPage(); |
| | | currentDeviceListPage = (int) pageNumberObject.getPageNo(); |
| | | //更新缓存 |
| | | HdlResidenceLogic.getInstance().setHouseIdList(list); |
| | | if (houseInfoAdapter != null) { |
| | | HdlDeviceLogic.getInstance().setListDevice(pageNumberObject.getList()); |
| | | //更新缓存 |
| | | if (deviceInfoAdapter != null) { |
| | | initData(); |
| | | //更新UI |
| | | houseInfoAdapter.setList(houseListBeanIDList); |
| | | deviceInfoAdapter.setList(deviceInfoList); |
| | | } |
| | | |
| | | } |
| | | nullDataUpdateUi(list); |
| | | nullDataUpdateUi(); |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | | |
| | |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | if (currentDeviceListPage > 1) { |
| | | --currentDeviceListPage; |
| | | } |
| | | |
| | | isDeviceLoadingMore = false; |
| | | if (isRefreshing) { |
| | | hideLoading(); |
| | | } |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | | } |
| | |
| | | |
| | | |
| | | /** |
| | | * 申请权限 |
| | | * 清空缓存数据 |
| | | */ |
| | | 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(); |
| | | private void clearData() { |
| | | if (isClickPowerStationLabel) { |
| | | currentHouseListPage = 0;// 重置当前电站列表页码 |
| | | currentHouseListTotal = 0;// 重置当前电站列表总页码 |
| | | if (houseListBeanIDList != null) { |
| | | houseListBeanIDList.clear(); //清空临时缓存列表 |
| | | } |
| | | HdlResidenceLogic.getInstance().clearHouseList(); //表示强制清空所有缓存信息 |
| | | } else { |
| | | currentDeviceListPage = 0; // 重置当前设备列表页码 |
| | | currentDeviceListTotal = 0; // 重置设备列表总页码 |
| | | if (deviceInfoList != null) { |
| | | deviceInfoList.clear();//清空临时缓存列表 |
| | | } |
| | | HdlDeviceLogic.getInstance().clearDeviceList(); //表示强制清空所有缓存信息 |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 没有电站列表的样式 |
| | | */ |
| | | 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, tipText, is_data); |
| | | } |
| | | |
| | | /** |
| | | * 删除电站,逆变器 |
| | | * (开始删除电站,同时,向逆变器发送初始化逆变器指令,无须处理结果) |
| | | * |
| | | * @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().initializeGateway(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); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除电站 |
| | | * |
| | | * @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); |
| | | HdlResidenceLogic.getInstance().delHouseId(homeId); |
| | | initData();//初始化缓存数据 |
| | | houseInfoAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | nullDataUpdateUi();//检测数据是否为空 |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | hideLoading(); |
| | | |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| | |
| | | |
| | | void failing(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 没有电站列表的样式 |
| | | */ |
| | | private void nullDataUpdateUi(List<HouseIdBean> list) { |
| | | HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.nullDataIc.getRoot(), viewBinding.nullDataIc.nullDataGifAnimationIv, viewBinding.nullDataIc.nullDataTv, getString(R.string.my_power_station_data_null), list != null && list.size() > 0); |
| | | } |
| | | |
| | | |