package com.hdl.photovoltaic.ui.newC;
|
|
|
import android.os.Bundle;
|
import android.os.Handler;
|
import android.os.Looper;
|
import android.view.View;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
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.databinding.ActivityPowerStationsMoveBinding;
|
import com.hdl.photovoltaic.enums.ShowErrorMode;
|
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.ui.bean.HouseIdBean;
|
import com.hdl.photovoltaic.ui.newC.adapter.HouseMoveAdapter;
|
import com.hdl.photovoltaic.widget.refreshlayout.BGARefreshLayout;
|
import com.hdl.photovoltaic.widget.refreshlayout.HDLRefreshViewHolder;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* C端电站列表移动位置
|
*/
|
public class PowerStationsMoveActivity extends CustomBaseActivity {
|
private Handler handler;
|
private Runnable delayedRunnable;
|
private ActivityPowerStationsMoveBinding viewBinding;//是否在编辑状态
|
|
private HouseMoveAdapter houseMoveAdapter;
|
private List<HouseIdBean> houseListBeanIDList;
|
|
@Override
|
public Object getContentView() {
|
viewBinding = ActivityPowerStationsMoveBinding.inflate(getLayoutInflater());
|
return viewBinding.getRoot();
|
}
|
|
|
@Override
|
public void onBindView(Bundle savedInstanceState) {
|
setStatusBarTranslucent();
|
getWindow().setNavigationBarColor(getColor(R.color.text_FF000000));
|
//初始化数据
|
initData();
|
//初始化
|
initView();
|
//初始化界面监听器
|
initEvent();
|
}
|
|
private void initData() {
|
this.houseListBeanIDList = new ArrayList<>();
|
this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList());
|
}
|
|
/**
|
* 下拉刷新的逻辑
|
*/
|
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();
|
HdlResidenceLogic.getInstance().clearHouseList();
|
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);
|
}
|
|
private void initEvent() {
|
//返回按钮
|
viewBinding.toolbarTopRl.topBackLl.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
finish();
|
}
|
});
|
|
if (houseMoveAdapter != null) {
|
//电站移动位置按钮
|
houseMoveAdapter.setMoveOnclickListener(new HouseMoveAdapter.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();//初始化缓存数据
|
houseMoveAdapter.setList(houseListBeanIDList);//重新刷新列表
|
nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空
|
//通知外面更新位置
|
HdlCommonLogic.getInstance().postEventBus(ConstantManage.REFRESH_HOME_LIST, ConstantManage.REFRESH_HOME_LIST);
|
|
}
|
|
@Override
|
public void onFailure(HDLException e) {
|
HdlThreadLogic.toast(_mActivity, e);
|
}
|
});
|
|
}
|
});
|
}
|
|
|
}
|
|
private void initView() {
|
viewBinding.toolbarTopRl.topBackLl.setVisibility(View.VISIBLE);
|
viewBinding.toolbarTopRl.topTitleTv.setText(R.string.power_station_selection);
|
LinearLayoutManager linearLayout = new LinearLayoutManager(_mActivity);
|
houseMoveAdapter = new HouseMoveAdapter(_mActivity);
|
viewBinding.fragmentHouseSrlListRc.setLayoutManager(linearLayout);
|
viewBinding.fragmentHouseSrlListRc.setAdapter(houseMoveAdapter);
|
houseMoveAdapter.setList(this.houseListBeanIDList);
|
this.nullDataUpdateUi(houseListBeanIDList);
|
pullToRefresh();
|
}
|
|
/**
|
* 刷新UI
|
*
|
* @param isRefreshing 表示是下拉刷新的
|
*/
|
private void downReadData(boolean isRefreshing) {
|
if (isRefreshing) {
|
//关闭下拉刷新的圈圈
|
showLoading();
|
}
|
//获取住宅(电站)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) {
|
//关闭下拉刷新的圈圈
|
hideLoading();
|
}
|
if (list != null && list.size() > 0) {
|
//更新缓存
|
HdlResidenceLogic.getInstance().setHouseIdList(list);
|
if (houseMoveAdapter != null) {
|
initData();
|
//更新UI
|
houseMoveAdapter.setList(houseListBeanIDList);
|
}
|
|
}
|
nullDataUpdateUi(list);
|
}
|
}, _mActivity, ShowErrorMode.YES);
|
|
}
|
|
@Override
|
public void onFailure(HDLException e) {
|
HdlThreadLogic.runMainThread(new Runnable() {
|
@Override
|
public void run() {
|
if (isRefreshing) {
|
//关闭下拉刷新的圈圈
|
hideLoading();
|
}
|
HdlThreadLogic.toast(_mActivity, e.getMsg() + "(" + e.getCode() + ")");
|
|
}
|
}, _mActivity, ShowErrorMode.YES);
|
}
|
});
|
}
|
|
/**
|
* 没有电站列表的样式
|
*/
|
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);
|
}
|
|
@Override
|
protected void onDestroy() {
|
if (handler != null && delayedRunnable != null) {
|
handler.removeCallbacks(delayedRunnable);
|
}
|
super.onDestroy();
|
}
|
|
|
}
|