| | |
| | | |
| | | import android.Manifest; |
| | | import android.content.DialogInterface; |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.view.View; |
| | | |
| | |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.ActivityPowerStationsListBinding; |
| | | import com.hdl.photovoltaic.enums.ShowErrorMode; |
| | |
| | | private HouseListAdapter houseListAdapter; |
| | | private List<HouseIdBean> houseListBeanIDList; |
| | | |
| | | private boolean is_edit = false;//表示是否在编辑状态(true=在编辑状态) |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | |
| | | private void initData() { |
| | | this.houseListBeanIDList = new ArrayList<>(); |
| | | this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList()); |
| | | setAllItemEdit(false); |
| | | setSelectState(); |
| | | } |
| | | |
| | | private void initEvent() { |
| | |
| | | viewBinding.toolbarTopRl.topBackLl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (!is_edit) { |
| | | finish(); |
| | | return; |
| | | } |
| | | |
| | | is_edit = false; |
| | | viewBinding.addPowerStationRl.setVisibility(View.VISIBLE);//添加电站组件 |
| | | viewBinding.toolbarTopRl.topMoreBtn.setVisibility(View.VISIBLE); |
| | | initData();//初始化缓存数据 |
| | | setAllItemEdit(false); |
| | | houseListAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | finish(); |
| | | } |
| | | }); |
| | | //编辑按钮 |
| | | viewBinding.toolbarTopRl.topMoreBtn.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (is_edit) { |
| | | return; |
| | | } |
| | | |
| | | is_edit = true; |
| | | viewBinding.addPowerStationRl.setVisibility(View.GONE);//添加电站组件 |
| | | viewBinding.toolbarTopRl.topMoreBtn.setVisibility(View.GONE); |
| | | initData();//初始化缓存数据 |
| | | setAllItemEdit(true); |
| | | houseListAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | Intent intent = new Intent(); |
| | | intent.setClass(_mActivity, PowerStationsMoveActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | |
| | |
| | | } |
| | | }); |
| | | if (houseListAdapter != null) { |
| | | //电站移动位置按钮 |
| | | 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 > 1) { |
| | | frontHomeId = houseListBeanIDList.get(position - 2).getHomeId(); |
| | | } |
| | | HdlResidenceLogic.getInstance().moveResidence(houseIdBean.getHomeId(), frontHomeId, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | //移动电站位置 |
| | | HdlResidenceLogic.getInstance().moveHouseId(houseIdBean.getHomeId()); |
| | | initData();//初始化缓存数据 |
| | | setAllItemEdit(is_edit); |
| | | houseListAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空 |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); |
| | | houseListAdapter.setOnItemClickListener(new HouseListAdapter.OnItemClickListener() { |
| | | @Override |
| | | public void onItemClick(int position, HouseIdBean houseBean) { |
| | |
| | | houseSelectionDialog(houseBean); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | viewBinding.addPowerStationTv.setOnClickListener(new View.OnClickListener() { |
| | |
| | | HdlResidenceLogic.getInstance().setHouseIdList(list); |
| | | if (houseListAdapter != null) { |
| | | initData(); |
| | | setAllItemEdit(is_edit); |
| | | setSelectState(); |
| | | //更新UI |
| | | houseListAdapter.setList(houseListBeanIDList); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置全部缓存数据编辑状态 |
| | | * |
| | | * @param edit true表示在编辑状态 |
| | | * 设置当前电站选中状态 |
| | | */ |
| | | private void setAllItemEdit(boolean edit) { |
| | | private void setSelectState() { |
| | | for (int i = 0; i < houseListBeanIDList.size(); i++) { |
| | | houseListBeanIDList.get(i).setMove(edit); |
| | | houseListBeanIDList.get(i).setDelIcon(false); |
| | | if (UserConfigManage.getInstance().getHomeId().equals(houseListBeanIDList.get(i).getHomeId())) { |
| | | this.houseListBeanIDList.get(i).setState_select(!edit); |
| | | this.houseListBeanIDList.get(i).setState_select(true); |
| | | } |
| | | } |
| | | } |
| | |
| | | }); |
| | | |
| | | } |
| | | } else if (ConstantManage.REFRESH_HOME_LIST.equals(eventBus.getTopic())) { |
| | | if (houseListAdapter != null) { |
| | | initData(); |
| | | setSelectState(); |
| | | //更新UI |
| | | houseListAdapter.setList(houseListBeanIDList); |
| | | } |
| | | } |
| | | } |
| | | |