| | |
| | | |
| | | |
| | | 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() { |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setNotificationBarBackgroundColor(CustomColor.white); |
| | | setStatusBarTextColor(); |
| | | setStatusBarTranslucent(); |
| | | getWindow().setNavigationBarColor(getColor(R.color.text_FF000000)); |
| | | //初始化数据 |
| | | initData(); |
| | | //初始化 |
| | |
| | | private void initData() { |
| | | this.houseListBeanIDList = new ArrayList<>(); |
| | | this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList()); |
| | | setAllItemEdit(false); |
| | | setSelectState(); |
| | | } |
| | | |
| | | private void initEvent() { |
| | | //返回按钮 |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setOnClickListener(new View.OnClickListener() { |
| | | 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.toolbarTopFragmentHouseListRl.topMoreBtn.setVisibility(View.VISIBLE); |
| | | initData();//初始化缓存数据 |
| | | setAllItemEdit(false); |
| | | houseListAdapter.setList(houseListBeanIDList);//重新刷新列表 |
| | | finish(); |
| | | } |
| | | }); |
| | | //编辑按钮 |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreBtn.setOnClickListener(new View.OnClickListener() { |
| | | 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.toolbarTopFragmentHouseListRl.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() { |
| | |
| | | } |
| | | |
| | | private void initView() { |
| | | viewBinding.toolbarTopFragmentHouseListRl.getRoot().setBackgroundColor(getColor(R.color.text_FFFFFFFF)); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackLl.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topLeftIv.setImageResource(R.drawable.back_c); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.power_station_selection); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreBtn.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setImageResource(R.drawable.editor_house); |
| | | viewBinding.toolbarTopRl.topBackLl.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopRl.topTitleTv.setText(R.string.power_station_selection); |
| | | viewBinding.toolbarTopRl.topMoreBtn.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopRl.topMoreIv.setImageResource(R.drawable.editor_house); |
| | | LinearLayoutManager linearLayout = new LinearLayoutManager(_mActivity); |
| | | houseListAdapter = new HouseListAdapter(_mActivity); |
| | | viewBinding.fragmentHouseSrlListRc.setLayoutManager(linearLayout); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | dialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | HdlResidenceLogic.getInstance().switchHouse(houseIdBean); |
| | | HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true); |
| | | dialog.dismiss(); |
| | | JsonObject jsonObject = new JsonObject(); |
| | | jsonObject.addProperty("homeId", houseIdBean.getHomeId()); |
| | |
| | | dialog.dismiss(); |
| | | } |
| | | }); |
| | | |
| | | dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
| | | @Override |
| | | public void onDismiss(DialogInterface dialog) { |
| | | //取消之后还原之前状态 |
| | | for (int i = 0; i < houseListBeanIDList.size(); i++) { |
| | | HouseIdBean houseIdBean = houseListBeanIDList.get(i); |
| | | houseIdBean.setState_select(false); |
| | | if (UserConfigManage.getInstance().getHomeId().equals(houseIdBean.getHomeId())) { |
| | | houseIdBean.setState_select(true); |
| | | } |
| | | } |
| | | houseListAdapter.notifyDataSetChanged(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | |
| | | }); |
| | | |
| | | } |
| | | } else if (ConstantManage.REFRESH_HOME_LIST.equals(eventBus.getTopic())) { |
| | | if (houseListAdapter != null) { |
| | | initData(); |
| | | setSelectState(); |
| | | //更新UI |
| | | houseListAdapter.setList(houseListBeanIDList); |
| | | } |
| | | } |
| | | } |
| | | |