package com.hdl.photovoltaic.ui.newC;
|
|
|
import android.Manifest;
|
import android.content.DialogInterface;
|
import android.os.Bundle;
|
import android.view.View;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
import com.google.gson.JsonObject;
|
import com.hdl.linkpm.sdk.core.exception.HDLException;
|
import com.hdl.photovoltaic.R;
|
import com.hdl.photovoltaic.base.CustomBaseActivity;
|
import com.hdl.photovoltaic.config.UserConfigManage;
|
import com.hdl.photovoltaic.databinding.ActivityPowerStationsListBinding;
|
import com.hdl.photovoltaic.enums.ShowErrorMode;
|
import com.hdl.photovoltaic.internet.HttpClient;
|
import com.hdl.photovoltaic.listener.CloudCallBeak;
|
import com.hdl.photovoltaic.other.HdlCommonLogic;
|
import com.hdl.photovoltaic.other.HdlResidenceLogic;
|
import com.hdl.photovoltaic.other.HdlThreadLogic;
|
import com.hdl.photovoltaic.other.HdlUniLogic;
|
import com.hdl.photovoltaic.ui.bean.HouseIdBean;
|
import com.hdl.photovoltaic.ui.device.ScanActivity;
|
import com.hdl.photovoltaic.ui.newC.adapter.HouseListAdapter;
|
import com.hdl.photovoltaic.uni.HDLUniMP;
|
import com.hdl.photovoltaic.utils.LocalManageUtil;
|
import com.hdl.photovoltaic.utils.PermissionUtils;
|
import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
|
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
|
|
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.ThreadMode;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* C端电站列表编辑
|
*/
|
public class PowerStationsListEdit extends CustomBaseActivity {
|
private ActivityPowerStationsListBinding viewBinding;//是否在编辑状态
|
|
private HouseListAdapter houseListAdapter;
|
private List<HouseIdBean> houseListBeanIDList;
|
|
private boolean is_edit = false;//表示是否在编辑状态(true=在编辑状态)
|
|
@Override
|
public Object getContentView() {
|
viewBinding = ActivityPowerStationsListBinding.inflate(getLayoutInflater());
|
return viewBinding.getRoot();
|
}
|
|
|
@Override
|
public void onBindView(Bundle savedInstanceState) {
|
setStatusBarTranslucent();
|
getWindow().setNavigationBarColor(getColor(R.color.text_FF333738));
|
//初始化数据
|
initData();
|
//初始化
|
initView();
|
//初始化界面监听器
|
initEvent();
|
}
|
|
private void initData() {
|
this.houseListBeanIDList = new ArrayList<>();
|
this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList());
|
setAllItemEdit(false);
|
}
|
|
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);//重新刷新列表
|
}
|
});
|
//编辑按钮
|
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);//重新刷新列表
|
}
|
});
|
|
//设置下拉箭头颜色
|
viewBinding.fragmentHouseSrl.setColorSchemeResources(R.color.text_FF245EC3);
|
//列表下拉按钮
|
viewBinding.fragmentHouseSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
@Override
|
public void onRefresh() {
|
downReadData(true);
|
}
|
});
|
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) {
|
for (int i = 0; i < houseListBeanIDList.size(); i++) {
|
HouseIdBean houseIdBean = houseListBeanIDList.get(i);
|
houseIdBean.setState_select(false);
|
}
|
houseListBeanIDList.get(position).setState_select(true);
|
houseListAdapter.notifyDataSetChanged();
|
if (UserConfigManage.getInstance().getHomeId().equals(houseBean.getHomeId())) {
|
//同一个不执行弹窗
|
return;
|
}
|
houseSelectionDialog(houseBean);
|
}
|
});
|
|
|
}
|
|
viewBinding.addPowerStationTv.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
PermissionUtils.requestPermissionsResultCallback(_mActivity, Manifest.permission.CAMERA, new PermissionUtils.PermissionState() {
|
@Override
|
public void Success(int value) {
|
if (value == PermissionUtils.STATUS_REFUSE_PERMANENT) {
|
// HdlThreadLogic.toast(_mActivity, R.string.permission_open);
|
return;
|
}
|
|
|
// startActivity(CaptureActivity.class);
|
startActivity(ScanActivity.class);
|
}
|
}, true);
|
// String path = HDLUniMP.UNI_EVENT_OPEN_DEVICESCAN + "?scanType=addPowerStation";
|
// HdlUniLogic.getInstance().openUniMP(path, null);
|
// startActivity(FastScanActivity.class);
|
|
}
|
});
|
|
}
|
|
private void initView() {
|
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);
|
viewBinding.fragmentHouseSrlListRc.setAdapter(houseListAdapter);
|
houseListAdapter.setList(this.houseListBeanIDList);
|
this.nullDataUpdateUi(houseListBeanIDList);
|
}
|
|
/**
|
* 刷新UI
|
*
|
* @param isRefreshing 表示是下拉刷新的
|
*/
|
private void downReadData(boolean isRefreshing) {
|
//获取住宅(电站)ID列表
|
HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() {
|
@Override
|
public void onSuccess(List<HouseIdBean> list) {
|
HdlThreadLogic.runMainThread(new Runnable() {
|
@Override
|
public void run() {
|
if (isRefreshing) {
|
//关闭下拉刷新的圈圈
|
viewBinding.fragmentHouseSrl.setRefreshing(false);
|
}
|
if (list != null && list.size() > 0) {
|
//更新缓存
|
HdlResidenceLogic.getInstance().setHouseIdList(list);
|
if (houseListAdapter != null) {
|
initData();
|
setAllItemEdit(is_edit);
|
//更新UI
|
houseListAdapter.setList(houseListBeanIDList);
|
}
|
|
}
|
nullDataUpdateUi(list);
|
}
|
}, _mActivity, ShowErrorMode.YES);
|
|
}
|
|
@Override
|
public void onFailure(HDLException e) {
|
HdlThreadLogic.runMainThread(new Runnable() {
|
@Override
|
public void run() {
|
if (isRefreshing) {
|
//关闭下拉刷新的圈圈
|
viewBinding.fragmentHouseSrl.setRefreshing(false);
|
}
|
|
}
|
}, _mActivity, ShowErrorMode.YES);
|
}
|
});
|
}
|
|
/**
|
* 设置全部缓存数据编辑状态
|
*
|
* @param edit true表示在编辑状态
|
*/
|
private void setAllItemEdit(boolean edit) {
|
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);
|
}
|
}
|
}
|
|
/**
|
* 没有电站列表的样式
|
*/
|
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);
|
}
|
|
|
/**
|
* 二次确认提示框
|
*
|
* @param houseIdBean 选中数据
|
*/
|
private void houseSelectionDialog(HouseIdBean houseIdBean) {
|
ConfirmationCancelDialog dialog = new ConfirmationCancelDialog(this);
|
dialog.setTitle(getString(R.string.loading_title_tip));
|
dialog.setContent(getString(R.string.switch_power_station).replace("%s", "\"" + houseIdBean.getHomeName() + "\""));
|
dialog.show();
|
dialog.isHideTitle(true);
|
dialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() {
|
@Override
|
public void Confirm() {
|
HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true);
|
dialog.dismiss();
|
JsonObject jsonObject = new JsonObject();
|
jsonObject.addProperty("homeId", houseIdBean.getHomeId());
|
jsonObject.addProperty("homeName", houseIdBean.getHomeName());
|
jsonObject.addProperty("powerStationStatus", houseIdBean.getPowerStationStatus() + "");
|
HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
|
uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_DETAILS);
|
uniCallBackBaseBean.setData(jsonObject);
|
HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
|
finish();
|
// //todo 逻辑: 这里可以指定关闭小程序详情,然后再重新打开详情界面;
|
// String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS_C
|
// + "?homeId=" + houseIdBean.getHomeId()
|
// + "&homeName=" + houseIdBean.getHomeName()
|
// + "&powerStationStatus=" + houseIdBean.getPowerStationStatus();
|
// HdlUniLogic.getInstance().openUniMP(path, null);
|
|
}
|
});
|
dialog.setNoOnclickListener(new ConfirmationCancelDialog.onNoOnclickListener() {
|
@Override
|
public void Cancel() {
|
//取消之后还原之前状态
|
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();
|
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();
|
}
|
});
|
}
|
|
|
/**
|
* 收到EventBUs通知
|
*
|
* @param eventBus 数据
|
*/
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
public void onEventMessage(BaseEventBus eventBus) {
|
super.onEventMessage(eventBus);
|
if (HDLUniMP.UNI_EVENT_REPLY_HOME_ADD.equals(eventBus.getTopic())) {
|
if (HDLUniMP.UNI_EVENT_REPLY_HOME_ADD.equals(eventBus.getType())) {
|
// // 取消粘性事件
|
// EventBus.getDefault().removeStickyEvent(eventBus);
|
HttpClient.getInstance().requestHttpGet(eventBus.getData().toString(), new CloudCallBeak<String>() {
|
@Override
|
public void onSuccess(String obj) {
|
downReadData(true);
|
}
|
|
@Override
|
public void onFailure(HDLException e) {
|
HdlThreadLogic.toast(_mActivity, e);
|
}
|
});
|
|
}
|
}
|
}
|
|
}
|