From 23d38b1e7374c20698702b6ab3feb1e92e82c4d3 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 04 十二月 2024 19:22:17 +0800
Subject: [PATCH] 2024年12月04日19:22:16

---
 app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java |  163 +++++++++++++++++++++++-------------------------------
 1 files changed, 70 insertions(+), 93 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java
index 4206835..c62de4f 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java
@@ -4,8 +4,6 @@
 import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.TextView;
 
 import androidx.annotation.NonNull;
 import androidx.appcompat.content.res.AppCompatResources;
@@ -18,7 +16,6 @@
 import com.hdl.photovoltaic.R;
 import com.hdl.photovoltaic.bean.PageNumberObject;
 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;
@@ -94,7 +91,7 @@
     /**
      * 杩樺師鏉′欢鐨勫垵濮嬪寲鐘舵��
      */
-    private void InitializationState() {
+    private void initializationState() {
         key = SortValue.all;
         value = SortValue.all;
         installedCapacityMinValue = "";
@@ -130,7 +127,7 @@
                 }
                 isClickPowerStationLabel = true;
                 selectedTitleLabelStyle();
-                InitializationState();
+                initializationState();
                 getStatusOverview();
                 loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
 
@@ -149,38 +146,50 @@
             }
         });
         //鍏ㄩ儴
-        viewBinding.powerStationAllIl.parentLl.setOnClickListener(new View.OnClickListener() {
+        viewBinding.allLl.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 powerStationStatusValue = PowerStationStatus.All;
-                selectedStationStateStyle(viewBinding.powerStationAllIl.parentLl, viewBinding.powerStationAllIl.stationTotalTv, viewBinding.powerStationAllIl.stationTitleTv, true);
+                viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
+                viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+                viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+                viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                 loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
             }
         });
         //鏁呴殰
-        viewBinding.powerStationFaultsIl.parentLl.setOnClickListener(new View.OnClickListener() {
+        viewBinding.faultsLl.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 powerStationStatusValue = PowerStationStatus.malfunction;
-                selectedStationStateStyle(viewBinding.powerStationFaultsIl.parentLl, viewBinding.powerStationFaultsIl.stationTotalTv, viewBinding.powerStationFaultsIl.stationTitleTv, true);
+                viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+                viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
+                viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+                viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                 loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
             }
         });
         //绂荤嚎
-        viewBinding.powerStationOfflineIl.parentLl.setOnClickListener(new View.OnClickListener() {
+        viewBinding.offlineLl.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 powerStationStatusValue = PowerStationStatus.off;
-                selectedStationStateStyle(viewBinding.powerStationOfflineIl.parentLl, viewBinding.powerStationOfflineIl.stationTotalTv, viewBinding.powerStationOfflineIl.stationTitleTv, true);
+                viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+                viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+                viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
+                viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                 loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
             }
         });
         //寰呮帴鍏�
-        viewBinding.powerStationConnectedIl.parentLl.setOnClickListener(new View.OnClickListener() {
+        viewBinding.connectedLl.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 powerStationStatusValue = PowerStationStatus.connecting;
-                selectedStationStateStyle(viewBinding.powerStationConnectedIl.parentLl, viewBinding.powerStationConnectedIl.stationTotalTv, viewBinding.powerStationConnectedIl.stationTitleTv, true);
+                viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+                viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+                viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+                viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
                 loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
             }
         });
@@ -260,7 +269,7 @@
             public void onClick(int position, HouseIdBean houseIdBean) {
                 //鐐瑰嚮浣忓畢璇︽儏
                 HdlLogLogic.print("鐐瑰嚮浣忓畢璇︽儏---" + new Gson().toJson(houseIdBean), false);
-                HdlResidenceLogic.getInstance().switchHouse(houseIdBean);
+                HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true);
                 String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId() + "&homeName=" + houseIdBean.getHomeName() + "&powerStationStatus=" + houseIdBean.getPowerStationStatus();
                 HdlUniLogic.getInstance().openUniMP(path, null);
 
@@ -497,13 +506,10 @@
     private void initView() {
         viewBinding.powerStationLabelParent.setVisibility(View.VISIBLE);
         viewBinding.deviceLabelParent.setVisibility(View.GONE);
-
-        viewBinding.powerStationAllIl.stationTitleTv.setText(getString(R.string.message_all));
-        viewBinding.powerStationFaultsIl.stationTitleTv.setText(getString(R.string.my_power_station_malfunction));
-        viewBinding.powerStationOfflineIl.stationTitleTv.setText(getString(R.string.my_power_station_off_line));
-        viewBinding.powerStationConnectedIl.stationTitleTv.setText(getString(R.string.to_be_added));
-
-        selectedStationStateStyle(viewBinding.powerStationAllIl.parentLl, viewBinding.powerStationAllIl.stationTotalTv, viewBinding.powerStationAllIl.stationTitleTv, true);
+        viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
+        viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+        viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
+        viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
         //鐢电珯鏍囩
         houseInfoAdapter = new HouseInfoAdapter(_mActivity);
         viewBinding.fragmentHouseSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity));
@@ -523,8 +529,8 @@
      */
     private void selectedTitleLabelStyle() {
         if (isClickPowerStationLabel) {
-            viewBinding.powerStationLabel.setTextAppearance(R.style.Text20Style);
-            viewBinding.deviceLabel.setTextAppearance(R.style.Text16Style);
+            viewBinding.powerStationLabel.setTextAppearance(R.style.Text18Style);
+            viewBinding.deviceLabel.setTextAppearance(R.style.Text14Style);
 //            viewBinding.editIv.setVisibility(View.VISIBLE);//缂栬緫鍥炬爣闅愯棌
             viewBinding.addIv.setVisibility(View.VISIBLE);//娣诲姞鍥炬爣闅愯棌
             viewBinding.powerStationLabelParent.setVisibility(View.VISIBLE);//鐢电珯鏍囩銆愮埗瀹瑰櫒銆戞樉绀�
@@ -533,8 +539,8 @@
                 viewBinding.deviceNullDataIc.getRoot().setVisibility(View.GONE);
             }
         } else {
-            viewBinding.deviceLabel.setTextAppearance(R.style.Text20Style);
-            viewBinding.powerStationLabel.setTextAppearance(R.style.Text16Style);
+            viewBinding.deviceLabel.setTextAppearance(R.style.Text18Style);
+            viewBinding.powerStationLabel.setTextAppearance(R.style.Text14Style);
 //            viewBinding.editIv.setVisibility(View.GONE);//缂栬緫鍥炬爣闅愯棌
             viewBinding.addIv.setVisibility(View.GONE);//娣诲姞鍥炬爣闅愯棌
             viewBinding.powerStationLabelParent.setVisibility(View.GONE);//鐢电珯鏍囩銆愮埗瀹瑰櫒銆戦殣钘�
@@ -546,40 +552,6 @@
 
     }
 
-    /**
-     * 鏄剧ず閫変腑鐘舵�佹牱寮�
-     *
-     * @param linearLayout         缁勪欢
-     * @param numberTv             缁勪欢
-     * @param titleTv              缁勪欢
-     * @param isShowSelectedStatus 鏄惁鏄剧ず鐘舵�佹牱寮�
-     */
-    private void selectedStationStateStyle(LinearLayout linearLayout, TextView numberTv, TextView titleTv, boolean isShowSelectedStatus) {
-        viewBinding.powerStationAllIl.parentLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
-        viewBinding.powerStationFaultsIl.parentLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
-        viewBinding.powerStationOfflineIl.parentLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
-        viewBinding.powerStationConnectedIl.parentLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
-
-        viewBinding.powerStationAllIl.stationTotalTv.setTextColor(getResources().getColor(R.color.text_E6000000, null));
-        viewBinding.powerStationAllIl.stationTitleTv.setTextColor(getResources().getColor(R.color.text_66000000, null));
-
-        viewBinding.powerStationFaultsIl.stationTotalTv.setTextColor(getResources().getColor(R.color.text_E6000000, null));
-        viewBinding.powerStationFaultsIl.stationTitleTv.setTextColor(getResources().getColor(R.color.text_66000000, null));
-
-        viewBinding.powerStationOfflineIl.stationTotalTv.setTextColor(getResources().getColor(R.color.text_E6000000, null));
-        viewBinding.powerStationOfflineIl.stationTitleTv.setTextColor(getResources().getColor(R.color.text_66000000, null));
-
-        viewBinding.powerStationConnectedIl.stationTotalTv.setTextColor(getResources().getColor(R.color.text_E6000000, null));
-        viewBinding.powerStationConnectedIl.stationTitleTv.setTextColor(getResources().getColor(R.color.text_66000000, null));
-
-
-        if (isShowSelectedStatus) {
-            linearLayout.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.selected_8_38c494));
-            numberTv.setTextColor(getResources().getColor(R.color.text_FFFFFFFF, null));
-            titleTv.setTextColor(getResources().getColor(R.color.text_FFFFFFFF, null));
-        }
-
-    }
 
     private void initData() {
         if (isClickPowerStationLabel) {
@@ -611,7 +583,7 @@
                     Gson gson = new Gson();
                     String json = eventBus.getData().toString();
                     HouseIdBean houseIdBean = gson.fromJson(json, HouseIdBean.class);
-                    HdlResidenceLogic.getInstance().switchHouse(houseIdBean);
+                    HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true);
 
                 }
             } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT.equals(eventBus.getType())) {
@@ -646,10 +618,10 @@
             EventBus.getDefault().removeStickyEvent(eventBus);
             //鏄湪锛堢數绔欙級妯″潡涓斿湪锛堢數绔欙級鏍囩椤垫墠杩涙潵杩欓噷
             if (HdlCommonLogic.lowerTagType == LowerTagType.power_station && isClickPowerStationLabel) {
-                //uin鍏抽棴浣忓畢璇︽儏鐣岄潰閫氱煡
-                if (MqttRecvClient.getInstance() != null) {
-                    MqttRecvClient.getInstance().removeAllTopic();
-                }
+//                //uin鍏抽棴浣忓畢璇︽儏鐣岄潰閫氱煡
+//                if (MqttRecvClient.getInstance() != null) {
+//                    MqttRecvClient.getInstance().removeAllTopic();
+//                }
                 loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
             }
         } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(eventBus.getType())) {
@@ -658,24 +630,28 @@
 //            if (!isClickPowerStationLabel) {
 //                return;
 //            }
+            //鍏堟竻绌鸿闃呬富棰�
+            if (MqttRecvClient.getInstance() != null) {
+                MqttRecvClient.getInstance().removeAllTopic();
+            }
+            String homeId = eventBus.getData().toString();
             //杩涘幓浣忓畢璇︽儏uni璇诲彇閫嗗彉鍣ㄥ垪琛ㄦ垚鍔熷悗閫氱煡
-            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).size(); i++) {
-                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()).get(i).getGatewayId();
+            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).size(); i++) {
+                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).get(i).getGatewayId();
                 //瀛楃涓叉槸鑷繁鎸夎鍒欐嫾鎺ョ殑,閲岄潰娉ㄥ唽涓婚鏃朵細瑙f瀽瀛楃涓�,鍙嬁getGatewayId()鍊�;
                 String topic = "/user/" + gatewayId + "/#";
                 //杩涘幓浣忓畢璇︽儏寮�濮嬭闃呬富棰�
                 MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topic);//璁㈤槄銆愰�嗗彉鍣ㄣ�戞秷鎭�
-
             }
-            String topicHome = "/user/" + UserConfigManage.getInstance().getHomeId() + "/#";
+            String topicHome = "/user/" + homeId + "/#";
             MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topicHome);//璁㈤槄銆愮數绔欍�戞秷鎭�
 
 
         } else if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) {
+            // 鍙栨秷绮樻�т簨浠�
+            EventBus.getDefault().removeStickyEvent(eventBus);
             //鎺ユ敹澶栭儴鐐瑰嚮浜嬩欢
             if (eventBus.getType().equals(HomepageTitleTabSwitch.powerstation.toString())) {
-                // 鍙栨秷绮樻�т簨浠�
-                EventBus.getDefault().removeStickyEvent(eventBus);
                 HdlLogLogic.print("姝e湪鐐瑰嚮銆愮數绔欍��");
 //                if (!isReadData) {
 //                    //1锛屼粠棣栭〉-鏁呴殰-杩涙潵-鐢电珯锛堜笉璇诲彇锛�
@@ -686,27 +662,28 @@
                 //2024骞�06鏈�24鏃�14:34:01 浜у搧缁忕悊瑕佹眰杩涘幓鐢电珯鍒楄〃閮借璇诲彇 涓旈粯璁よ繘鍘婚兘鏄粯璁ょ數绔欐爣绛�
                 isClickPowerStationLabel = true;
                 selectedTitleLabelStyle();
-                InitializationState();
+                initializationState();
                 getStatusOverview();
                 loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
-
-
-            } else if (eventBus.getType().equals(PowerStationStatus.All)) {
-                isClickPowerStationLabel = true;
-                selectedTitleLabelStyle();
-                viewBinding.powerStationAllIl.parentLl.performClick();
-            } else if (eventBus.getType().equals(PowerStationStatus.malfunction)) {
-                isClickPowerStationLabel = true;
-                selectedTitleLabelStyle();
-                viewBinding.powerStationFaultsIl.parentLl.performClick();
-            } else if (eventBus.getType().equals(PowerStationStatus.off)) {
-                isClickPowerStationLabel = true;
-                selectedTitleLabelStyle();
-                viewBinding.powerStationOfflineIl.parentLl.performClick();
-            } else if (eventBus.getType().equals(PowerStationStatus.connecting)) {
-                isClickPowerStationLabel = true;
-                selectedTitleLabelStyle();
-                viewBinding.powerStationConnectedIl.parentLl.performClick();
+            } else if (eventBus.getType().equals(ConstantManage.station_page)) {
+                //閫氳繃棣栭〉鐢电珯杩涙潵鐨�
+                if (eventBus.getData().equals(PowerStationStatus.All)) {
+                    isClickPowerStationLabel = true;
+                    selectedTitleLabelStyle();
+                    viewBinding.allLl.performClick();
+                } else if (eventBus.getData().equals(PowerStationStatus.malfunction)) {
+                    isClickPowerStationLabel = true;
+                    selectedTitleLabelStyle();
+                    viewBinding.faultsLl.performClick();
+                } else if (eventBus.getData().equals(PowerStationStatus.off)) {
+                    isClickPowerStationLabel = true;
+                    selectedTitleLabelStyle();
+                    viewBinding.offlineLl.performClick();
+                } else if (eventBus.getData().equals(PowerStationStatus.connecting)) {
+                    isClickPowerStationLabel = true;
+                    selectedTitleLabelStyle();
+                    viewBinding.connectedLl.performClick();
+                }
             } else if (eventBus.getType().equals(ConstantManage.station_edit)) {
                 //缂栬緫鍚庢洿鏂颁竴涓嬩綇瀹呭垪琛�
                 //loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
@@ -731,10 +708,10 @@
                 if (statusOverviewBean == null) {
                     return;
                 }
-                viewBinding.powerStationAllIl.stationTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getTotal()));
-                viewBinding.powerStationFaultsIl.stationTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getFault()));
-                viewBinding.powerStationOfflineIl.stationTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getOffline()));
-                viewBinding.powerStationConnectedIl.stationTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getConnecting()));
+                viewBinding.allTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getTotal()));
+                viewBinding.faultsTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getFault()));
+                viewBinding.offlineTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getOffline()));
+                viewBinding.connectedTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getConnecting()));
             }
 
             @Override

--
Gitblit v1.8.0