From 94e4e5b9fd3da964c44b7b14227d6fe2bbb426d7 Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期四, 02 四月 2020 13:56:39 +0800
Subject: [PATCH] 2020-04-02-2

---
 ZigbeeApp/Shared/Phone/Device/Light/OnOffControl.cs |  382 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 239 insertions(+), 143 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/Light/OnOffControl.cs b/ZigbeeApp/Shared/Phone/Device/Light/OnOffControl.cs
index dae9d4c..bb3e05b 100755
--- a/ZigbeeApp/Shared/Phone/Device/Light/OnOffControl.cs
+++ b/ZigbeeApp/Shared/Phone/Device/Light/OnOffControl.cs
@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using Shared.Common;
 using Shared.Phone.Device.CommonForm;
+using Shared.Phone.Device.DeviceLogic;
 using Shared.Phone.UserView;
 using ZigBee.Device;
 namespace Shared.Phone.Device.Light
@@ -19,7 +20,7 @@
         /// <summary>
         /// The action.
         /// </summary>
-        public Action action;
+        public Action<CommonDevice, Common.Room> action;
 
         /// <summary>
         /// The light image.
@@ -32,7 +33,7 @@
         /// <summary>
         /// 浼犺繃鏉ョ殑璁惧
         /// </summary>
-        private DeviceUI device;
+        private CommonDevice device;
         /// <summary>
         /// 浼犺繃鏉ョ殑鎴块棿
         /// </summary>
@@ -70,34 +71,14 @@
         /// </summary>
         private Button OffBtn;
 
+        /// <summary>
+        /// IsDrawerLockMode
+        /// </summary>
+        public bool IsDrawerLockMode;
         #endregion
 
         #region 鈼� 鎺ュ彛__________________________
-        /// <summary>
-        /// 澶勭悊鍙樺寲浜嬩欢 --灏嗗純鐢� 鏀圭敤DeviceInfoChange()
-        /// </summary>
-        /// <returns>The changed.</returns>
-        /// <param name="common">Common.</param>
-        public void Changed(CommonDevice common)
-        {
-
-        }
-        /// <summary>
-        /// Changeds the IL ogic status.
-        /// </summary>
-        /// <param name="logic">Logic.</param>
-        public void ChangedILogicStatus(ZigBee.Device.Logic logic)
-        {
-            //throw new NotImplementedException();
-        }
-        /// <summary>
-        /// Changeds the IS cene status.
-        /// </summary>
-        /// <param name="scene">Scene.</param>
-        public void ChangedISceneStatus(Scene scene)
-        {
-            //throw new NotImplementedException();
-        }
+        
         /// <summary>
         /// 璁惧鐘舵�佹洿鏂版帴鍙�
         /// <para>type锛氬鏋滀负 DeviceInComingRespon:璁惧鏂颁笂鎶�</para>
@@ -118,20 +99,20 @@
                     {
                         var deviceUI = device;
                         //璁惧涓虹┖
-                        if (deviceUI.CommonDevice == null)
+                        if (deviceUI == null)
                         {
                             return;
                         }
                         //鏄惁涓哄綋鍓嶈澶�
-                        if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr)
+                        if (deviceUI.DeviceEpoint != common.DeviceEpoint || deviceUI.DeviceAddr != common.DeviceAddr)
                         {
                             return;
                         }
-                        if (deviceUI.CommonDevice.Type == DeviceType.OnOffOutput)
+                        if (deviceUI.Type == DeviceType.OnOffOutput)
                         {
                             if (common.DeviceStatusReport.CluterID == 6)
                             {
-                                var light = deviceUI.CommonDevice as ToggleLight;
+                                var light = deviceUI as ToggleLight;
                                 light.DeviceStatusReport = common.DeviceStatusReport;
                                 //璁板綍銆佹洿鏂扮姸鎬�
                                 if (light.DeviceStatusReport.AttriBute == null || light.DeviceStatusReport.AttriBute.Count == 0)
@@ -139,8 +120,22 @@
                                     return;
                                 }
                                 light.OnOffStatus = light.DeviceStatusReport.AttriBute[0].AttriButeData;
-                                SetONOFFStatu(light.OnOffStatus == 1);
-                                StatuBtn.Text = CommonFormResouce.GetSwitchStatu(light.OnOffStatus == 1);
+                                StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + "   " + UserCenter.HdlDeviceOtherLogic.Current.GetDeviceStatu(device);
+
+                                if (device.DfunctionType == DeviceFunctionType.A寮�鍏�)
+                                {
+                                    SetONOFFStatu(light.OnOffStatus == 1);
+                                }
+                                else if (device.DfunctionType == DeviceFunctionType.A鎻掑骇)
+                                {
+                                    deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1;
+                                }
+                                else
+                                {
+                                    deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1;
+                                }
+                                
+
                                 light.LastDateTime = DateTime.Now;
                             }
                         }
@@ -159,18 +154,18 @@
                     {
                         var deviceUI = device;
                         //璁惧涓虹┖
-                        if (deviceUI.CommonDevice == null)
+                        if (deviceUI == null)
                         {
                             return;
                         }
                         //鏄惁涓哄綋鍓嶈澶�
-                        if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr)
+                        if (deviceUI.DeviceEpoint != common.DeviceEpoint || deviceUI.DeviceAddr != common.DeviceAddr)
                         {
                             return;
                         }
-                        deviceUI.CommonDevice.IsOnline = common.IsOnline;
-                        OnBtn.IsSelected = OffBtn.IsSelected= deviceUI.CommonDevice.IsOnline == 1;
-                        deviceUI.CommonDevice.LastDateTime = DateTime.Now;
+                        deviceUI.IsOnline = common.IsOnline;
+                        //OnBtn.IsSelected = OffBtn.IsSelected= deviceUI.CommonDevice.IsOnline == 1;
+                        deviceUI.LastDateTime = DateTime.Now;
                     }
                     catch (Exception ex)
                     {
@@ -188,9 +183,13 @@
         public override void RemoveFromParent()
         {
             ZbGateway.StatusList.Remove(this);
-            //action();
-            //action = null;
+            action(device, room);
+            action = null;
             RemoveUpdateControlDeviceStatuAction();
+            if (IsDrawerLockMode)
+            {
+                CommonPage.Instance.IsDrawerLockMode = false;
+            }
             base.RemoveFromParent();
         }
 
@@ -207,10 +206,10 @@
         /// </summary>
         /// <param name="dev">Device.</param>
         /// <param name="room">Room.</param>
-        public void Show(DeviceUI dev, Shared.Common.Room room)
+        public void Show(CommonDevice dev, Shared.Common.Room room)
         {
             device = dev;
-            zbGateway = this.device.CommonDevice.Gateway;
+            zbGateway = this.device.Gateway;
             this.room = room;
 
             AddTop();
@@ -218,7 +217,7 @@
             AddBodyView(device);
 
 
-            var light = dev.CommonDevice as ToggleLight;
+            var light = dev as ToggleLight;
             //琛ヤ笂闈炶繙绋�
             if (light.Gateway == null)
             {
@@ -228,8 +227,7 @@
             {
                 UserHomeView.ReadStatus(light, () =>
                 {
-                    light.ReadOnOffStatus();
-                    light.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
+                    ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device);
                 });
             }
             else
@@ -237,13 +235,11 @@
                 //闃叉鐭椂闂村唴澶氭璇诲彇鐘舵��
                 if (CommonPage.ReadDeviceStatuSpan < (DateTime.Now - light.LastDateTime).TotalSeconds)
                 {
-                    light.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
-                    light.ReadOnOffStatus();
+                    ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device);
                 }
             }
 
-            var de = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == device.FileName);
-            if (de == null)
+            if(UserCenter.HdlRoomLogic.Current.IsCollectInRoom(device) == false)
             {
                 collectionBtn.IsSelected = false;
             }
@@ -274,16 +270,6 @@
                 RemoveFromParent();
             };
 
-            var sharedBtn = new Button
-            {
-                X = Application.GetRealWidth(850),
-                Width = Application.GetMinReal(69),
-                Height = Application.GetMinReal(69),
-                Gravity = Gravity.CenterVertical,
-                UnSelectedImagePath = "Item/Shared.png"
-            };
-            top.topView.AddChidren(sharedBtn);
-
             var moreBtn = new Button
             {
                 X = Application.GetRealWidth(953),
@@ -300,7 +286,7 @@
         /// <summary>
         /// AddBodyView
         /// </summary>
-        public void AddBodyView(DeviceUI device)
+        public void AddBodyView(CommonDevice device)
         {
             bodyFrameLayout = new FrameLayout()
             {
@@ -338,9 +324,10 @@
                 Width = Application.GetRealWidth(500),
                 Height = Application.GetRealHeight(60),
                 Gravity = Gravity.CenterHorizontal,
-                Text = device.CommonDevice.DeviceEpointName,
+                Text = Common.LocalDevice.Current.GetDeviceEpointName(device),
                 TextColor = ZigbeeColor.Current.GXCTextBlackColor,
-                TextSize = 15
+                TextSize = 15,
+                IsBold=true
             };
             itemView.AddChidren(deviceNameBtn);
 
@@ -351,43 +338,10 @@
                 Height = Application.GetRealHeight(60),
                 Gravity = Gravity.CenterHorizontal,
                 TextColor = ZigbeeColor.Current.GXCTextGrayColor,
-                Text = CommonFormResouce.GetSwitchStatu(device.CommonDevice.IsOnline == 1)
+                Text = Language.StringByID(R.MyInternationalizationString.Current) + "   " + UserCenter.HdlDeviceOtherLogic.Current.GetDeviceStatu(device),
+                TextSize = 10
             };
             itemView.AddChidren(StatuBtn);
-
-            deviceIMG = new Button()
-            {
-                Y = Application.GetRealHeight(340),
-                Width = Application.GetMinRealAverage(579),
-                Height = Application.GetMinRealAverage(579),
-                Gravity = Gravity.CenterHorizontal,
-                UnSelectedImagePath = "Light/OnOff.png",
-            };
-            itemView.AddChidren(deviceIMG);
-
-            OffBtn = new Button
-            {
-                X = Application.GetRealWidth(294),
-                Y = Application.GetRealHeight(588),
-                Width = Application.GetMinRealAverage(81),
-                Height = Application.GetMinRealAverage(81),
-                UnSelectedImagePath = "Light/OFF.png",
-                SelectedImagePath = "Light/OFFSelected.png",
-                IsSelected = (device.CommonDevice as ToggleLight).OnOffStatus == 0
-            };
-            itemView.AddChidren(OffBtn);
-
-            OnBtn = new Button
-            {
-                X = Application.GetRealWidth(590),
-                Y = Application.GetRealHeight(588),
-                Width = Application.GetMinRealAverage(81),
-                Height = Application.GetMinRealAverage(81),
-                UnSelectedImagePath = "Light/ON.png",
-                SelectedImagePath = "Light/ONSelected.png",
-                IsSelected = (device.CommonDevice as ToggleLight).OnOffStatus == 1
-            };
-            itemView.AddChidren(OnBtn);
 
             var roomBG = new Button
             {
@@ -424,9 +378,142 @@
                 Height = Application.GetRealHeight(50),
                 Text = room.Name,
                 TextAlignment = TextAlignment.CenterLeft,
-                TextColor = ZigbeeColor.Current.GXCTextWhiteColor
+                TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
+                TextSize = 12
             };
             itemView.AddChidren(roomName);
+
+            AddByFunctionType(itemView);
+        }
+
+        /// <summary>
+        /// AddByFunctionType
+        /// </summary>
+        private void AddByFunctionType(FrameLayout itemView)
+        {
+            if(device.DfunctionType == DeviceFunctionType.A寮�鍏�)
+            {
+                AddOnOff(itemView);
+            }
+            else if(device.DfunctionType == DeviceFunctionType.A鎻掑骇)
+            {
+                AddPlug(itemView);
+            }
+            else
+            {
+                AddLight(itemView);
+            }
+        }
+
+        /// <summary>
+        /// AddOnOff
+        /// </summary>
+        private void AddOnOff(FrameLayout itemView)
+        {
+            deviceIMG = new Button()
+            {
+                Y = Application.GetRealHeight(340),
+                Width = Application.GetMinRealAverage(579),
+                Height = Application.GetMinRealAverage(579),
+                Gravity = Gravity.CenterHorizontal,
+                UnSelectedImagePath = "Light/OnOff.png",
+            };
+            itemView.AddChidren(deviceIMG);
+
+            OffBtn = new Button
+            {
+                X = Application.GetRealWidth(294),
+                Y = Application.GetRealHeight(588),
+                Width = Application.GetMinRealAverage(81),
+                Height = Application.GetMinRealAverage(81),
+                UnSelectedImagePath = "Light/OFF.png",
+                SelectedImagePath = "Light/OFFSelected.png",
+                IsSelected = (device as ToggleLight).OnOffStatus == 0
+            };
+            itemView.AddChidren(OffBtn);
+
+            OnBtn = new Button
+            {
+                X = Application.GetRealWidth(590),
+                Y = Application.GetRealHeight(588),
+                Width = Application.GetMinRealAverage(81),
+                Height = Application.GetMinRealAverage(81),
+                UnSelectedImagePath = "Light/ON.png",
+                SelectedImagePath = "Light/ONSelected.png",
+                IsSelected = (device as ToggleLight).OnOffStatus == 1
+            };
+            itemView.AddChidren(OnBtn);
+
+            OnBtn.MouseUpEventHandler += ON;
+            OffBtn.MouseUpEventHandler += OFF;
+        }
+
+        /// <summary>
+        /// light
+        /// </summary>
+        /// <param name="itemView"></param>
+        private void AddLight(FrameLayout itemView)
+        {
+            deviceIMG = new Button()
+            {
+                Y = Application.GetRealHeight(389),
+                Width = Application.GetMinRealAverage(377),
+                Height = Application.GetMinRealAverage(435),
+                Gravity = Gravity.CenterHorizontal,
+                UnSelectedImagePath = "Light/DeskLamp.png",
+                SelectedImagePath = "Light/DeskLampSelected.png",
+                IsSelected = (device as ToggleLight).OnOffStatus == 1
+            };
+            itemView.AddChidren(deviceIMG);
+
+            switchBtn = new Button()
+            {
+                Y = Application.GetRealHeight(996),
+                Width = Application.GetMinRealAverage(81),
+                Height = Application.GetMinRealAverage(81),
+                Gravity = Gravity.CenterHorizontal,
+                UnSelectedImagePath = "Item/Switch.png",
+                SelectedImagePath = "Item/SwitchSelected.png",
+                IsSelected = (device as ToggleLight).OnOffStatus == 1
+            };
+            itemView.AddChidren(switchBtn);
+
+            switchBtn.MouseUpEventHandler += Switch;
+            deviceIMG.MouseUpEventHandler += Switch;
+        }
+
+        /// <summary>
+        /// plug
+        /// </summary>
+        /// <param name="itemView"></param>
+        private void AddPlug(FrameLayout itemView)
+        {
+            deviceIMG = new Button()
+            {
+                Y = Application.GetRealHeight(344),
+                Width = Application.GetMinRealAverage(567),
+                Height = Application.GetMinRealAverage(567),
+                Gravity = Gravity.CenterHorizontal,
+                UnSelectedImagePath = "Light/Plug.png",
+                SelectedImagePath = "Light/PlugSelected.png",
+                IsSelected = (device as ToggleLight).OnOffStatus == 1
+            };
+            itemView.AddChidren(deviceIMG);
+
+            switchBtn = new Button()
+            {
+                Y = Application.GetRealHeight(996),
+                Width = Application.GetMinRealAverage(81),
+                Height = Application.GetMinRealAverage(81),
+                Gravity = Gravity.CenterHorizontal,
+                UnSelectedImagePath = "Item/Switch.png",
+                SelectedImagePath = "Item/SwitchSelected.png",
+                IsSelected = (device as ToggleLight).OnOffStatus == 1
+            };
+            itemView.AddChidren(switchBtn);
+
+            switchBtn.MouseUpEventHandler += Switch;
+            deviceIMG.MouseUpEventHandler += Switch;
         }
 
         #endregion
@@ -437,8 +524,6 @@
         /// </summary>
         private void BindEvent()
         {
-            OnBtn.MouseUpEventHandler += ON;
-            OffBtn.MouseUpEventHandler += OFF;
             collectionBtn.MouseUpEventHandler += Collection;
         }
 
@@ -451,35 +536,43 @@
         /// </summary>
         /// <param name="sender">Sender.</param>
         /// <param name="eventArgs">Event arguments.</param>
-        //private void Switch(object sender, MouseEventArgs eventArgs)
-        //{
-        //    sendedControlCommand = false;
-        //    zbGateway.ReportAction += UpdateDeviceControllStatu;
-        //    switchBtn.IsSelected = !switchBtn.IsSelected;
-        //    deviceIMG.IsSelected = !deviceIMG.IsSelected;
-        //    StatuBtn.Text = CommonFormResouce.GetSwitchStatu(deviceIMG.IsSelected);
-        //    if (switchBtn.IsSelected == true)
-        //    {
-        //        (device.CommonDevice as ToggleLight).SwitchControl(1);
-        //    }
-        //    else
-        //    {
-        //        (device.CommonDevice as ToggleLight).SwitchControl(0);
-        //    }
-        //    //鎺у埗寤舵椂鍥炶皟
-        //    DeviceUI.SendCommandDelayAction(device.CommonDevice, () =>
-        //    {
-        //        if (Parent == null)
-        //        {
-        //            return;
-        //        }
-        //        RemoveUpdateControlDeviceStatuAction();
-        //        if (sendedControlCommand == false)
-        //        {
-        //            DeviceUI.ShowStatuTip(R.MyInternationalizationString.FAIL);
-        //        }
-        //    });
-        //}
+        private void Switch(object sender, MouseEventArgs eventArgs)
+        {
+            sendedControlCommand = false;
+            zbGateway.ReportAction += UpdateDeviceControllStatu;
+            switchBtn.IsSelected = !switchBtn.IsSelected;
+            deviceIMG.IsSelected = !deviceIMG.IsSelected;
+            StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + "   ";
+            if (deviceIMG.IsSelected == true)
+            {
+                StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.uOpen1);
+            }
+            else
+            {
+                StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.Close);
+            }
+            if (switchBtn.IsSelected == true)
+            {
+                (device as ToggleLight).SwitchControl(1);
+            }
+            else
+            {
+                (device as ToggleLight).SwitchControl(0);
+            }
+            //鎺у埗寤舵椂鍥炶皟
+            UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () =>
+            {
+                if (Parent == null)
+                {
+                    return;
+                }
+                RemoveUpdateControlDeviceStatuAction();
+                if (sendedControlCommand == false)
+                {
+                    UserCenter.HdlDeviceOtherLogic.Current.ShowStatuTip(R.MyInternationalizationString.FAIL);
+                }
+            });
+        }
 
         /// <summary>
         /// ON
@@ -489,10 +582,10 @@
         private void ON(object sender, MouseEventArgs eventArgs)
         {
             SetONOFFStatu(true);
-            (device.CommonDevice as ToggleLight).SwitchControl(1);
+            (device as ToggleLight).SwitchControl(1);
             //鎺у埗寤舵椂鍥炶皟
             zbGateway.ReportAction += UpdateDeviceControllStatu;
-            DeviceUI.SendCommandDelayAction(device.CommonDevice, () =>
+            UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () =>
             {
                 if (Parent == null)
                 {
@@ -501,7 +594,7 @@
                 RemoveUpdateControlDeviceStatuAction();
                 if (sendedControlCommand == false)
                 {
-                    DeviceUI.ShowStatuTip(R.MyInternationalizationString.FAIL);
+                    UserCenter.HdlDeviceOtherLogic.Current.ShowStatuTip(R.MyInternationalizationString.FAIL);
                 }
             });
         }
@@ -513,10 +606,10 @@
         private void OFF(object sender, MouseEventArgs eventArgs)
         {
             SetONOFFStatu(false);
-            (device.CommonDevice as ToggleLight).SwitchControl(0);
+            (device as ToggleLight).SwitchControl(0);
             //鎺у埗寤舵椂鍥炶皟
             zbGateway.ReportAction += UpdateDeviceControllStatu;
-            DeviceUI.SendCommandDelayAction(device.CommonDevice, () =>
+            UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () =>
             {
                 if (Parent == null)
                 {
@@ -525,7 +618,7 @@
                 RemoveUpdateControlDeviceStatuAction();
                 if (sendedControlCommand == false)
                 {
-                    DeviceUI.ShowStatuTip(R.MyInternationalizationString.FAIL);
+                    UserCenter.HdlDeviceOtherLogic.Current.ShowStatuTip(R.MyInternationalizationString.FAIL);
                 }
             });
         }
@@ -535,19 +628,22 @@
         /// </summary>
         /// <param name="statu"></param>
         private void SetONOFFStatu(bool statu)
-        {
+        {
+            StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + "   ";
             if (statu)
             {
                 OnBtn.IsSelected = true;
                 OffBtn.IsSelected = false;
+                StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.uOpen1);
             }
             else
             {
                 OnBtn.IsSelected = false;
-                OffBtn.IsSelected = true;
+                OffBtn.IsSelected = true;
+                StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.Close);
             }
         }
-        
+
 
         #endregion
 
@@ -563,9 +659,9 @@
             UserView.HomePage.Instance.AddChidren(detailInfo);
             UserView.HomePage.Instance.PageIndex += 1;
             detailInfo.Show(device, room);
-            detailInfo.action = () =>
+            detailInfo.EditAction += (curDev, curRoom) =>
             {
-                Show(device, room);
+                Show(curDev, curRoom);
             };
         }
 
@@ -582,12 +678,12 @@
             //collection
             if ((sender as Button).IsSelected)
             {
-                Shared.Common.Room.CurrentRoom.GetLoveRoom().DeleteDevice(device.FileName);
+                UserCenter.HdlRoomLogic.Current.DeleteLoveDevice(device);
                 (sender as Button).IsSelected = false;
             }
             else
             {
-                Shared.Common.Room.CurrentRoom.GetLoveRoom().AddDevice(device.FileName);
+                UserCenter.HdlRoomLogic.Current.AddLoveDevice(device);
                 (sender as Button).IsSelected = true;
             }
         }
@@ -612,7 +708,7 @@
                 return;
             }
             var tempDevice = (CommonDevice)objValue;
-            if (tempDevice.DeviceEpoint != this.device.CommonDevice.DeviceEpoint || tempDevice.DeviceAddr != this.device.CommonDevice.DeviceAddr)
+            if (tempDevice.DeviceEpoint != this.device.DeviceEpoint || tempDevice.DeviceAddr != this.device.DeviceAddr)
             {
                 //涓嶆槸褰撳墠璁惧鐨勬帹閫侊紝鍒欎笉澶勭悊
                 return;

--
Gitblit v1.8.0