From c13cb54d0b9f9b2c73f213b6cdb163f462fd64c7 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期五, 13 十月 2023 18:17:59 +0800
Subject: [PATCH] 2023年10月13日18:17:52
---
app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java | 108 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 98 insertions(+), 10 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 b0e9e75..4308d08 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
@@ -12,10 +12,15 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+import com.google.gson.Gson;
+import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.R;
-import com.hdl.photovoltaic.config.UserConfigManage;
+import com.hdl.photovoltaic.bean.BaseEventBus;
import com.hdl.photovoltaic.databinding.FragmentHouseListBinding;
import com.hdl.photovoltaic.base.CustomBaseFragment;
+import com.hdl.photovoltaic.enums.ShowErrorMode;
+import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.other.HdlDeviceLogic;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlResidenceLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
@@ -24,10 +29,14 @@
import com.hdl.photovoltaic.ui.bean.HouseIdBean;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.utils.PermissionUtils;
+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";//鍙戠數鍔熺巼鎺掑簭
@@ -54,7 +63,6 @@
@Override
public void onBindView(Bundle savedInstanceState) {
manager = (CameraManager) _mActivity.getSystemService(Context.CAMERA_SERVICE);
-
initData();
//鍒濆鍖�
initView();
@@ -91,8 +99,7 @@
viewBinding.fragmentHouseSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
-
- viewBinding.fragmentHouseSrl.setRefreshing(false);
+ updateUIData(true);
Log.d("HouseListFragment", "涓嬫媺鍒锋柊");
}
});
@@ -100,9 +107,9 @@
@Override
public void onClick(int position, HouseIdBean houseIdBean) {
//鐐瑰嚮浣忓畢璇︽儏
- HdlLogLogic.print("====鐐瑰嚮浣忓畢璇︽儏" + position);
- HdlResidenceLogic.getInstance().switchHouse(houseIdBean.getHomeId());
- String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId();
+ HdlLogLogic.print("鐐瑰嚮浣忓畢璇︽儏===" + new Gson().toJson(houseIdBean));
+ HdlResidenceLogic.getInstance().switchHouse(houseIdBean);
+ String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId()+"&homeName="+houseIdBean.getHomeName();
HdlUniLogic.getInstance().openUniMP(path, null);
}
});
@@ -128,19 +135,100 @@
// this.houseListBeanList.add(houseListBean);
// }
this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList());
-
-
}
+ /**
+ * 鏀跺埌EventBUs閫氱煡
+ *
+ * @param eventBus 鏁版嵁
+ */
+ @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);
+ }
+ } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE.equals(eventBus.getType())) {
+ //uin鍏抽棴浣忓畢璇︽儏鐣岄潰閫氱煡
+ if (MqttRecvClient.getInstance() != null) {
+ MqttRecvClient.getInstance().removeAllTopic();
+ }
+ } 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();
+ //瀛楃涓叉槸鑷繁鎸夎鍒欐嫾鎺ョ殑,閲岄潰娉ㄥ唽涓婚鏃朵細瑙f瀽瀛楃涓�,鍙嬁getGatewayId()鍊�;
+ //String topic = "/user/" + gatewayId+"/1";
+ //杩涘幓浣忓畢璇︽儏寮�濮嬭闃呬富棰�
+ MqttRecvClient.getInstance().checkAndsubscribeAllTopics("");
+ }
+ }
+ }
+
+ /**
+ * 鍒锋柊UI
+ *
+ * @param isRefreshing 琛ㄧず鏄笅鎷夊埛鏂扮殑
+ */
+ private void updateUIData(boolean isRefreshing) {
+ //鑾峰彇浣忓畢(鐢电珯)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) {
+ //鍏抽棴涓嬫媺鍒锋柊鐨勫湀鍦�
+ viewBinding.fragmentHouseSrl.setRefreshing(false);
+ }
+ if (list != null && list.size() > 0) {
+ //鏇存柊缂撳瓨
+ HdlResidenceLogic.getInstance().setHouseIdList(list);
+ if (houseInfoAdapter != null) {
+ //鏇存柊UI
+ houseInfoAdapter.setList(list);
+ houseInfoAdapter.notifyDataSetChanged();
+ }
+
+ }
+ }
+ }, _mActivity, ShowErrorMode.YES);
+
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ HdlThreadLogic.runMainThread(new Runnable() {
+ @Override
+ public void run() {
+ if (isRefreshing) {
+ //鍏抽棴涓嬫媺鍒锋柊鐨勫湀鍦�
+ viewBinding.fragmentHouseSrl.setRefreshing(false);
+ }
+
+ }
+ }, _mActivity, ShowErrorMode.YES);
+ }
+ });
+ }
/**
* 鐢宠鏉冮檺
*/
private void requestPermissions(PermissionsResultCallback permissionsResultCallback) {
+
+
mPermissionsResultCallback = permissionsResultCallback;
//Manifest.permission.CAMERA,
String[] s = new String[]{
- Manifest.permission.ACCESS_FINE_LOCATION
+ Manifest.permission.ACCESS_FINE_LOCATION,
};
String[] ary = PermissionUtils.checkPermission(_mActivity, s);
if (ary.length > 0) {
--
Gitblit v1.8.0