File was renamed from app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java |
| | |
| | | import android.content.DialogInterface; |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.os.SystemClock; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | import android.os.Handler; |
| | | import android.os.Looper; |
| | | 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.linkpm.sdk.user.HDLLinkPMUser; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | |
| | | import com.hdl.photovoltaic.enums.ShowErrorMode; |
| | | import com.hdl.photovoltaic.internet.HttpClient; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.listener.LinkCallBack; |
| | | import com.hdl.photovoltaic.other.HdlCommonLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | import com.hdl.photovoltaic.other.HdlResidenceLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.other.HdlUniLogic; |
| | |
| | | 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.photovoltaic.widget.DelayedConfirmationCancelDialog; |
| | | import com.hdl.photovoltaic.widget.PermissionExplanationDialog; |
| | | import com.hdl.photovoltaic.widget.refreshlayout.BGARefreshLayout; |
| | | import com.hdl.photovoltaic.widget.refreshlayout.HDLRefreshViewHolder; |
| | | 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.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | |
| | | /** |
| | | * C端电站列表编辑 |
| | | */ |
| | | public class PowerStationsListEdit extends CustomBaseActivity { |
| | | public class PowerStationsListActivity extends CustomBaseActivity { |
| | | private Handler handler; |
| | | private Runnable delayedRunnable; |
| | | private ActivityPowerStationsListBinding viewBinding;//是否在编辑状态 |
| | | |
| | | private HouseListAdapter houseListAdapter; |
| | |
| | | } |
| | | }); |
| | | |
| | | //设置下拉箭头颜色 |
| | | viewBinding.fragmentHouseSrl.setColorSchemeResources(R.color.text_FF245EC3); |
| | | //列表下拉按钮 |
| | | viewBinding.fragmentHouseSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | downReadData(true); |
| | | } |
| | | }); |
| | | if (houseListAdapter != null) { |
| | | //选中电站事件 |
| | | houseListAdapter.setOnItemClickListener(new HouseListAdapter.OnItemClickListener() { |
| | | @Override |
| | | public void onItemClick(int position, HouseIdBean houseBean) { |
| | |
| | | return; |
| | | } |
| | | houseSelectionDialog(houseBean); |
| | | } |
| | | }); |
| | | //删除电站事件 |
| | | houseListAdapter.setDelOnclickListener(new HouseListAdapter.OnDelClickListener() { |
| | | @Override |
| | | public void onDelClick(int position, HouseIdBean houseIdBean) { |
| | | if (houseIdBean.isOtherShare()) { |
| | | //分享过来的电站不能删除 |
| | | HdlThreadLogic.toast(_mActivity, getString(R.string.no_permission_delete_home)); |
| | | return; |
| | | } |
| | | |
| | | DelayedConfirmationCancelDialog delayedConfirmationCancelDialog = new DelayedConfirmationCancelDialog(_mActivity); |
| | | delayedConfirmationCancelDialog.show(); |
| | | delayedConfirmationCancelDialog.isHideTitle(true); |
| | | String del_home = getString(R.string.confirm_deletion) + "\"" + houseIdBean.getHomeName() + "\"" + "?"; |
| | | delayedConfirmationCancelDialog.setContent(del_home); |
| | | |
| | | // delayedConfirmationCancelDialog.startCountdown(4); |
| | | delayedConfirmationCancelDialog.setYesOnclickListener(new DelayedConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | delayedConfirmationCancelDialog.dismiss(); |
| | | showLoading(getString(R.string.deleting_please_wait)); |
| | | HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(houseIdBean.getHomeId(), new CloudCallBeak<List<GatewayBean>>() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> list) { |
| | | //发起删除电站指令 |
| | | deleteResidence(houseIdBean.getHomeId(), list); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //发起删除电站指令 |
| | | deleteResidence(houseIdBean.getHomeId(), null); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); |
| | | delayedConfirmationCancelDialog.setNoOnclickListener(new DelayedConfirmationCancelDialog.onNoOnclickListener() { |
| | | @Override |
| | | public void Cancel() { |
| | | delayedConfirmationCancelDialog.dismiss(); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | |
| | | viewBinding.fragmentHouseSrlListRc.setAdapter(houseListAdapter); |
| | | houseListAdapter.setList(this.houseListBeanIDList); |
| | | this.nullDataUpdateUi(houseListBeanIDList); |
| | | pullToRefresh(); |
| | | } |
| | | |
| | | /** |
| | | * 下拉刷新的逻辑 |
| | | */ |
| | | protected void pullToRefresh() { |
| | | viewBinding.fragmentHouseSrl.setDelegate(new BGARefreshLayout.BGARefreshLayoutDelegate() { |
| | | @Override |
| | | public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) { |
| | | handler = new Handler(Looper.getMainLooper()); |
| | | |
| | | delayedRunnable = new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | viewBinding.fragmentHouseSrl.endRefreshing(); |
| | | downReadData(false); |
| | | } |
| | | }; |
| | | // 延迟 5 秒执行 |
| | | handler.postDelayed(delayedRunnable, 1000); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public boolean onBGARefreshLayoutBeginLoadingMore(BGARefreshLayout refreshLayout) { |
| | | |
| | | handler = new Handler(Looper.getMainLooper()); |
| | | delayedRunnable = new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | viewBinding.fragmentHouseSrl.endLoadingMore(); |
| | | |
| | | } |
| | | }; |
| | | // 延迟 5 秒执行 |
| | | handler.postDelayed(delayedRunnable, 10); |
| | | |
| | | return true; |
| | | } |
| | | }); |
| | | HDLRefreshViewHolder hdlRefreshViewHolder = new HDLRefreshViewHolder(_mActivity, true); |
| | | hdlRefreshViewHolder.setPullDownImageResource(R.mipmap.loading_44); |
| | | hdlRefreshViewHolder.setChangeToReleaseRefreshAnimResId(R.drawable.loading_refresh); |
| | | hdlRefreshViewHolder.setRefreshingAnimResId(R.drawable.loading_refresh_end); |
| | | viewBinding.fragmentHouseSrl.setRefreshViewHolder(hdlRefreshViewHolder); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param isRefreshing 表示是下拉刷新的 |
| | | */ |
| | | private void downReadData(boolean isRefreshing) { |
| | | if (isRefreshing) { |
| | | showLoading(); |
| | | } |
| | | //获取住宅(电站)ID列表 |
| | | HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { |
| | | @Override |
| | |
| | | public void run() { |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | hideLoading(); |
| | | } |
| | | if (list != null && !list.isEmpty()) { |
| | | if (!comparableList(houseListBeanIDList, list)) { |
| | |
| | | public void run() { |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | hideLoading(); |
| | | } |
| | | |
| | | HdlThreadLogic.toast(_mActivity, e.getMsg() + "(" + e.getCode() + ")"); |
| | |
| | | houseListAdapter.notifyDataSetChanged(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 删除电站 |
| | | * |
| | | * @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); //发起初始化指令给逆变器;(注意:前面已先解绑云端逆变器,mqtt通道已断开,初始化只能是本地发送(先搜索局域网逆变器列表,建立本地通讯通道)) |
| | | HdlResidenceLogic.getInstance().delHouseId(homeId);//删除电站缓存 |
| | | initData();//初始化缓存数据 |
| | | refreshDetails(); |
| | | //更新电站选中状态 |
| | | setSelectState(); |
| | | houseListAdapter.setList(houseListBeanIDList); //更新列表数据 |
| | | nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空 |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | hideLoading(); |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 删除电站,逆变器 |
| | | * (开始删除电站,同时,向逆变器发送初始化逆变器指令,无须处理结果) |
| | | * |
| | | * @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); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | if (handler != null && delayedRunnable != null) { |
| | | handler.removeCallbacks(delayedRunnable); |
| | | } |
| | | super.onDestroy(); |
| | | } |
| | | } |