gxc
2019-12-03 a7a6907b3df65db9c4b2bb1237f709db5c985b52
ZigbeeApp/Shared/Phone/UserView/UserHomeView.cs
@@ -5,6 +5,8 @@
using ZigBee.Device;
using Shared.Phone.Device.CommonForm;
using Shared.Phone.UserCenter.DoorLock;
using System.Timers;
using Shared.Phone.Device.DeviceLogic;
namespace Shared.Phone.UserView
{
@@ -78,6 +80,14 @@
        /// floorBtn
        /// </summary>
        private Button floorBtn;
        /// <summary>
        /// timeDic
        /// </summary>
        private Dictionary<string, Timer> timerDic = new Dictionary<string, Timer> { };
        /// <summary>
        /// sceneScrolView
        /// </summary>
        private VerticalScrolViewLayout sceneScrolView ;
        #endregion
        #region ◆ 接口____________________________
@@ -250,6 +260,15 @@
                                                //此属性描述恒温设备正处于哪种模式
                                                ac.currentSystemMode = attriButeList[0].AttriButeData;
                                                ac.LastDateTime = DateTime.Now;
                                                break;
                                            case 4099:
                                                var value = Convert.ToString(attriButeList[0].AttriButeData, 2).PadLeft(16, '0');
                                                var modeStr = value.Substring(value.Length - 5, 5);
                                                for (int j = 0; j < modeStr.Length; j++)
                                                {
                                                    ac.listSupportMode[j] = Convert.ToInt32(modeStr[j]) == 49 ? 1 : 0;
                                                }
                                                break;
                                        }
                                        (rowFL.GetChildren(0) as FunctionMainView).IsSelected = ac.currentSystemMode != 0;
@@ -484,7 +503,7 @@
                        Y = Application.GetRealHeight(248),
                        Width = Application.GetMinRealAverage(449),
                        Height = Application.GetMinRealAverage(478),
                        UnSelectedImagePath = "Item/SelectHouse"
                        UnSelectedImagePath = "Item/SelectHouse.png"
                    };
                    closeBGview.AddChidren(bg);
@@ -492,8 +511,8 @@
                    {
                        X = Application.GetRealWidth(35),
                        Y = Application.GetRealHeight(271),
                        Height = Application.GetRealHeight(449),
                        Width = Application.GetRealWidth(440),
                        Height = Application.GetMinRealAverage(449),
                        Width = Application.GetMinRealAverage(440),
                        Radius = CommonPage.BigFormRadius,
                        BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
                    };
@@ -605,26 +624,25 @@
            //消息
            messageBtn.MouseUpEventHandler += (send, e) =>
            {
                var roomList = new Shared.Phone.Device.Room.RoomManagement();
                HomePage.Instance.AddChidren(roomList);
                HomePage.Instance.PageIndex += 1;
                roomList.Show();
            };
            #endregion
            if (CanBindGateway() == false)
            {
                var roomPageView = new PageLayout()
                var roomPageView = new HorizontalPages()
                {
                    Y = Application.GetRealHeight(302),
                    Width = Application.GetRealWidth(CommonPage.AppRealWidth - CommonPage.XLeft * 2),
                    Height = Application.GetMinRealAverage(roomPageView_Height),
                    Radius = CommonPage.BigFormRadius,
                    Gravity = Gravity.CenterHorizontal,
                    IsShowPoint = false
                    Width = Application.GetRealWidth(CommonPage.AppRealWidth),
                    Height = Application.GetRealHeight(478),
                };
                AddChidren(roomPageView);
                //与屏幕边框的边距
                roomPageView.RowPadding = Application.GetRealWidth(181);
                //两个page之间的间距
                roomPageView.PagePadding = Application.GetRealWidth(69);
                //当前房间
                //Room.CurrentRoom = Room.CurrentRoom == null ? Room.Lists[0] : Room.CurrentRoom;
@@ -632,53 +650,14 @@
                Room.CurrentRoom = rList[0];
                foreach (var room in rList)
                {
                    var roomBackView = new FrameLayout()
                    var roomView = new Device.CommonForm.RoomView(0, 0);
                    roomPageView.AddChidren(roomView);
                    roomView.Init(room);
                    roomView.action += () =>
                    {
                        BackgroundImagePath = room.BackgroundImage
                    };
                    roomPageView.AddChidren(roomBackView);
                    var roomBG = new Button()
                    {
                        UnSelectedImagePath = "Room/HomeBG.png",
                        //UnSelectedImagePath = room.BackgroundImage
                    };
                    roomBackView.AddChidren(roomBG);
                    var roomName = new Button()
                    {
                        X = Application.GetRealWidth(20),
                        Y = Application.GetRealHeight(20),
                        Width = Application.GetRealWidth(500),
                        Height = Application.GetRealHeight(80),
                        Text = room.Name,
                        TextAlignment = TextAlignment.CenterLeft,
                        TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                        TextSize = 18,
                    };
                    roomBackView.AddChidren(roomName);
                    var roomListBtn = new Device.CommonForm.SelectedStatuButton()
                    {
                        X = roomPageView.Width - Application.GetRealWidth(100 + 20),
                        Y = Application.GetRealHeight(20),
                        Width = Application.GetMinRealAverage(100),
                        Height = Application.GetMinRealAverage(100),
                        UnSelectedImagePath = "Item/List.png",
                    };
                    roomBackView.AddChidren(roomListBtn);
                    roomListBtn.MouseUpEventHandler += (send, e) =>
                    {
                        var editRoom = new Device.Room.EditRoom();
                        HomePage.Instance.AddChidren(editRoom);
                        HomePage.Instance.PageIndex += 1;
                        editRoom.Show(room);
                        editRoom.action += () =>
                        {
                            Show();
                        };
                        Show();
                    };
                }
                var functionSceneView = new FrameLayout()
                {
@@ -700,7 +679,8 @@
                    TextColor = ZigbeeColor.Current.GXCTextGrayColor3,
                    SelectedTextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                    TextID = R.MyInternationalizationString.Scence,
                    IsSelected = false
                    IsSelected = true,
                    TextSize=16
                };
                functionSceneView.AddChidren(sceneBtn);
@@ -714,7 +694,8 @@
                    TextColor = ZigbeeColor.Current.GXCTextGrayColor3,
                    SelectedTextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                    TextID = R.MyInternationalizationString.Function,
                    IsSelected = false
                    IsSelected = false,
                    TextSize=14
                };
                functionSceneView.AddChidren(functionBtn);
@@ -733,6 +714,8 @@
                {
                    sceneBtn.IsSelected = false;
                    functionBtn.IsSelected = true;
                    sceneBtn.TextSize = 14;
                    functionBtn.TextSize = 16;
                    RefreshBodyView();
                };
                //选择场景分栏
@@ -740,6 +723,8 @@
                {
                    functionBtn.IsSelected = false;
                    sceneBtn.IsSelected = true;
                    sceneBtn.TextSize = 16;
                    functionBtn.TextSize = 14;
                    RefreshBodyView();
                };
@@ -788,9 +773,10 @@
            var floorFL = new Phone.Device.Category.SelectFloor();
            AddChidren(floorFL);
            floorFL.Init(35, 153);
            floorFL.FloorAction = (floorName) =>
            floorFL.changeFloor = true;
            floorFL.FloorAction = (floorId) =>
            {
                floorBtn.Text = floorName;
                floorBtn.Text = Config.Instance.Home.GetFloorNameById(floorId);
                Show();
            };
        }
@@ -970,21 +956,6 @@
                        deviceVerticalScrolViewLayout.AddChidren(itemView);
                    }
                    //删除设备
                    EventHandler<MouseEventArgs> delEvent = (sender, e) =>
                    {
                        var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ConfirmDelete), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim));
                        alert.Show();
                        alert.ResultEventHandler += (send1, e1) =>
                        {
                            if (e1)
                            {
                                Room.CurrentRoom.DeleteDevice(device.FileName);
                                //RefreshBodyView();
                                deviceVerticalScrolViewLayout.RemoveViewByTag((sender as Button).Tag);
                            }
                        };
                    };
                    //收藏
                    EventHandler<MouseEventArgs> collectionEvent = (sender, e) =>
                    {
@@ -1019,14 +990,14 @@
                            //发送读取状态命令
                            ReadStatus(rollerShade, () =>
                            {
                                rollerShade.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                ReadDeviceAttributeLogic.Instance.SendCurtainStatuComand(device.CommonDevice);
                            });
                        }
                        else
                        {
                            if (CommonPage.ReadDeviceStatuSpan < (DateTime.Now - rollerShade.LastDateTime).TotalSeconds)
                            {
                                rollerShade.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                ReadDeviceAttributeLogic.Instance.SendCurtainStatuComand(device.CommonDevice);
                            }
                        }
                        var lightView = new FunctionMainView(xx, yy);
@@ -1098,6 +1069,7 @@
                        lightView.CardBG.MouseUpEventHandler += (sender, e) =>
                        {
                            CommonPage.Instance.IsDrawerLockMode = true;
                            var rollerShadeControl = new Phone.Device.Curtain.RollerShadeControl();
                            UserView.HomePage.Instance.AddChidren(rollerShadeControl);
                            UserView.HomePage.Instance.PageIndex += 1;
@@ -1123,16 +1095,14 @@
                            //发送读取状态命令
                            ReadStatus(light, () =>
                            {
                                light.ReadOnOffStatus();
                                light.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device.CommonDevice);
                            });
                        }
                        else
                        {
                            if (CommonPage.ReadDeviceStatuSpan < (DateTime.Now - light.LastDateTime).TotalSeconds)
                            {
                                light.ReadOnOffStatus();
                                light.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device.CommonDevice);
                            }
                        }
@@ -1214,6 +1184,7 @@
                        lightView.CardBG.MouseUpEventHandler += (sender, e) =>
                        {
                            CommonPage.Instance.IsDrawerLockMode = true;
                            if (device.CommonDevice.DfunctionType == DeviceFunctionType.A开关)
                            {
                                var lightControl = new Phone.Device.Light.OnOffControl();
@@ -1257,8 +1228,7 @@
                            //发送读取状态命令
                            ReadStatus(airSwitch, () =>
                            {
                                airSwitch.ReadOnOffStatus();
                                airSwitch.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device.CommonDevice);
                            });
                        }
                        else
@@ -1266,8 +1236,7 @@
                            //防止短时间内多次读取设备状态
                            if ((DateTime.Now - airSwitch.LastDateTime).TotalSeconds > CommonPage.ReadDeviceStatuSpan)
                            {
                                airSwitch.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                airSwitch.ReadOnOffStatus();
                                ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device.CommonDevice);
                            }
                        }
@@ -1340,6 +1309,7 @@
                        lightView.CardBG.MouseUpEventHandler += (sender, e) =>
                        {
                            CommonPage.Instance.IsDrawerLockMode = true;
                            var lightControl = new Phone.Device.Light.AirSwitchControl();
                            UserView.HomePage.Instance.AddChidren(lightControl);
                            UserView.HomePage.Instance.PageIndex += 1;
@@ -1364,14 +1334,7 @@
                            //发送读取状态命令
                            ReadStatus(ac, () =>
                            {
                                ac.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                ac.ReadLocalTemperature();
                                ac.ReadCoolingSetpoint();
                                ac.ReadHeatingSetpoint();
                                ac.ReadAutoSetpoint();
                                ac.ReadFanMode();
                                ac.ReadSystemMode();
                                ac.ReadSystemFansSwingMode();
                                ReadDeviceAttributeLogic.Instance.SendACStatuComand(device.CommonDevice);
                            });
                        }
                        else
@@ -1379,14 +1342,7 @@
                            //防止短时间内多次读取设备状态
                            if ((DateTime.Now - ac.LastDateTime).TotalSeconds > CommonPage.ReadDeviceStatuSpan)
                            {
                                ac.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                ac.ReadLocalTemperature();
                                ac.ReadCoolingSetpoint();
                                ac.ReadHeatingSetpoint();
                                ac.ReadAutoSetpoint();
                                ac.ReadFanMode();
                                ac.ReadSystemMode();
                                ac.ReadSystemFansSwingMode();
                                ReadDeviceAttributeLogic.Instance.SendACStatuComand(device.CommonDevice);
                            }
                        }
                        var lightView = new FunctionMainView(xx, yy);
@@ -1457,6 +1413,7 @@
                        lightView.CardBG.MouseUpEventHandler += (sender, e) =>
                        {
                            CommonPage.Instance.IsDrawerLockMode = true;
                            var lightControl = new Phone.Device.AC.ACControl();
                            UserView.HomePage.Instance.AddChidren(lightControl);
                            UserView.HomePage.Instance.PageIndex += 1;
@@ -1480,8 +1437,7 @@
                            //发送读取状态命令
                            ReadStatus(dimmableLight, () =>
                            {
                                dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                dimmableLight.ReadOnOffStatus();
                                ReadDeviceAttributeLogic.Instance.SendDimmableLightStatuComand(device.CommonDevice);
                            });
                        }
                        else
@@ -1489,8 +1445,7 @@
                            //防止短时间内多次读取设备状态
                            if ((DateTime.Now - dimmableLight.LastDateTime).TotalSeconds > CommonPage.ReadDeviceStatuSpan)
                            {
                                dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                                dimmableLight.ReadOnOffStatus();
                                ReadDeviceAttributeLogic.Instance.SendDimmableLightStatuComand(device.CommonDevice);
                            }
                        }
@@ -1572,6 +1527,7 @@
                        lightView.CardBG.MouseUpEventHandler += (sender, e) =>
                        {
                            CommonPage.Instance.IsDrawerLockMode = true;
                            var dimmableLightControl = new Phone.Device.Light.DimmableLightControl();
                            UserView.HomePage.Instance.AddChidren(dimmableLightControl);
                            UserView.HomePage.Instance.PageIndex += 1;
@@ -1589,20 +1545,6 @@
                        if (dimmableLight.Gateway == null)
                        {
                            continue;
                        }
                        if (dimmableLight.Gateway.IsVirtual)
                        {
                            ReadStatus(dimmableLight, () =>
                            {
                                dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                            });
                        }
                        else
                        {
                            if ((DateTime.Now - dimmableLight.LastDateTime).TotalSeconds > CommonPage.ReadDeviceStatuSpan)
                            {
                                dimmableLight.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
                            }
                        }
                        var lightView = new FunctionMainView(xx, yy);
@@ -1626,6 +1568,7 @@
                        lightView.CardBG.MouseUpEventHandler += (sender, e) =>
                        {
                            CommonPage.Instance.IsDrawerLockMode = true;
                            var userDoorLockPage = new UserDoorLockPage(Room.CurrentRoom, device);
                            HomePage.Instance.AddChidren(userDoorLockPage);
                            HomePage.Instance.PageIndex += 1;
@@ -1707,7 +1650,7 @@
            }
            else
            {
                var sceneScrolView = new VerticalScrolViewLayout { };
                sceneScrolView = new VerticalScrolViewLayout { };
                functionSceneBodyView.AddChidren(sceneScrolView);
                for (int i = 0; i < sceneList.Count; i++)
                {
@@ -1731,108 +1674,73 @@
                    var sceneView = new SceneMainView(xx, yy);
                    itemView.AddChidren(sceneView);
                    sceneView.Init();
                    sceneView.SetSceneNameText(scene.Name);
                    sceneView.SetIcon($"SceneIcon/{i}.png");
                    sceneView.SetCollect(Common.Room.CurrentRoom.GetLoveRoom().SceneUIFilePathList.Contains(scene.FileName));
                    if (scene.SceneDelayTime == 0)
                    {
                        sceneView.SetTimeImage();
                    }
                    else
                    {
                        sceneView.SetTimeText(CommonFormResouce.GetTimeString(scene.SceneDelayTime));
                    }
                    sceneView.TimeButton.MouseUpEventHandler += (sender, e) =>
                    {
                        var timeSelect = new SelectTime();
                        CommonPage.Instance.AddChidren(timeSelect);
                        timeSelect.TempTime = scene.DelayTime;
                        timeSelect.Init();
                        timeSelect.TimeAction = (t) =>
                        {
                            scene.SceneDelayTime = t;
                            if (t > 0)
                            {
                                sceneView.SetTimeText(CommonFormResouce.GetTimeString(scene.SceneDelayTime));
                            }
                            else
                            {
                                sceneView.SetTimeImage();
                            }
                        };
                    };
                    //调用场景
                    EventHandler<MouseEventArgs> sceneUpHandler = async (sender, e) =>
                    {
                        //1成功 0失败
                        //后面补上相关提示
                        // Error参数含义
                        //<para>1:网关无法解析命令数据。</para>
                        //<para>2:协调器正在升级或备份/恢复数据
                        //<para>3:操作设备/组/场景不存在</para>
                        //<para>4:其他错误</para>
                        //<para>5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)</para>
                        var sceneOpenAllData = await ZigBee.Device.Scene.ControlSceneAsync(scene.Id, scene.SceneDelayTime);
                        if (sceneOpenAllData == null || sceneOpenAllData.sceneOpenData == null)
                        {
                            return;
                        }
                        if (sceneOpenAllData.sceneOpenData.Result == 0)
                        {
                            if (sceneOpenAllData.errorResponData == null)
                            {
                                return;
                            }
                            CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ControlSceneFail);
                        }
                    };
                    //收藏
                    EventHandler<MouseEventArgs> collectionEvent = (sender, e) =>
                    {
                        (sender as Button).IsSelected = !(sender as Button).IsSelected;
                        if ((sender as Button).IsSelected)
                        {
                            //scene.IsCollected = true;
                            Room.CurrentRoom.GetLoveRoom().AddScene(scene);
                        }
                        else
                        {
                            //scene.IsCollected = false;
                            Room.CurrentRoom.GetLoveRoom().RemoveScene(scene);
                        }
                        scene.Save();
                        //if ((sender as Button).IsSelected)
                        //{
                        //    scene.Collect(false);
                        //    (sender as Button).IsSelected = false;
                        //}
                        //else
                        //{
                        //    scene.Collect(true);
                        //    (sender as Button).IsSelected = true;
                        //}
                        //scene.Save();
                        //if (Room.CurrentRoom.IsLove)
                        //{
                        //    RefreshBodyView();
                        //}
                    };
                    sceneView.CollectButton.MouseUpEventHandler += collectionEvent;
                    sceneView.MouseUpEventHandler += sceneUpHandler;
                    sceneView.SceneIcon.MouseUpEventHandler += sceneUpHandler;
                    sceneView.SceneNameButton.MouseUpEventHandler += sceneUpHandler;
                    sceneView.Init(scene);
                }
                GetDelayScene(sceneScrolView);
            }
        }
        /// <summary>
        /// GetDelayScene
        /// </summary>
        /// <param name="scrolViewLayout"></param>
        private void GetDelayScene(VerticalScrolViewLayout scrolViewLayout)
        {
            new System.Threading.Thread(async () =>
            {
                var catDelaySceneResponseAllData = await Scene.CatDelaySceneAsync();
                if (catDelaySceneResponseAllData == null)
                {
                    return;
                }
                var catDelaySceneResponseData = catDelaySceneResponseAllData.catDelaySceneResponseData;
                if (catDelaySceneResponseData == null || catDelaySceneResponseData.DelayScenesList.Count == 0)
                {
                    return;
                }
                var delayList = catDelaySceneResponseData.DelayScenesList;
                Application.RunOnMainThread(() =>
                {
                    for (int i = 0; scrolViewLayout != null && i < scrolViewLayout.ChildrenCount; i++)
                    {
                        var iView = scrolViewLayout.GetChildren(i) as FrameLayout;
                        for (int j = 0; iView != null && j < iView.ChildrenCount; j++)
                        {
                            var sceneView = iView.GetChildren(j) as SceneMainView;
                            foreach (var delayScenesListResponseInfo in delayList)
                            {
                                if (delayScenesListResponseInfo.ScenesId == sceneView.scene.Id)
                                {
                                    var times = delayScenesListResponseInfo.RemainTime;
                                    sceneView.scene.RemainTime = times;
                                    new System.Threading.Thread(() =>
                                    {
                                        while (times > 0)
                                        {
                                            System.Threading.Thread.Sleep(1000);
                                            Application.RunOnMainThread(() =>
                                            {
                                                sceneView.SetTimeText(CommonFormResouce.GetTimeString(times));
                                            });
                                            times -= 1;
                                        }
                                        Application.RunOnMainThread(() =>
                                        {
                                            sceneView.SetTimeImage();
                                        });
                                    })
                                    { IsBackground = true }.Start();
                                    break;
                                }
                            }
                        }
                    }
                });
            })
            { IsBackground = true }.Start();
        }
        #endregion