| | |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.ActivityHouseListEditBinding; |
| | | import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch; |
| | | import com.hdl.photovoltaic.enums.MessageStateType; |
| | | import com.hdl.photovoltaic.enums.ShowErrorMode; |
| | | 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.ui.bean.CloudInverterDeviceBean; |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | | import com.hdl.photovoltaic.ui.newC.adapter.HouseListAdapter; |
| | | 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 org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | private ActivityHouseListEditBinding viewBinding; |
| | | |
| | | private HouseListAdapter houseListAdapter; |
| | | private List<HouseIdBean> houseListBeanIDList; |
| | | private List<HouseIdBean> houseListBeanIDList = new ArrayList<>(); |
| | | |
| | | |
| | | @Override |
| | |
| | | initView(); |
| | | //初始化界面监听器 |
| | | initEvent(); |
| | | if (this.houseListBeanIDList.size() == 0) { |
| | | downReadData(false); |
| | | } |
| | | } |
| | | |
| | | private void initData() { |
| | | this.houseListBeanIDList = new ArrayList<>(); |
| | | this.houseListBeanIDList.clear(); |
| | | this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList()); |
| | | for (int i = 0; i < this.houseListBeanIDList.size(); i++) { |
| | | this.houseListBeanIDList.get(i).setDelIcon(true); |
| | | this.houseListBeanIDList.get(i).setMove(true); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onBackPressed() { |
| | | super.onBackPressed(); |
| | | sendEventBus(); |
| | | } |
| | | |
| | | private void sendEventBus() { |
| | | HdlCommonLogic.getInstance().postEventBus(ConstantManage.homepage_title_tab_switch, ConstantManage.station_edit); |
| | | finish(); |
| | | } |
| | | |
| | | private void initEvent() { |
| | | //返回按钮 |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setOnClickListener(new View.OnClickListener() { |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | BaseEventBus baseEventBus = new BaseEventBus(); |
| | | baseEventBus.setTopic(ConstantManage.homepage_title_tab_switch); |
| | | baseEventBus.setType(HomepageTitleTabSwitch.powerstation.toString()); |
| | | EventBus.getDefault().post(baseEventBus); |
| | | finish(); |
| | | sendEventBus(); |
| | | } |
| | | }); |
| | | |
| | |
| | | houseListAdapter.setMoveOnclickListener(new HouseListAdapter.OnMoveClickListener() { |
| | | @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 |
| | |
| | | } |
| | | }); |
| | | |
| | | //电站移动位置按钮 |
| | | //电站删除位置按钮 |
| | | houseListAdapter.setDelOnclickListener(new HouseListAdapter.OnDelClickListener() { |
| | | @Override |
| | | public void onDelClick(int position, HouseIdBean houseIdBean) { |
| | |
| | | String homeName = "\"" + houseIdBean.getHomeName() + "\""; |
| | | 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();//初始化缓存数据 |
| | | houseListAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空 |
| | | delayedConfirmationCancelDialog.dismiss(); |
| | | public void onSuccess(List<GatewayBean> list) { |
| | | deleteResidence(houseIdBean.getHomeId()); |
| | | initializeInverter(list); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | deleteResidence(houseIdBean.getHomeId()); |
| | | } |
| | | }); |
| | | // //删除住宅 |
| | | // HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() { |
| | | // @Override |
| | | // public void onSuccess(Boolean obj) { |
| | | // HdlResidenceLogic.getInstance().delHouseId(houseIdBean.getHomeId()); |
| | | // initData();//初始化缓存数据 |
| | | // houseListAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | // nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空 |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onFailure(HDLException e) { |
| | | // HdlThreadLogic.toast(_mActivity, e); |
| | | // } |
| | | // }); |
| | | } |
| | | }); |
| | | delayedConfirmationCancelDialog.setNoOnclickListener(new DelayedConfirmationCancelDialog.onNoOnclickListener() { |
| | |
| | | |
| | | private void initView() { |
| | | viewBinding.toolbarTopFragmentHouseListRl.getRoot().setBackgroundColor(getColor(R.color.text_FFFFFFFF)); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topLeftIv.setImageResource(R.drawable.back_c); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.power_station_editing); |
| | | LinearLayoutManager linearLayout = new LinearLayoutManager(_mActivity); |
| | |
| | | this.nullDataUpdateUi(houseListBeanIDList); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除电站,逆变器 |
| | | * (开始删除电站,同时,向逆变器发送初始化逆变器指令,无须处理结果) |
| | | * |
| | | * @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().initializeInverter(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 |
| | | */ |
| | | private void deleteResidence(String homeId) { |
| | | //删除住宅 |
| | | HdlResidenceLogic.getInstance().delResidence(homeId, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | hideLoading(); |
| | | HdlResidenceLogic.getInstance().delHouseId(homeId); |
| | | initData();//初始化缓存数据 |
| | | houseListAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空 |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | hideLoading(); |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 刷新UI |
| | | * |
| | | * @param isRefreshing 表示是下拉刷新的 |
| | | */ |
| | | private void downReadData(boolean isRefreshing) { |
| | | if (!isRefreshing) { |
| | | showLoading(); |
| | | } |
| | | //获取住宅(电站)ID列表 |
| | | HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { |
| | | @Override |
| | |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | } else { |
| | | hideLoading(); |
| | | } |
| | | if (list != null && list.size() > 0) { |
| | | //更新缓存 |
| | |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | } else { |
| | | hideLoading(); |
| | | } |
| | | |
| | | |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 没有电站列表的样式 |
| | | */ |