| | |
| | | |
| | | |
| | | import android.Manifest; |
| | | import android.content.DialogInterface; |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Looper; |
| | | import android.os.SystemClock; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | |
| | | |
| | | 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.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.HdlLogLogic; |
| | | 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.FastScanActivity; |
| | | 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.PermissionExplanationDialog; |
| | | import com.hdl.photovoltaic.widget.refreshlayout.BGARefreshLayout; |
| | | import com.hdl.photovoltaic.widget.refreshlayout.HDLRefreshViewHolder; |
| | | 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.Collections; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * C端电站列表编辑 |
| | | */ |
| | | public class PowerStationsListEdit extends CustomBaseActivity { |
| | | private Handler handler; |
| | | private Runnable delayedRunnable; |
| | | private ActivityPowerStationsListBinding viewBinding;//是否在编辑状态 |
| | | |
| | | 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(); |
| | | //初始化 |
| | | initView(); |
| | | //初始化界面监听器 |
| | | initEvent(); |
| | | //后台读取住宅列表 |
| | | // downReadData(false); |
| | | } |
| | | |
| | | 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.addPowerStationTv.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.addPowerStationTv.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); |
| | | } |
| | | }); |
| | | |
| | | //设置下拉箭头颜色 |
| | | 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) { |
| | |
| | | houseSelectionDialog(houseBean); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | viewBinding.addPowerStationTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | |
| | | // 未授权 如果应用程序没有所需的权限,则显示解释说明 |
| | | PermissionExplanationDialog.getInstance().showPortConflictPdDialog(_mActivity, getString(R.string.camera_storage_instructions), getString(R.string.camera_storage_purpose)); |
| | | PermissionUtils.requestPermissionsResultCallback(_mActivity, Manifest.permission.CAMERA, new PermissionUtils.PermissionState() { |
| | | @Override |
| | | public void Success(int value) { |
| | | if (value == PermissionUtils.STATUS_REFUSE_PERMANENT) { |
| | | PermissionExplanationDialog.getInstance().dismiss(); |
| | | if (value == PermissionUtils.STATUS_REFUSE_PERMANENT | value == PermissionUtils.STATUS_REFUSE) { |
| | | // HdlThreadLogic.toast(_mActivity, R.string.permission_open); |
| | | return; |
| | | } |
| | | startActivity(FastScanActivity.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.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); |
| | | 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.size() > 0) { |
| | | //更新缓存 |
| | | HdlResidenceLogic.getInstance().setHouseIdList(list); |
| | | if (houseListAdapter != null) { |
| | | initData(); |
| | | setAllItemEdit(is_edit); |
| | | //更新UI |
| | | houseListAdapter.setList(houseListBeanIDList); |
| | | } |
| | | if (list != null && !list.isEmpty()) { |
| | | if (!comparableList(houseListBeanIDList, list)) { |
| | | //更新缓存 |
| | | HdlResidenceLogic.getInstance().setHouseIdList(list, true); |
| | | if (houseListAdapter != null) { |
| | | //重新获取列表数据 |
| | | initData(); |
| | | refreshDetails(); |
| | | //更新电站选中状态 |
| | | setSelectState(); |
| | | //更新列表数据 |
| | | houseListAdapter.setList(houseListBeanIDList); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | nullDataUpdateUi(list); |
| | | } |
| | |
| | | public void run() { |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | hideLoading(); |
| | | } |
| | | |
| | | HdlThreadLogic.toast(_mActivity, e.getMsg() + "(" + e.getCode() + ")"); |
| | | |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置全部缓存数据编辑状态 |
| | | * |
| | | * @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.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); |
| | | 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(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } else if (ConstantManage.REFRESH_HOME_LIST.equals(eventBus.getTopic())) { |
| | | if (houseListAdapter != null) { |
| | | initData(); |
| | | setSelectState(); |
| | | //更新UI |
| | | houseListAdapter.setList(houseListBeanIDList); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 比较住宅列表数据是否都一样 |
| | | * |
| | | * @param oldList 旧列表 |
| | | * @param newList 新列表 |
| | | * @return 相同返回true,否则返回false |
| | | */ |
| | | boolean comparableList(List<HouseIdBean> oldList, List<HouseIdBean> newList) { |
| | | if (oldList == null || newList == null) return false; |
| | | if (oldList.size() != newList.size()) return false; |
| | | List<String> oidStrList = new ArrayList<>(); |
| | | for (int i = 0; i < oldList.size(); i++) { |
| | | oidStrList.add(oldList.get(i).getHomeId()); |
| | | } |
| | | |
| | | List<String> newStrList = new ArrayList<>(); |
| | | for (int i = 0; i < newList.size(); i++) { |
| | | newStrList.add(newList.get(i).getHomeId()); |
| | | } |
| | | Collections.sort(oidStrList); |
| | | Collections.sort(newStrList); |
| | | return oidStrList.equals(newStrList); |
| | | } |
| | | |
| | | /** |
| | | * 通知uni更新数据 |
| | | * (在平台上删除C端当前住宅后,获取列表实收要通知uni那边更新界面卡片) |
| | | */ |
| | | private void refreshDetails() { |
| | | try { |
| | | List<HouseIdBean> localHouseIdList = HdlResidenceLogic.getInstance().getHouseIdList(); |
| | | if (localHouseIdList.isEmpty()) { |
| | | JsonObject jsonObject = new JsonObject(); |
| | | jsonObject.addProperty("homeId", ""); |
| | | 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); |
| | | } else { |
| | | int select_home = -1; |
| | | for (int i = 0; i < localHouseIdList.size(); i++) { |
| | | if (localHouseIdList.get(i).getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | select_home = i; |
| | | break; |
| | | } |
| | | } |
| | | if (select_home == -1) { |
| | | //找不到默认第一个 |
| | | HouseIdBean houseIdBean = localHouseIdList.get(0); |
| | | HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true); |
| | | 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); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | if (handler != null && delayedRunnable != null) { |
| | | handler.removeCallbacks(delayedRunnable); |
| | | } |
| | | super.onDestroy(); |
| | | } |
| | | } |