From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 09:07:13 +0800
Subject: [PATCH] 新云端Ver1.3

---
 ZigbeeApp/Shared/Phone/MainPage/HomeMainPageForm.cs |  356 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 186 insertions(+), 170 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/MainPage/HomeMainPageForm.cs b/ZigbeeApp/Shared/Phone/MainPage/HomeMainPageForm.cs
index cfbcfbf..726e76a 100755
--- a/ZigbeeApp/Shared/Phone/MainPage/HomeMainPageForm.cs
+++ b/ZigbeeApp/Shared/Phone/MainPage/HomeMainPageForm.cs
@@ -16,6 +16,10 @@
         #region 鈻� 鍙橀噺澹版槑___________________________
 
         /// <summary>
+        /// The instance.
+        /// </summary>
+        public static HomeMainPageForm Instance;
+        /// <summary>
         /// 鏁翠釜鐣岄潰鐨勪笂涓嬫粦鍔ㄦ帶浠�
         /// </summary>
         private VerticalFrameControl listBodyContr = null;
@@ -49,8 +53,11 @@
         /// </summary>
         public void ShowForm()
         {
+            this.FormID = "HomeMainPageForm";
+            Instance = this;
+            
             //鍏堝垵濮嬪寲宸︽粦鎴块棿鍒楄〃鐣岄潰(鍦ㄥ弽灏勯噷闈㈠垵濮嬪寲)
-            if (ListRoomViewFrom.Instance == null) { }
+            if (LeftListRoomViewFrom.Instance == null) { }
 
             //鏁翠釜鑳屾櫙鐨勪笂涓嬫粦鍔ㄦ帶浠�
             if (this.listBodyContr == null)
@@ -75,8 +82,8 @@
             this.AddNormalDeviceReportEvent();
             //娣诲姞浼犳劅鍣ㄧ姸鎬佷笂鎶ヤ簨浠�
             this.AddSensorDeviceReportEvent();
-            //灏嗗綋鍓嶇殑鐢婚潰淇濆瓨鍒板唴瀛樺綋涓�
-            UserCenterLogic.AddActionForm(this);
+            //寮�鍚紶鎰熷櫒鐘舵�佽繕鍘熺殑绾跨▼
+            this.StartRecoverSenorStatuThread();
         }
 
         /// <summary>
@@ -85,7 +92,7 @@
         private void InitTopFrameLayoutControl()
         {
             //澶撮儴瀹瑰櫒
-            base.topFrameLayout = new FrameLayout();
+            base.topFrameLayout = new NormalFrameLayout();
             topFrameLayout.Y = Application.GetRealHeight(60);
             topFrameLayout.Height = Application.GetRealHeight(127);
             topFrameLayout.BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor;
@@ -93,7 +100,7 @@
 
             //妤煎眰鍥炬爣
             var btnFloorIcon = new IconViewControl(69);
-            btnFloorIcon.X = ControlCommonResourse.XXLeft;
+            btnFloorIcon.X = HdlControlResourse.XXLeft;
             btnFloorIcon.Gravity = Gravity.CenterVertical;
             btnFloorIcon.UnSelectedImagePath = "Item/Floor.png";
             topFrameLayout.AddChidren(btnFloorIcon);
@@ -124,8 +131,11 @@
                     this.ShowSelectFloorForm(btnFloorName);
                 };
             }
+
+            //鍙瀵硅蹇嵎鏂瑰紡
+            Shared.Phone.Device.VideoIntercom.VideoMachine.AccountSupportVideo(topFrameLayout);
             //瀹夐槻蹇嵎鏂瑰紡
-            if (UserCenterResourse.ResidenceOption.SafetyShortcut)
+            if (HdlUserCenterResourse.ResidenceOption.SafetyShortcut)
             {
                 var btnSafety = new Controls.SafetyShortcutControl();
                 btnSafety.X = Application.GetRealWidth(860);
@@ -142,13 +152,13 @@
 
             //浣忓畢鍚嶅瓧
             var btnHouseName = new NormalViewControl(700, 95, true);
-            btnHouseName.X = ControlCommonResourse.XXLeft;
+            btnHouseName.X = HdlControlResourse.XXLeft;
             btnHouseName.Y = Application.GetRealHeight(161);
             btnHouseName.TextSize = 24;
             btnHouseName.TextColor = ZigbeeColor.Current.GXCTextDeepBlackColor;
             btnHouseName.IsBold = true;
             btnHouseName.Text = Config.Instance.Home.Name;
-            btnHouseName.Width = btnHouseName.GetRealWidthByText();
+            btnHouseName.Width = btnHouseName.GetRealWidthByText() + Application.GetRealWidth(100);
             this.listBodyContr.frameTable.AddChidren(btnHouseName);
 
             //鍒囨崲浣忓畢
@@ -165,7 +175,8 @@
                     selectHouse.Init();
                     selectHouse.HouseAction = (houseId) =>
                     {
-                        ChangeResidence(House.GetHouseByHouseId(houseId));
+                        //鍒囨崲浣忓畢
+                        this.ChangeResidence(HdlResidenceLogic.Current.GetHouseByHouseId(houseId));
                     };
                 }
             };
@@ -177,7 +188,7 @@
         private void InitMidFrameLayoutControl()
         {
             //鎴愬憳韬唤涓嶅厑璁告坊鍔犵綉鍏�
-            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
+            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 3)
             {
                 //鍒濆鍖栧満鏅�,鍔熻兘鐨勫垏鎹㈡帶浠�
                 this.InitSceneFunctionSwitchControl();
@@ -187,7 +198,7 @@
             }
 
             //妫�娴嬫槸鍚︾粦瀹氭湁缃戝叧
-            if (this.CheckHadBindGateway() == false)
+            if (Common.Config.Instance.Home.IsVirtually == false && this.CheckHadBindGateway() == false)
             {
                 //鏄剧ず娌℃湁缁戝畾杩囩綉鍏崇殑鐣岄潰
                 this.ShowNoGatewayTip();
@@ -236,13 +247,13 @@
             btnFunction.TextID = R.MyInternationalizationString.Function;
             btnFunction.TextAlignment = TextAlignment.Center;
             functionSceneView.AddChidren(btnFunction);
-            if (UserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex == 1)
+            if (HdlUserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex == 1)
             {
                 btnScene.IsSelected = true;
                 btnScene.TextSize = 17;
                 btnScene.IsBold = true;
             }
-            else if (UserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex == 2)
+            else if (HdlUserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex == 2)
             {
                 btnFunction.IsSelected = true;
                 btnFunction.TextSize = 17;
@@ -250,13 +261,10 @@
             }
 
             //鍔熻兘鍜屽満鏅痓odyView
-            this.bodyFrameLayout = new FrameLayout()
-            {
-                Y = functionSceneView.Bottom,
-                Height = Application.GetRealHeight(750),
-                Gravity = Gravity.CenterHorizontal,
-                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
-            };
+            this.bodyFrameLayout = new NormalFrameLayout();
+            bodyFrameLayout.Y = functionSceneView.Bottom;
+            bodyFrameLayout.Height = this.listBodyContr.frameTable.Height - functionSceneView.Bottom;
+            bodyFrameLayout.BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor;
             this.listBodyContr.frameTable.AddChidren(bodyFrameLayout);
 
             //閫夋嫨鍔熻兘鍒嗘爮
@@ -267,7 +275,7 @@
                     return;
                 }
                 //鍔熻兘鍒嗘敮閫夋嫨
-                UserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex = 2;
+                HdlUserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex = 2;
 
                 btnScene.IsSelected = false;
                 btnScene.TextSize = 15;
@@ -287,7 +295,7 @@
                     return;
                 }
                 //鍦烘櫙鍒嗘敮閫夋嫨
-                UserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex = 1;
+                HdlUserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex = 1;
 
                 btnScene.IsSelected = true;
                 btnScene.TextSize = 17;
@@ -312,8 +320,8 @@
             bg.UnSelectedImagePath = "Item/NoBindGW.png";
             this.listBodyContr.frameTable.AddChidren(bg);
 
-            var tip = new NormalViewControl(Application.GetMinRealAverage(717), Application.GetMinRealAverage(58), false);
-            tip.Y = Application.GetRealHeight(815);
+            var tip = new NormalViewControl(this.GetPictrueRealSize(717), this.GetPictrueRealSize(58), false);
+            tip.Y = bg.Bottom + Application.GetRealHeight(35);
             tip.Gravity = Gravity.CenterHorizontal;
             tip.TextID = R.MyInternationalizationString.NewAccountNeedBingGW;
             tip.TextColor = ZigbeeColor.Current.GXCTextGrayColor;
@@ -321,13 +329,13 @@
             this.listBodyContr.frameTable.AddChidren(tip);
 
             var addBG = new PicViewControl(971, 366);
-            addBG.Y = Application.GetRealHeight(1048);
+            addBG.Y = tip.Bottom + Application.GetRealHeight(176);
             addBG.UnSelectedImagePath = "Item/VirtualFrame.png";
             addBG.Gravity = Gravity.CenterHorizontal;
             this.listBodyContr.frameTable.AddChidren(addBG);
 
             var addGatewayBtn = new IconViewControl(89);
-            addGatewayBtn.Y = Application.GetRealHeight(1143);
+            addGatewayBtn.Y = tip.Bottom + Application.GetRealHeight(271);
             addGatewayBtn.UnSelectedImagePath = "Item/Add_GW.png";
             addGatewayBtn.Gravity = Gravity.CenterHorizontal;
             this.listBodyContr.frameTable.AddChidren(addGatewayBtn);
@@ -338,7 +346,7 @@
             };
 
             var addTip = new PicViewControl(717, 58);
-            addTip.Y = Application.GetRealHeight(1256);
+            addTip.Y = addGatewayBtn.Bottom + Application.GetRealHeight(23);
             addTip.Gravity = Gravity.CenterHorizontal;
             addTip.TextID = R.MyInternationalizationString.AddSmartGW;
             addTip.TextColor = ZigbeeColor.Current.GXCTextBlackColor;
@@ -400,7 +408,11 @@
             roomPageView.SetLeftAndRightImageView(mLeftImageView, mRightImageView);
 
             //褰撳墠鎴块棿
-            var listRoom = HdlRoomLogic.Current.GetRoomsByCurrentFloorIdAppendLoveRoom();
+            var listRoom = HdlRoomLogic.Current.GetRoomsByFloorIdAppendLoveRoom(Config.Instance.Home.CurrentFloorId);
+            if (HdlRoomLogic.Current.NowMainPageRoom == null)
+            {
+                HdlRoomLogic.Current.NowMainPageRoom = listRoom[0];
+            }
             var curIndex = 0;
             for (int i = 0; i < listRoom.Count; i++)
             {
@@ -408,7 +420,7 @@
                 roomPageView.AddChidren(roomView);
                 roomView.Init(listRoom[i]);
 
-                if (listRoom[i].Id == HdlRoomLogic.Current.CurrentRoom.Id)
+                if (listRoom[i].Id == HdlRoomLogic.Current.NowMainPageRoom.Id)
                 {
                     //褰撳墠鎴块棿,鍒欐樉绀洪偅浜涙暟鎹嚭鏉�
                     roomView.HideName(false);
@@ -473,7 +485,7 @@
                 btnRoomRightShadow.Visible = true;
                 btnRoomBottomShadow.Visible = true;
                 //鍒囨崲褰撳墠鎴块棿
-                HdlRoomLogic.Current.CurrentRoom = listRoom[curIndex];
+                HdlRoomLogic.Current.NowMainPageRoom = listRoom[curIndex];
                 //鍒锋柊璁惧妗屽竷鎺т欢
                 this.isRoomChanging = false;
                 this.RefreshBodyView();
@@ -498,7 +510,7 @@
                 //褰撴病鏈夌粦瀹氭湁缃戝叧,宸︽粦鏃�,鐐瑰嚮鎴块棿鍒楄〃,鍒欎笉楦熷畠
                 return;
             }
-            var listRoom = HdlRoomLogic.Current.GetRoomsByCurrentFloorIdAppendLoveRoom();
+            var listRoom = HdlRoomLogic.Current.GetRoomsByFloorIdAppendLoveRoom(Config.Instance.Home.CurrentFloorId);
             for (int i = 0; i < listRoom.Count; i++)
             {
                 if (room.Id == listRoom[i].Id)
@@ -514,7 +526,7 @@
             //閲嶇疆涓�涓嬫ゼ灞傚悕瀛�
             if (this.btnFloorName != null)
             {
-                btnFloorName.Text = HdlResidenceLogic.Current.GetFloorNameById(Config.Instance.Home.CurrentFloorId);
+                btnFloorName.Text = Config.Instance.Home.GetCurrentFloorName;
             }
         }
 
@@ -531,15 +543,15 @@
             bodyFrameLayout.RemoveAll();
             bodyFrameLayout.Height = Application.GetRealHeight(750);
             this.listBodyContr.RecoverTableHeight();
-            this.dicSceneCardControl.Clear();
-            this.dicDeviceCardControl.Clear();
+            this.dicSceneCardControl = new Dictionary<int, Controls.SceneCardControl>();
+            this.dicDeviceCardControl = new Dictionary<string, Controls.DeviceCardCommon>();
 
             var listDevice = new List<CommonDevice>();
-            foreach (var mainkeys in HdlRoomLogic.Current.CurrentRoom.ListDevice)
+            foreach (var mainkeys in HdlRoomLogic.Current.NowMainPageRoom.ListDevice)
             {
-                var device = LocalDevice.Current.GetDevice(mainkeys);
+                var device = HdlDeviceCommonLogic.Current.GetDevice(mainkeys);
                 //鍒ゆ柇璇ヨ澶囪兘鍚︽樉绀哄湪涓婚〉
-                if (LocalDevice.Current.CanShowInHomeHomeMainPage(device) == false)
+                if (HdlDeviceCommonLogic.Current.CanShowInHomeHomeMainPage(device) == false)
                 {
                     continue;
                 }
@@ -549,7 +561,8 @@
             //褰撳墠鎴块棿鐨勮澶囨暟
             if (listDevice.Count == 0)
             {
-                ShowNoFunctionTip();
+                //杩樻病鏈夊姛鑳藉摝
+                this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.NoFunction_Tip));
                 return;
             }
             //璁惧鍒楄〃瀹瑰櫒鎺т欢
@@ -573,7 +586,7 @@
             //璁惧璁℃暟
             int contrCount = 0;
             //X杞村潗鏍�(鍥剧墖宸﹁竟鏈変綑鐧�)
-            int XX = Application.GetMinRealAverage(44);
+            int XX = this.GetPictrueRealSize(44);
             //Y杞村潗鏍�
             int YY = 0;
             var listContr = new List<Controls.DeviceCardCommon>();
@@ -607,6 +620,16 @@
                     {
                         cardContr = new Controls.DeviceAcCardControl();
                     }
+                    //鏂伴
+                    else if (device.Type == DeviceType.FreshAir)
+                    {
+                        cardContr = new Controls.DeviceFreshAirCardControl();
+                    }
+                    // PM2.5
+                    else if (device.Type == DeviceType.PMSensor)
+                    {
+                        cardContr = new Controls.DevicePmSensorCardControl();
+                    }
                     //褰╃伅(璋冨厜鍣�)
                     else if (device.Type == DeviceType.DimmableLight)
                     {
@@ -627,6 +650,11 @@
                     {
                         cardContr = new Controls.DeviceDoorLockCardControl();
                     }
+                    //鑹叉俯鐏�
+                    else if (device.Type == DeviceType.ColorTemperatureLight)
+                    {
+                        cardContr = new Controls.DeviceColorTemperatureCardControl();
+                    }
                     //鏃犳硶璇嗗埆
                     else
                     {
@@ -637,24 +665,24 @@
                     cardContr.X = XX;
                     cardContr.Y = YY;
                     listDeviceBackContr.AddChidren(cardContr);
-                    cardContr.InitControl(device);
+                    cardContr.InitControl(device, HdlRoomLogic.Current.NowMainPageRoom);
                     //鍗$墖闇�瑕佽绉婚櫎鐨勪簨浠�
                     cardContr.CardNeedRemoveEvent += () =>
                     {
                         //閲嶇疆璁惧鍗$墖鎺т欢鍧愭爣(鍗$墖闇�瑕佽鍒犻櫎涓撶敤)
-                        this.ResetDeviceCardControlLocation(LocalDevice.Current.GetDeviceMainKeys(device));
+                        this.ResetDeviceCardControlLocation(HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device));
                     };
                     //璁惧璁℃暟
                     contrCount++;
                     //鍗$墖宸﹀彸涓よ竟鏈�14鐨勪綑鐧�,姣忎袱涓悗,X杞撮噸缃�
-                    XX = contrCount % 2 == 0 ? Application.GetMinRealAverage(44) : cardContr.Right + Application.GetMinRealAverage(20);
+                    XX = contrCount % 2 == 0 ? this.GetPictrueRealSize(44) : cardContr.Right + this.GetPictrueRealSize(20);
                     if (contrCount % 2 == 0)
                     {
                         //娌′袱涓箣鍚�,Y杞撮�掑
-                        YY = cardContr.Bottom + Application.GetMinRealAverage(15);
+                        YY = cardContr.Bottom + this.GetPictrueRealSize(15);
                     }
                     //鎺т欢璁板綍鍒扮紦瀛樹腑
-                    this.dicDeviceCardControl[LocalDevice.Current.GetDeviceMainKeys(device)] = cardContr;
+                    this.dicDeviceCardControl[HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device)] = cardContr;
                     //鍔犵紦瀛�,鐒跺悗鍙戝懡浠�
                     listContr.Add(cardContr);
 
@@ -669,17 +697,31 @@
                         }
                         HdlThreadLogic.Current.RunThread(() =>
                         {
-                            for (int i = 0; i < listContr.Count; i++)
+                            while (listDeviceBackContr.Parent != null)
                             {
-                                if (listDeviceBackContr.Parent == null)
+                                bool hadSend = false;
+                                for (int i = 0; i < listContr.Count; i++)
                                 {
-                                    return;
+                                    if (listDeviceBackContr.Parent == null)
+                                    {
+                                        return;
+                                    }
+                                    //濡傛灉杩樻病鏈夋帴鏀跺埌鏁版嵁,鍒欏啀娆″彂閫�
+                                    if (listContr[i].ReceiveResponeResultStatu() == false)
+                                    {
+                                        //鍙戦�佽幏鍙栫姸鎬佺殑鍛戒护
+                                        listContr[i].SendStatuComand();
+                                        hadSend = true;
+                                        System.Threading.Thread.Sleep(200);
+                                    }
                                 }
-                                System.Threading.Thread.Sleep(200);
-                                //鍙戦�佽幏鍙栫姸鎬佺殑鍛戒护
-                                listContr[i].SendStatuComand();
+                                if (hadSend == false)
+                                {
+                                    //濡傛灉宸茬粡鍏ㄩ儴鍥炶矾閮芥帴鏀朵簡缃戝叧鍥炲,鍒欎笉鍐嶄簩娆″彂閫�
+                                    break;
+                                }
+                                System.Threading.Thread.Sleep(2000);
                             }
-
                         }, ShowErrorMode.NO);
                     }
                 });
@@ -689,33 +731,6 @@
                     System.Threading.Thread.Sleep(50);
                 }
             }
-        }
-
-        /// <summary>
-        /// 鏄剧ず娌℃湁鍔熻兘
-        /// </summary>
-        private void ShowNoFunctionTip()
-        {
-            var noFunction = new Button
-            {
-                Y = Application.GetRealHeight(69),
-                Width = Application.GetMinRealAverage(683),
-                Height = Application.GetMinRealAverage(392),
-                Gravity = Gravity.CenterHorizontal,
-                UnSelectedImagePath = "Item/NoFunction.png"
-            };
-            bodyFrameLayout.AddChidren(noFunction);
-
-            var noFunctionTip = new Button()
-            {
-                Y = noFunction.Bottom,
-                Height = Application.GetRealHeight(200),
-                Text = Language.StringByID(R.MyInternationalizationString.NoFunction_Tip).Replace("{\\r\\n}", "\r\n"),
-                TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
-                TextAlignment = TextAlignment.Center,
-                IsMoreLines = true
-            };
-            bodyFrameLayout.AddChidren(noFunctionTip);
         }
 
         #endregion
@@ -755,12 +770,12 @@
                 if (contrCount % 2 == 1)
                 {
                     //绗竴涓浐瀹�44
-                    XX = Application.GetMinRealAverage(44);
+                    XX = this.GetPictrueRealSize(44);
                 }
                 else
                 {
                     //绗簩涓槸44+鎺т欢瀹藉害+20浣欑櫧
-                    XX = Application.GetMinRealAverage(44) + this.dicDeviceCardControl[mainkey].Width + Application.GetMinRealAverage(20);
+                    XX = this.GetPictrueRealSize(44) + this.dicDeviceCardControl[mainkey].Width + this.GetPictrueRealSize(20);
                 }
 
                 //姣忎袱涓箣鍚�,骞朵笖鏄涓�涓殑鏃跺��,Y杞撮�掑
@@ -769,7 +784,7 @@
                     //姹傚晢
                     int value = contrCount / 2;
                     //鎺т欢鐨勫簳閮ㄦ湁15鐨勯棿闅�
-                    YY = value * (this.dicDeviceCardControl[mainkey].Height + Application.GetMinRealAverage(15));
+                    YY = value * (this.dicDeviceCardControl[mainkey].Height + this.GetPictrueRealSize(15));
                 }
                 if (canMove == true)
                 {
@@ -807,11 +822,11 @@
             bodyFrameLayout.RemoveAll();
             bodyFrameLayout.Height = Application.GetRealHeight(750);
             this.listBodyContr.RecoverTableHeight();
-            this.dicSceneCardControl.Clear();
-            this.dicDeviceCardControl.Clear();
+            this.dicSceneCardControl = new Dictionary<int, Controls.SceneCardControl>();
+            this.dicDeviceCardControl = new Dictionary<string, Controls.DeviceCardCommon>();
 
             var listScene = new List<SceneUI>();
-            foreach (int sceneId in HdlRoomLogic.Current.CurrentRoom.ListSceneId)
+            foreach (int sceneId in HdlRoomLogic.Current.NowMainPageRoom.ListSceneId)
             {
                 var sceneUi = HdlSceneLogic.Current.GetSceneUIBySceneId(sceneId);
                 if (sceneUi == null)
@@ -824,8 +839,8 @@
 
             if (listScene.Count == 0)
             {
-                //鏄剧ず娌″満鏅�
-                this.ShowNoSceneTip();
+                //杩樻病鏈夊満鏅摝
+                this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.NoScene_Tip));
                 return;
             }
             //鍒楄〃鎺т欢
@@ -910,26 +925,6 @@
         }
 
         /// <summary>
-        /// 鏄剧ず娌″満鏅�
-        /// </summary>
-        private void ShowNoSceneTip()
-        {
-            var picNoFunc = new PicViewControl(683, 392);
-            picNoFunc.Y = Application.GetRealHeight(69);
-            picNoFunc.Gravity = Gravity.CenterHorizontal;
-            picNoFunc.UnSelectedImagePath = "Item/NoFunction.png";
-            bodyFrameLayout.AddChidren(picNoFunc);
-
-            var btnTip = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(200), false);
-            btnTip.Y = picNoFunc.Bottom;
-            btnTip.Text = Language.StringByID(R.MyInternationalizationString.NoScene_Tip).Replace("{\\r\\n}", "\r\n");
-            btnTip.TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor;
-            btnTip.TextAlignment = TextAlignment.Center;
-            btnTip.IsMoreLines = true;
-            bodyFrameLayout.AddChidren(btnTip);
-        }
-
-        /// <summary>
         /// 璁剧疆鍦烘櫙鐨勫欢杩熺姸鎬�
         /// </summary>
         /// <param name="listSceneBackContr"></param>
@@ -1009,12 +1004,12 @@
                 if (contrCount % 2 == 1)
                 {
                     //绗竴涓浐瀹�44
-                    XX = Application.GetMinRealAverage(44);
+                    XX = this.GetPictrueRealSize(44);
                 }
                 else
                 {
                     //绗簩涓槸44+鎺т欢瀹藉害+20浣欑櫧
-                    XX = Application.GetMinRealAverage(44) + this.dicSceneCardControl[sceneId].Width + Application.GetMinRealAverage(20);
+                    XX = this.GetPictrueRealSize(44) + this.dicSceneCardControl[sceneId].Width + this.GetPictrueRealSize(20);
                 }
 
                 //姣忎袱涓箣鍚�,骞朵笖鏄涓�涓椂,Y杞撮�掑
@@ -1023,7 +1018,7 @@
                     //姹傚晢
                     int value = contrCount / 2;
                     //鎺т欢鐨勫簳閮ㄦ湁15鐨勯棿闅�
-                    YY = value * (this.dicSceneCardControl[sceneId].Height + Application.GetMinRealAverage(15));
+                    YY = value * (this.dicSceneCardControl[sceneId].Height + this.GetPictrueRealSize(15));
                 }
                 if (canMove == true)
                 {
@@ -1062,7 +1057,7 @@
             //璁╃晫闈㈠埆闂儊
             HdlThreadLogic.Current.RunMainInThread(() =>
             {
-                if (UserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex == 2)
+                if (HdlUserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex == 2)
                 {
                     //鍔熻兘
                     this.ShowFunction();
@@ -1084,36 +1079,23 @@
         /// <param name="home">Home.</param>
         private void ChangeResidence(House home)
         {
-            try
+            HdlThreadLogic.Current.RunThread(() =>
             {
-                CommonPage.Loading.Start();
-                new System.Threading.Thread(async () =>
-                {
-                    Config.Instance.HomeId = home.Id;
-                    Config.Instance.Home = House.GetHouseByFilePath(home.FileName);
-                    Global.CreateHomeDirectory(home.Id);
-                    Config.Instance.Save();
-                    //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼
-                    await UserCenterLogic.InitUserCenterMenmoryAndThread();
-                    //鍒濆鍖栧叏閮ㄦ埧闂�
-                    HdlRoomLogic.Current.InitAllRoom();
+                this.ShowProgressBar();
 
-                    Application.RunOnMainThread(() =>
-                    {
-                        ShowForm();
-                        CommonPage.Loading.Hide();
-                    });
-                })
-                { IsBackground = true }.Start();
-            }
-            catch (Exception ex)
-            {
-                Application.RunOnMainThread(() =>
+                //鍒囨崲浣忓畢
+                var result = HdlResidenceLogic.Current.SwitchResidence(home.Id);
+
+                HdlThreadLogic.Current.RunMain(() =>
                 {
-                    CommonPage.Loading.Hide();
-                    Console.WriteLine(ex.Message);
+                    if (result == true)
+                    {
+                        //鍒锋柊鐣岄潰
+                        this.ShowForm();
+                    }
+                    this.CloseProgressBar();
                 });
-            }
+            });
         }
 
         #endregion
@@ -1131,17 +1113,24 @@
                 HdlThreadLogic.Current.RunMain(() =>
                 {
                     //澶勭悊涓�鑸澶囩殑涓婃姤鏁版嵁
-                    string mainKeys = LocalDevice.Current.GetDeviceMainKeys(report);
+                    string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(report);
                     if (this.dicDeviceCardControl.ContainsKey(mainKeys) == true)
                     {
                         //鍒锋柊鍗$墖淇℃伅
-                        var locadevice = LocalDevice.Current.GetDevice(mainKeys);
-                        if (report.DeviceStatusReport.CluterID == 513 && report.DeviceStatusReport.AttriBute[0].AttributeId == 28)
+                        var locadevice = HdlDeviceCommonLogic.Current.GetDevice(mainKeys);
+                        //宸茬粡鎺ユ敹鍒扮綉鍏崇殑鍙嶉 2020.05.09:鍒犻櫎Ack涓婚
+                        this.dicDeviceCardControl[mainKeys].SetHadGetResponeResultStatu();
+                        //鍒锋柊鎺т欢
+                        if (locadevice.Type != DeviceType.IASZone)
                         {
-                            //绌鸿皟鏄壒娈婄殑,瀹冪殑寮�鍏虫槸灞炴�т笂鎶ユ潵鐫�.宸茬粡鎺ユ敹鍒扮綉鍏崇殑鍙嶉
-                            this.dicDeviceCardControl[mainKeys].SetHadGetResponeResultStatu();
+                            //浼犳劅鍣ㄤ笉闇�瑕佸睘鎬т笂鎶�(浣嗘槸閭d釜鐞冨瀷浼犳劅鍣ㄥ眳鐒朵細灞炴�т笂鎶�)
+                            this.dicDeviceCardControl[mainKeys].RefreshControlInfo(locadevice);
                         }
-                        this.dicDeviceCardControl[mainKeys].RefreshControlInfo(locadevice);
+                        else if (report.DeviceStatusReport.CluterID == 1)
+                        {
+                            //杩欎釜鏄數閲忔帹閫�
+                            this.dicDeviceCardControl[mainKeys].RefreshBatteryStatu();
+                        }
                     }
                 }, ShowErrorMode.NO);
             });
@@ -1151,29 +1140,13 @@
             {
                 HdlThreadLogic.Current.RunMain(() =>
                 {
-                    string mainKeys = LocalDevice.Current.GetDeviceMainKeys(report);
+                    string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(report);
                     if (this.dicDeviceCardControl.ContainsKey(mainKeys) == true)
                     {
                         //鍒锋柊鍗$墖鐘舵��
-                        this.dicDeviceCardControl[mainKeys].SetCardOnlineStatu(report.IsOnline == 1);
+                        bool bolOnline = HdlDeviceCommonLogic.Current.CheckDeviceIsOnline(report);
+                        this.dicDeviceCardControl[mainKeys].SetCardOnlineStatu(bolOnline);
                         return;
-                    }
-
-                }, ShowErrorMode.NO);
-            });
-
-            //璁惧鎺у埗鍙嶉涓婃姤
-            HdlGatewayReceiveLogic.Current.AddAttributeEvent("UserHomeViewDeviceRespone", ReceiveComandDiv.A鑺傜偣鎺у埗鍙嶉, (report) =>
-            {
-                HdlThreadLogic.Current.RunMain(() =>
-                {
-                    string mainKeys = LocalDevice.Current.GetDeviceMainKeys(report);
-                    if (this.dicDeviceCardControl.ContainsKey(mainKeys) == true)
-                    {
-                        //璁惧鍗$墖
-                        var deviceCardContr = this.dicDeviceCardControl[mainKeys];
-                        //宸茬粡鎺ユ敹鍒扮綉鍏崇殑鍙嶉
-                        deviceCardContr.SetHadGetResponeResultStatu();
                     }
 
                 }, ShowErrorMode.NO);
@@ -1195,16 +1168,54 @@
                 HdlThreadLogic.Current.RunMain(() =>
                 {
                     //澶勭悊浼犳劅鍣ㄤ笂鎶ユ暟鎹�
-                    string mainKeys = LocalDevice.Current.GetDeviceMainKeys(report);
+                    string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(report);
                     if (this.dicDeviceCardControl.ContainsKey(mainKeys) == true)
                     {
-                        //鏈湴璁惧瀵硅薄
-                        var locadevice = LocalDevice.Current.GetDevice(mainKeys);
-                        //鍒锋柊鍗$墖淇℃伅
-                        this.dicDeviceCardControl[mainKeys].RefreshControlInfo(locadevice);
+                        //寮�鍚崱鐗囬棯鐑佺壒鏁�
+                        this.dicDeviceCardControl[mainKeys].StartCardLightAppeal();
                     }
 
                 }, ShowErrorMode.NO);
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 浼犳劅鍣ㄧ姸鎬佽繕鍘焈____________________
+
+        /// <summary>
+        /// 寮�鍚紶鎰熷櫒鐘舵�佽繕鍘熺殑绾跨▼
+        /// </summary>
+        private void StartRecoverSenorStatuThread()
+        {
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                while (this.Parent != null)
+                {
+                    try
+                    {
+                        var dicControl = this.dicDeviceCardControl;
+                        foreach (var contr in dicControl.Values)
+                        {
+                            //濡傛灉鏄紶鎰熷櫒,鍒欏埛鏂扮姸鎬�
+                            if (contr.device.Type == DeviceType.IASZone && contr.Parent != null
+                              && ((IASZone)contr.device).iASInfo == null)
+                            {
+                                HdlThreadLogic.Current.RunMain(() =>
+                                {
+                                    //璁惧鐘舵�佸繀椤诲埛鏂�
+                                    string statuText = HdlDeviceCommonLogic.Current.GetMainPageDeviceStatuText(contr.device);
+                                    contr.SetDeviceStatuText(statuText);
+                                    //浼犳劅鍣ㄥ垏鎹负鐏拌壊鐘舵��
+                                    contr.SwitchCardStatuAppeal(false);
+
+                                }, ShowErrorMode.NO);
+                            }
+                        }
+                        System.Threading.Thread.Sleep(8000);
+                    }
+                    catch { System.Threading.Thread.Sleep(3000); }
+                }
             });
         }
 
@@ -1218,13 +1229,16 @@
         private void ShowSelectFloorForm(NormalViewControl btnFloor)
         {
             var floorFL = new Category.SelectFloorForm();
+            floorFL.CurFloorId = Config.Instance.Home.CurrentFloorId;
             this.AddChidren(floorFL);
             floorFL.Init(35, 153);
-            floorFL.changeFloor = true;
             floorFL.FloorAction = (floorId) =>
             {
-                btnFloor.Text = Config.Instance.Home.GetFloorNameById(floorId);
-                HdlRoomLogic.Current.CurrentRoom = HdlRoomLogic.Current.GetLoveRoom();
+                btnFloor.Text = HdlResidenceLogic.Current.GetFloorNameById(floorId);
+                Config.Instance.Home.CurrentFloorId = floorId;
+                HdlRoomLogic.Current.NowMainPageRoom = HdlRoomLogic.Current.GetLoveRoom();
+                //鍒嗙被鐣岄潰闇�瑕佸埛鏂�
+                UserView.UserPage.Instance.RefreshCategoryForm = true;
                 this.ShowForm();
             };
         }
@@ -1238,8 +1252,10 @@
         /// </summary>
         public override void CloseFormBefore()
         {
+            //鎶婇潤鎬佸彉閲忕殑杩欎釜涓滆タ缃┖
+            Instance = null;
+
             HdlGatewayReceiveLogic.Current.RemoveEvent("UserHomeViewDeviceOnline");
-            HdlGatewayReceiveLogic.Current.RemoveEvent("UserHomeViewDeviceRespone");
             HdlGatewayReceiveLogic.Current.RemoveEvent("UserHomeViewDeviceStatus");
             HdlGatewayReceiveLogic.Current.RemoveEvent("UserHomeViewSensor");
 

--
Gitblit v1.8.0