From 5d3efa4c93dde0cde474951e5310bb72ebbf4184 Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期三, 07 五月 2025 15:18:26 +0800 Subject: [PATCH] 2025年05月07日15:18:20 1.2.0 --- app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java | 401 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 331 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java b/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java index 7828cfc..af6c830 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/newC/PowerStationsListEdit.java @@ -1,37 +1,66 @@ package com.hdl.photovoltaic.ui.newC; +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 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.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.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 ActivityPowerStationsListBinding viewBinding; + private Handler handler; + private Runnable delayedRunnable; + private ActivityPowerStationsListBinding viewBinding;//鏄惁鍦ㄧ紪杈戠姸鎬� private HouseListAdapter houseListAdapter; private List<HouseIdBean> houseListBeanIDList; - private boolean is_edit = false; @Override public Object getContentView() { @@ -42,98 +71,143 @@ @Override public void onBindView(Bundle savedInstanceState) { + 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()); + setSelectState(); } private void initEvent() { //杩斿洖鎸夐挳 - viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.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.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.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.setNoOnclickListener(new HouseListAdapter.OnClickListener() { + houseListAdapter.setOnItemClickListener(new HouseListAdapter.OnItemClickListener() { @Override - public void onMoveClick(int position, HouseIdBean houseIdBean) { -// HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() { -// @Override -// public void onSuccess(Boolean obj) { - //绉诲姩鐢电珯浣嶇疆 - HdlResidenceLogic.getInstance().moveHouseId(houseIdBean.getHomeId()); - initData();//鍒濆鍖栫紦瀛樻暟鎹� - houseListAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃 - nullDataUpdateUi(houseListBeanIDList);//妫�娴嬫暟鎹槸鍚︿负绌� -// } -// -// @Override -// public void onFailure(HDLException e) { -// HdlThreadLogic.toast(_mActivity, e); -// } -// }); + 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) { + + // 鏈巿鏉� 濡傛灉搴旂敤绋嬪簭娌℃湁鎵�闇�鐨勬潈闄愶紝鍒欐樉绀鸿В閲婅鏄� + 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) { + PermissionExplanationDialog.getInstance().dismiss(); + if (value == PermissionUtils.STATUS_REFUSE_PERMANENT | value == PermissionUtils.STATUS_REFUSE) { +// HdlThreadLogic.toast(_mActivity, R.string.permission_open); + return; + } + + + startActivity(ScanActivity.class); + } + }, true); + + } + }); + } private void initView() { - viewBinding.toolbarTopFragmentHouseListRl.getRoot().setBackgroundColor(getColor(R.color.text_FFFFFFFF)); - viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.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); } /** @@ -142,6 +216,9 @@ * @param isRefreshing 琛ㄧず鏄笅鎷夊埛鏂扮殑 */ private void downReadData(boolean isRefreshing) { + if (isRefreshing) { + showLoading(); + } //鑾峰彇浣忓畢(鐢电珯)ID鍒楄〃 HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { @Override @@ -151,18 +228,24 @@ 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); } @@ -177,8 +260,10 @@ public void run() { if (isRefreshing) { //鍏抽棴涓嬫媺鍒锋柊鐨勫湀鍦� - viewBinding.fragmentHouseSrl.setRefreshing(false); + hideLoading(); } + + HdlThreadLogic.toast(_mActivity, e.getMsg() + "(" + e.getCode() + ")"); } }, _mActivity, ShowErrorMode.YES); @@ -187,13 +272,13 @@ } /** - * 璁剧疆鍏ㄩ儴缂撳瓨鏁版嵁缂栬緫鐘舵�� - * - * @param edit true琛ㄧず鍦ㄧ紪杈戠姸鎬� + * 璁剧疆褰撳墠鐢电珯閫変腑鐘舵�� */ - private void setAllItemEdit(boolean edit) { + private void setSelectState() { for (int i = 0; i < houseListBeanIDList.size(); i++) { - houseListBeanIDList.get(i).setEdit(edit); + if (UserConfigManage.getInstance().getHomeId().equals(houseListBeanIDList.get(i).getHomeId())) { + this.houseListBeanIDList.get(i).setState_select(true); + } } } @@ -203,4 +288,180 @@ 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); + } + }); + + } + } else if (ConstantManage.REFRESH_HOME_LIST.equals(eventBus.getTopic())) { + if (houseListAdapter != null) { + initData(); + setSelectState(); + //鏇存柊UI + houseListAdapter.setList(houseListBeanIDList); + } + } + } + + + /** + * 姣旇緝浣忓畢鍒楄〃鏁版嵁鏄惁閮戒竴鏍� + * + * @param oldList 鏃у垪琛� + * @param newList 鏂板垪琛� + * @return 鐩稿悓杩斿洖true锛屽惁鍒欒繑鍥瀎alse + */ + 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鏇存柊鏁版嵁 + * 锛堝湪骞冲彴涓婂垹闄绔綋鍓嶄綇瀹呭悗,鑾峰彇鍒楄〃瀹炴敹瑕侀�氱煡uni閭h竟鏇存柊鐣岄潰鍗$墖锛� + */ + 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(); + } } \ No newline at end of file -- Gitblit v1.8.0