From f9956641e92cce3ece4cdff523a6e453f159d268 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 21 十二月 2023 11:58:30 +0800 Subject: [PATCH] 2023年12月21日11:58:13 --- app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java | 86 ++++++++++++++++++++++++++++++++++-------- 1 files changed, 69 insertions(+), 17 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 bd3064f..5d5a91a 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,36 +2,47 @@ 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; 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.bean.BaseEventBus; +import com.hdl.photovoltaic.config.AppConfigManage; 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.ShowErrorMode; import com.hdl.photovoltaic.listener.CloudCallBeak; +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.adapter.HouseInfoAdapter; import com.hdl.photovoltaic.ui.bean.HouseIdBean; +import com.hdl.photovoltaic.ui.bean.HouseInfoBean; +import com.hdl.photovoltaic.ui.device.FastScanActivity; import com.hdl.photovoltaic.uni.HDLUniMP; import com.hdl.photovoltaic.utils.PermissionUtils; +import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; +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";//鍙戠數鍔熺巼鎺掑簭 @@ -58,7 +69,6 @@ @Override public void onBindView(Bundle savedInstanceState) { manager = (CameraManager) _mActivity.getSystemService(Context.CAMERA_SERVICE); - initData(); //鍒濆鍖� initView(); @@ -70,16 +80,19 @@ 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() { - // 鎵撳紑灏忕▼搴忛〉闈� + +// Intent intent = new Intent(); +// intent.setClass(_mActivity, FastScanActivity.class); +// startActivity(intent); +// // 鎵撳紑灏忕▼搴忛〉闈� HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null); } @@ -96,27 +109,32 @@ @Override public void onRefresh() { updateUIData(true); - Log.d("HouseListFragment", "涓嬫媺鍒锋柊"); + HdlLogLogic.print("HouseListFragment涓嬫媺鍒锋柊", false); } }); houseInfoAdapter.setNoOnclickListener(new HouseInfoAdapter.OnclickListener() { @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), false); + HdlResidenceLogic.getInstance().switchHouse(houseIdBean); + String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + + "?homeId=" + houseIdBean.getHomeId() + + "&homeName=" + houseIdBean.getHomeName() + + "&powerStationStatus=" + houseIdBean.getPowerStationStatus() + + "&serverAddress=" + AppConfigManage.getUserRegionUrl(); HdlUniLogic.getInstance().openUniMP(path, null); + } }); } private void initView() { - viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.my_power_station_鎴戠殑鐢电珯); + viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.my_power_station); 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(this.houseListBeanIDList, _mActivity); viewBinding.fragmentHouseSrlListRc.setLayoutManager(linearLayout); viewBinding.fragmentHouseSrlListRc.setAdapter(houseInfoAdapter); @@ -133,12 +151,43 @@ this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList()); } + /** + * 鏀跺埌EventBUs閫氱煡 + * + * @param eventBus 鏁版嵁 + */ @Override public void onEventMessage(BaseEventBus eventBus) { super.onEventMessage(eventBus); - //鏀跺埌EventBUs閫氱煡 - if (ConstantManage.EVENTBUS_POST_HOME_CREATED.equals(eventBus.getType())) { + 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(""); + } + } else if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) { + //鎺ユ敹澶栭儴鐐瑰嚮浜嬩欢 + if (eventBus.getType().equals(HdlCommonLogic.HomepageTitleTabSwitch.powerstation.toString())) { + HdlLogLogic.print("姝e湪鐐瑰嚮銆愮數绔欍��"); + } } } @@ -167,6 +216,7 @@ houseInfoAdapter.setList(list); houseInfoAdapter.notifyDataSetChanged(); } + } } }, _mActivity, ShowErrorMode.YES); @@ -174,7 +224,7 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { HdlThreadLogic.runMainThread(new Runnable() { @Override public void run() { @@ -196,9 +246,10 @@ mPermissionsResultCallback = permissionsResultCallback; - //Manifest.permission.CAMERA, + String[] s = new String[]{ Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.CAMERA, }; String[] ary = PermissionUtils.checkPermission(_mActivity, s); if (ary.length > 0) { @@ -226,6 +277,7 @@ } + private PermissionsResultCallback mPermissionsResultCallback; public interface PermissionsResultCallback { -- Gitblit v1.8.0