From 788c70114287306db20e9a4539018d6e32fb5cb7 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期五, 19 四月 2024 10:10:10 +0800
Subject: [PATCH] Merge branch 'wjc_new' into develop_new
---
app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java | 303 ++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 245 insertions(+), 58 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java
index 4308d08..5c94e11 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java
@@ -2,10 +2,10 @@
import android.Manifest;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.camera2.CameraManager;
import android.os.Bundle;
-import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
@@ -15,38 +15,39 @@
import com.google.gson.Gson;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.R;
-import com.hdl.photovoltaic.bean.BaseEventBus;
+import com.hdl.photovoltaic.config.ConstantManage;
+import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.databinding.FragmentHouseListBinding;
import com.hdl.photovoltaic.base.CustomBaseFragment;
+import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch;
import com.hdl.photovoltaic.enums.ShowErrorMode;
import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.listener.LinkCallBack;
+import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.other.HdlDeviceLogic;
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.MyPowerStationActivity;
import com.hdl.photovoltaic.ui.adapter.HouseInfoAdapter;
+import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
import com.hdl.photovoltaic.ui.bean.HouseIdBean;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.utils.PermissionUtils;
+import com.hdl.photovoltaic.widget.DelayedConfirmationCancelDialog;
+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 com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient;
import java.util.ArrayList;
import java.util.List;
/**
- * 鐢电珯鍒楄〃鐣岄潰
+ * (浣忓畢)鐢电珯鍒楄〃-鐣岄潰
*/
public class HouseListFragment extends CustomBaseFragment {
-
- public static final String SORT_TYPE_1 = "powerSort";//鍙戠數鍔熺巼鎺掑簭
- public static final String SORT_TYPE_2 = "todayElectricitySort";//浠婃棩鍙戠數閲忔帓搴�
- public static final String SORT_TYPE_3 = "createTimeSort";//鍒涘缓鏃堕棿鎺掑簭
- public static final String DESCENDING = "descending";//闄嶅簭
- public static final String ASCENDING = "ascending";//鍗囧簭
- public static final String SELECTED_SORT_TYPE = SORT_TYPE_1;
- public static final String SELECTED_SORT = DESCENDING;
-
private FragmentHouseListBinding viewBinding;
private HouseInfoAdapter houseInfoAdapter;
private CameraManager manager;
@@ -68,29 +69,16 @@
initView();
//鍒濆鍖栫晫闈㈢洃鍚櫒
initEvent();
-
-
}
private void initEvent() {
+
+ //娣诲姞鐢电珯
viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
-
- // 鎵撳紑灏忕▼搴忛〉闈�
-// HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null);
- requestPermissions(new PermissionsResultCallback() {
- @Override
- public void succeed() {
- // 鎵撳紑灏忕▼搴忛〉闈�
- HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null);
- }
-
- @Override
- public void failing() {
- }
- });
+ HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null);
}
});
@@ -99,41 +87,133 @@
viewBinding.fragmentHouseSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
- updateUIData(true);
- Log.d("HouseListFragment", "涓嬫媺鍒锋柊");
+ downReadData(true);
}
});
+ //杩涘叆鐢电珯璇︽儏,鍒犻櫎鐢电珯,绉诲姩鐢电珯浣嶇疆
houseInfoAdapter.setNoOnclickListener(new HouseInfoAdapter.OnclickListener() {
@Override
public void onClick(int position, HouseIdBean houseIdBean) {
//鐐瑰嚮浣忓畢璇︽儏
- HdlLogLogic.print("鐐瑰嚮浣忓畢璇︽儏===" + new Gson().toJson(houseIdBean));
+ HdlLogLogic.print("鐐瑰嚮浣忓畢璇︽儏--->" + new Gson().toJson(houseIdBean), false);
HdlResidenceLogic.getInstance().switchHouse(houseIdBean);
- String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId()+"&homeName="+houseIdBean.getHomeName();
+ String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId() + "&homeName=" + houseIdBean.getHomeName() + "&powerStationStatus=" + houseIdBean.getPowerStationStatus();
HdlUniLogic.getInstance().openUniMP(path, null);
+
+ }
+
+ @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();//鍒濆鍖栫紦瀛樻暟鎹�
+ houseInfoAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
+ nullDataUpdateUi(houseListBeanIDList);//妫�娴嬫暟鎹槸鍚︿负绌�
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ HdlThreadLogic.toast(_mActivity, e);
+ }
+ });
+
+
+ }
+
+ @Override
+ public void onDelClick(int position, HouseIdBean houseIdBean) {
+
+ DelayedConfirmationCancelDialog delayedConfirmationCancelDialog = new DelayedConfirmationCancelDialog(_mActivity);
+ delayedConfirmationCancelDialog.setTitleContent(getString(R.string.loading_title_tip));
+ String homeName = "\"" + houseIdBean.getHomeName() + "\"";
+ delayedConfirmationCancelDialog.setContent(getString(R.string.delete_power_station).replace("%s", homeName));
+ delayedConfirmationCancelDialog.show();
+ 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);
+ }
+ });
+
+// //鍒犻櫎浣忓畢
+// HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() {
+// @Override
+// public void onSuccess(Boolean obj) {
+// HdlResidenceLogic.getInstance().delHouseId(houseIdBean.getHomeId());
+// initData();//鍒濆鍖栫紦瀛樻暟鎹�
+// houseInfoAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
+// nullDataUpdateUi(houseListBeanIDList);//妫�娴嬫暟鎹槸鍚︿负绌�
+// }
+//
+// @Override
+// public void onFailure(HDLException e) {
+// HdlThreadLogic.toast(_mActivity, e);
+// }
+// });
+ }
+ });
+ delayedConfirmationCancelDialog.setNoOnclickListener(new DelayedConfirmationCancelDialog.onNoOnclickListener() {
+ @Override
+ public void Cancel() {
+ delayedConfirmationCancelDialog.dismiss();
+ }
+ });
+
+ }
+ });
+
+ //缂栬緫鐢电珯鎸夐挳
+ viewBinding.toolbarTopFragmentHouseListRl.topEditIv.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startActivity(HouseListEditActivity.class);
}
});
}
private void initView() {
- viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.my_power_station_鎴戠殑鐢电珯);
+ viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.my_power_station);
+ viewBinding.toolbarTopFragmentHouseListRl.topEditIv.setVisibility(View.VISIBLE);
+ viewBinding.toolbarTopFragmentHouseListRl.topEditIv.setImageResource(R.drawable.editor_house);
viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setVisibility(View.VISIBLE);
viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setImageResource(R.drawable.add);
LinearLayoutManager linearLayout = new LinearLayoutManager(_mActivity);
- houseInfoAdapter = new HouseInfoAdapter(this.houseListBeanIDList);
+ houseInfoAdapter = new HouseInfoAdapter(_mActivity);
viewBinding.fragmentHouseSrlListRc.setLayoutManager(linearLayout);
viewBinding.fragmentHouseSrlListRc.setAdapter(houseInfoAdapter);
+ houseInfoAdapter.setList(this.houseListBeanIDList);
+ this.nullDataUpdateUi(houseListBeanIDList);
}
private void initData() {
this.houseListBeanIDList = new ArrayList<>();
-// for (int i = 0; i < 11; i++) {
-// HouseListBean houseListBean = new HouseListBean();
-// houseListBean.setHomeName("鐢电珯" + i);
-// this.houseListBeanList.add(houseListBean);
-// }
this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList());
}
@@ -145,38 +225,76 @@
@Override
public void onEventMessage(BaseEventBus eventBus) {
super.onEventMessage(eventBus);
- if (HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION.equals(eventBus.getType())) {
- //uin鍒涘缓鐢电珯鎴愬姛鍚庨�氱煡
- updateUIData(false);
- if (eventBus.getData() != null) {
- Gson gson = new Gson();
- String json = eventBus.getData().toString();
- HouseIdBean houseIdBean = gson.fromJson(json, HouseIdBean.class);
- HdlResidenceLogic.getInstance().switchHouse(houseIdBean);
+ if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(eventBus.getTopic())) {
+ if (HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION.equals(eventBus.getType())) {
+ //uin鍒涘缓鐢电珯鎴愬姛鍚庨�氱煡
+ downReadData(false);
+ if (eventBus.getData() != null) {
+ Gson gson = new Gson();
+ String json = eventBus.getData().toString();
+ HouseIdBean houseIdBean = gson.fromJson(json, HouseIdBean.class);
+ HdlResidenceLogic.getInstance().switchHouse(houseIdBean);
+
+ }
+ } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT.equals(eventBus.getType())) {
+ //todo 鐜板湪榛樿鍒锋柊鍏ㄩ儴
+ //uin缂栬緫浣忓畢閫氱煡
+// String homeId = HdlUniLogic.getInstance().getKeyValue("homeId", eventBus.getData());
+// String home_name = HdlUniLogic.getInstance().getKeyValue("powerStationName", eventBus.getData());
+// if (TextUtils.isEmpty(homeId) || TextUtils.isEmpty(home_name)) {
+// return;
+// }
+// int index = -1;
+// for (int i = 0; i < houseListBeanIDList.size(); i++) {
+// HouseIdBean houseIdBean = houseListBeanIDList.get(i);
+// if (houseIdBean.getHomeId().equals(homeId)) {
+// index = i;
+// houseIdBean.setHomeName(home_name);
+// break;
+// }
+// }
+// if (index > -1) {
+// if (houseInfoAdapter != null) {
+// //鏇存柊鍗曚釜鏁版嵁
+// houseInfoAdapter.notifyItemChanged(index);
+// }
+// }
+
+
}
} else if (HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE.equals(eventBus.getType())) {
//uin鍏抽棴浣忓畢璇︽儏鐣岄潰閫氱煡
if (MqttRecvClient.getInstance() != null) {
MqttRecvClient.getInstance().removeAllTopic();
}
+ downReadData(false);
+
} else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(eventBus.getType())) {
//杩涘幓浣忓畢璇︽儏uni璇诲彇閫嗗彉鍣ㄥ垪琛ㄦ垚鍔熷悗閫氱煡
- for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList().size(); i++) {
- //String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList().get(i).getGatewayId();
+ for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).size(); i++) {
+ String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).get(i).getGatewayId();
//瀛楃涓叉槸鑷繁鎸夎鍒欐嫾鎺ョ殑,閲岄潰娉ㄥ唽涓婚鏃朵細瑙f瀽瀛楃涓�,鍙嬁getGatewayId()鍊�;
- //String topic = "/user/" + gatewayId+"/1";
+ String topic = "/user/" + gatewayId + "/#";
//杩涘幓浣忓畢璇︽儏寮�濮嬭闃呬富棰�
- MqttRecvClient.getInstance().checkAndsubscribeAllTopics("");
+ MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topic);
+ }
+ } else if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) {
+ //鎺ユ敹澶栭儴鐐瑰嚮浜嬩欢
+ if (eventBus.getType().equals(HomepageTitleTabSwitch.powerstation.toString())) {
+ HdlLogLogic.print("姝e湪鐐瑰嚮銆愮數绔欍��");
+ initData();//鍒濆鍖栫紦瀛樻暟鎹�
+ houseInfoAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
}
}
}
+
/**
* 鍒锋柊UI
*
* @param isRefreshing 琛ㄧず鏄笅鎷夊埛鏂扮殑
*/
- private void updateUIData(boolean isRefreshing) {
+ private void downReadData(boolean isRefreshing) {
//鑾峰彇浣忓畢(鐢电珯)ID鍒楄〃
HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() {
@Override
@@ -192,12 +310,13 @@
//鏇存柊缂撳瓨
HdlResidenceLogic.getInstance().setHouseIdList(list);
if (houseInfoAdapter != null) {
+ initData();
//鏇存柊UI
- houseInfoAdapter.setList(list);
- houseInfoAdapter.notifyDataSetChanged();
+ houseInfoAdapter.setList(houseListBeanIDList);
}
}
+ nullDataUpdateUi(list);
}
}, _mActivity, ShowErrorMode.YES);
@@ -219,6 +338,7 @@
});
}
+
/**
* 鐢宠鏉冮檺
*/
@@ -226,10 +346,8 @@
mPermissionsResultCallback = permissionsResultCallback;
- //Manifest.permission.CAMERA,
- String[] s = new String[]{
- Manifest.permission.ACCESS_FINE_LOCATION,
- };
+
+ String[] s = new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CAMERA,};
String[] ary = PermissionUtils.checkPermission(_mActivity, s);
if (ary.length > 0) {
requestPermissions(ary, PermissionUtils.STATUS_SUCCESS);
@@ -249,12 +367,17 @@
if (mPermissionsResultCallback != null) {
mPermissionsResultCallback.succeed();
}
+ } else {
+ if (mPermissionsResultCallback != null) {
+ mPermissionsResultCallback.failing();
+ }
}
}
}
}
+
private PermissionsResultCallback mPermissionsResultCallback;
@@ -266,4 +389,68 @@
}
+ /**
+ * 娌℃湁鐢电珯鍒楄〃鐨勬牱寮�
+ */
+ 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 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().initializeGateway(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);
+ }
+ });
+ }
+ }
+
+ /**
+ * 鍒犻櫎鐢电珯
+ *
+ * @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);
+ HdlResidenceLogic.getInstance().delHouseId(homeId);
+ initData();//鍒濆鍖栫紦瀛樻暟鎹�
+ houseInfoAdapter.setList(houseListBeanIDList);//閲嶆柊鍒锋柊鍒楄〃
+ nullDataUpdateUi(houseListBeanIDList);//妫�娴嬫暟鎹槸鍚︿负绌�
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ hideLoading();
+
+ HdlThreadLogic.toast(_mActivity, e);
+ }
+ });
+ }
+
+
}
--
Gitblit v1.8.0