陈嘉乐
2020-07-10 48ba446936b51fffafa7c3600c0dadc6ac0e8c20
ZigbeeApp/Shared/Phone/Category/CategoryMainForm.cs
@@ -54,6 +54,7 @@
        /// </summary>
        public CategoryMainForm()
        {
            this.FormID = "CategoryMainForm";
            BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor;
            instance = this;
        }
@@ -131,7 +132,7 @@
            //应该是body吧
            this.bodyFrameLayout = new FrameLayout();
            bodyFrameLayout.Y = topFrameLayout.Bottom;
            bodyFrameLayout.Height = Application.GetRealHeight(1549);
            bodyFrameLayout.Height = this.Height - topFrameLayout.Bottom;
            bodyFrameLayout.BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor;
            this.AddChidren(bodyFrameLayout);
@@ -161,8 +162,8 @@
                    floors.changeFloor = true;
                    floors.FloorAction += (floorId) =>
                    {
                        btnFloorName.Text = Config.Instance.Home.GetFloorNameById(floorId);
                        HdlRoomLogic.Current.CurrentRoom = HdlRoomLogic.Current.GetLoveRoom();
                        btnFloorName.Text = HdlResidenceLogic.Current.GetFloorNameById(floorId);
                        HdlRoomLogic.Current.NowCategoryRoom = HdlRoomLogic.Current.GetLoveRoom();
                        //刷新bodyView
                        this.RefreshBodyView();
                    };
@@ -182,7 +183,7 @@
            //目前不知道郭雪城的这个具体放在哪个的位置
            this.functionSceneAutoBodyView = new FrameLayout();
            functionSceneAutoBodyView.Y = frameSwitchBack.Bottom;
            functionSceneAutoBodyView.Height = Application.GetRealHeight(1423);
            functionSceneAutoBodyView.Height = bodyFrameLayout.Height - frameSwitchBack.Bottom;
            bodyFrameLayout.AddChidren(functionSceneAutoBodyView);
            //场景,功能,自动化的切换控件
@@ -248,7 +249,8 @@
                //自动化
                else if (UserCenterResourse.ResidenceOption.CategoryPageSwitchIndex == 2)
                {
                    this.ShowAutotion();
                    //自动化功能代码入口
                    Device.Logic.SkipView.ShowAutotionView(functionSceneAutoBodyView);
                    //隐藏楼层
                    floorVisible = false;
                    //显示右上角的加号
@@ -275,16 +277,21 @@
        {
            //当前楼层的全部房间
            var lisrRoom = HdlRoomLogic.Current.GetRoomsByCurrentFloorIdAppendLoveRoom();
            if (HdlRoomLogic.Current.NowCategoryRoom == null)
            {
                //设置第一个为初始房间
                HdlRoomLogic.Current.NowCategoryRoom = lisrRoom[0];
            }
            //房间菜单控件
            var roomSwitchContr = new RoomDeviceGroupMenuControl(lisrRoom);
            roomSwitchContr.Y = Application.GetRealHeight(-55);
            this.functionSceneAutoBodyView.AddChidren(roomSwitchContr);
            //设置初始值
            roomSwitchContr.SetDefultIndex(HdlRoomLogic.Current.CurrentRoom.Id);
            roomSwitchContr.SetDefultIndex(HdlRoomLogic.Current.NowCategoryRoom.Id);
            //选择事件
            roomSwitchContr.SelectRoomEvent += (selectRoom) =>
            {
                HdlRoomLogic.Current.CurrentRoom = selectRoom;
                HdlRoomLogic.Current.NowCategoryRoom = selectRoom;
                //场景
                if (UserCenterResourse.ResidenceOption.CategoryPageSwitchIndex == 0)
                {
@@ -333,7 +340,9 @@
            var dicGroupDevice = this.GetAllGroupDevice(room);
            if (dicGroupDevice.Count == 0)
            {
                this.ShowNoFunctionTip();
                //没有功能{0}请在个人中心--设备管理处添加
                string[] arryMsg = Language.StringByID(R.MyInternationalizationString.NoFunction).Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries);
                this.ShowNotDataImage(functionSceneBodyView, arryMsg);
                return;
            }
@@ -430,35 +439,6 @@
            }
        }
        /// <summary>
        /// 提示没有功能
        /// </summary>
        private void ShowNoFunctionTip()
        {
            var noFunction = new Button()
            {
                Y = Application.GetRealHeight(320),
                Width = Application.GetMinRealAverage(757),
                Height = Application.GetMinRealAverage(435),
                UnSelectedImagePath = "Item/NoFunction.png",
                Gravity = Gravity.CenterHorizontal
            };
            functionSceneBodyView.AddChidren(noFunction);
            var noFunctionTip = new Button()
            {
                Y = noFunction.Bottom + Application.GetRealHeight(32),
                Height = Application.GetRealHeight(200),
                Width = Application.GetRealWidth(700),
                Gravity = Gravity.CenterHorizontal,
                Text = Language.StringByID(R.MyInternationalizationString.NoFunction).Replace("{\\r\\n}", "\r\n"),
                TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
                TextAlignment = TextAlignment.Center,
                IsMoreLines = true
            };
            functionSceneBodyView.AddChidren(noFunctionTip);
        }
        #endregion
        #region ■ 初始化设备列表控件_________________
@@ -506,54 +486,69 @@
                    //窗帘
                    if (device.Type == DeviceType.WindowCoveringDevice)
                    {
                        cardContr = new Controls.DeviceCurtainRowControl(listView.rowSpace / 2);
                        cardContr = new Controls.DeviceCurtainRowControl();
                    }
                    //继电器
                    else if (device.Type == DeviceType.OnOffOutput)
                    {
                        cardContr = new Controls.DeviceRelayRowControl(listView.rowSpace / 2);
                        cardContr = new Controls.DeviceRelayRowControl();
                    }
                    //空气开关
                    else if (device.Type == DeviceType.AirSwitch)
                    {
                        cardContr = new Controls.DeviceAirSwitchRowControl(listView.rowSpace / 2);
                        cardContr = new Controls.DeviceAirSwitchRowControl();
                    }
                    //空调
                    else if (device.Type == DeviceType.Thermostat)
                    {
                        cardContr = new Controls.DeviceAcRowControl(listView.rowSpace / 2);
                        cardContr = new Controls.DeviceAcRowControl();
                    }
                    // 新风
                    else if (device.Type == DeviceType.FreshAir)
                    {
                        cardContr = new Controls.DeviceFreshAirRowControl();
                    }
                    // PM2.5
                    else if (device.Type == DeviceType.PMSensor)
                    {
                        cardContr = new Controls.DevicePmSensorRowControl();
                    }
                    //彩灯(调光器)
                    else if (device.Type == DeviceType.DimmableLight)
                    {
                        cardContr = new Controls.DeviceColorLightRowControl(listView.rowSpace / 2);
                        cardContr = new Controls.DeviceColorLightRowControl();
                    }
                    //传感器
                    else if (device.Type == DeviceType.IASZone)
                    {
                        cardContr = new Controls.DeviceSensorRowControl(listView.rowSpace / 2);
                        cardContr = new Controls.DeviceSensorRowControl();
                    }
                    //温湿度
                    else if (device.Type == DeviceType.TemperatureSensor)
                    {
                        cardContr = new Controls.DeviceTemperatureRowControl(listView.rowSpace / 2);
                        cardContr = new Controls.DeviceTemperatureRowControl();
                    }
                    //门锁
                    else if (device.Type == DeviceType.DoorLock)
                    {
                        cardContr = new Controls.DeviceDoorLockRowControl(listView.rowSpace / 2);
                        cardContr = new Controls.DeviceDoorLockRowControl();
                    }
                    //色温灯
                    else if (device.Type == DeviceType.ColorTemperatureLight)
                    {
                        cardContr = new Controls.DeviceColorTemperatureRowControl();
                    }
                    //无法识别
                    else
                    {
                        cardContr = new Controls.DeviceRowCommon(listView.rowSpace / 2);
                        cardContr = new Controls.DeviceRowCommon();
                        //没有状态功能
                        cardContr.hadStatuFunction = false;
                    }
                    cardContr.chidrenYaxis = listView.rowSpace / 2;
                    //初始化卡片
                    listView.AddChidren(cardContr);
                    cardContr.InitControl(device);
                    cardContr.InitControl(device, HdlRoomLogic.Current.NowCategoryRoom);
                    //控件记录到缓存中
                    this.dicDeviceRowControl[LocalDevice.Current.GetDeviceMainKeys(device)] = cardContr;
                    //加缓存,然后发命令
@@ -604,6 +599,60 @@
        /// <param name="room"></param>
        private void RefreshSceneView(Room room)
        {
            //主人,管理员专用刷新控件
            VerticalListRefreshControl listview1 = null;
            //成员专用不能刷新的控件
            VerticalListControl listview2 = null;
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
                //主人,管理员专用刷新控件
                listview1 = new VerticalListRefreshControl();
                functionSceneBodyView.AddChidren(listview1);
                //下拉刷新
                listview1.BeginHeaderRefreshingAction += () =>
                {
                    //如果当前是虚拟住宅,则只给个特效
                    if (Common.Config.Instance.Home.IsVirtually == true)
                    {
                        HdlThreadLogic.Current.RunThread(() =>
                        {
                            System.Threading.Thread.Sleep(1500);
                            HdlThreadLogic.Current.RunMain(() =>
                            {
                                listview1.EndHeaderRefreshing();
                            });
                        });
                        return;
                    }
                    HdlThreadLogic.Current.RunThread(() =>
                    {
                        //从网关刷新场景列表
                        bool result = HdlSceneLogic.Current.RefreshSceneUIList();
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            listview1.EndHeaderRefreshing();
                            if (result == true)
                            {
                                //在外面清空(特效的问题)
                                this.functionSceneBodyView.RemoveAll();
                                HdlThreadLogic.Current.RunMainInThread(() =>
                                {
                                    //刷新场景分支控件
                                    this.RefreshSceneView(room);
                                });
                            }
                        });
                    });
                };
            }
            else
            {
                //成员专用不能刷新的控件
                listview2 = new VerticalListControl();
                functionSceneBodyView.AddChidren(listview2);
            }
            var listScene = new List<SceneUI>();
            foreach (var sceneId in room.ListSceneId)
            {
@@ -615,26 +664,17 @@
            }
            if (listScene.Count == 0)
            {
                this.ShowNoSceneTip();
                //在滑动控件里面添加一个桌布
                var frameTable = new FrameLayout();
                listview1?.AddChidren(frameTable);
                listview2?.AddChidren(frameTable);
                //没有场景{0}请点击右上角添加
                string[] arryMsg = Language.StringByID(R.MyInternationalizationString.NoScene).Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries);
                this.ShowNotDataImage(frameTable, arryMsg);
                return;
            }
            var dicSceneContr = new Dictionary<int, SceneCategoryView>();
            //主人,管理员专用刷新控件
            VerticalListRefreshControl listview1 = null;
            //成员专用不能刷新的控件
            VerticalListControl listview2 = null;
            //if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            //{
            //    listview1 = new VerticalListRefreshControl();
            //    functionSceneBodyView.AddChidren(listview1);
            //}
            //else
            {
                listview2 = new VerticalListControl();
                functionSceneBodyView.AddChidren(listview2);
            }
            foreach (var scene in listScene)
            {
                //场景卡片控件
@@ -753,36 +793,6 @@
            });
        }
        /// <summary>
        /// 显示没有场景
        /// </summary>
        private void ShowNoSceneTip()
        {
            var noFunction = new Button()
            {
                Y = Application.GetRealHeight(320),
                Width = Application.GetMinRealAverage(757),
                Height = Application.GetMinRealAverage(435),
                UnSelectedImagePath = "Item/NoFunction.png",
                Gravity = Gravity.CenterHorizontal
            };
            functionSceneBodyView.AddChidren(noFunction);
            var noScenceTip = new Button()
            {
                Y = noFunction.Bottom + Application.GetRealHeight(32),
                Height = Application.GetRealHeight(200),
                Width = Application.GetRealWidth(700),
                Gravity = Gravity.CenterHorizontal,
                Text = Language.StringByID(R.MyInternationalizationString.NoScene).Replace("{\\r\\n}", "\r\n"),
                TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
                TextAlignment = TextAlignment.Center,
                IsMoreLines = true
            };
            functionSceneBodyView.AddChidren(noScenceTip);
        }
        #endregion
        #region ■ 一般设备状态上报___________________
@@ -793,7 +803,7 @@
        private void AddNormalDeviceReportEvent()
        {
            //设备属性上报(缓存的修改交由 HdlGatewayReceiveLogic 处理)
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("UserHomeViewDeviceStatus", ReceiveComandDiv.A设备属性上报, (report) =>
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("CategoryMainFormDeviceStatus", ReceiveComandDiv.A设备属性上报, (report) =>
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
@@ -803,18 +813,16 @@
                    {
                        //刷新卡片信息
                        var locadevice = LocalDevice.Current.GetDevice(mainKeys);
                        if (report.DeviceStatusReport.CluterID == 513 && report.DeviceStatusReport.AttriBute[0].AttributeId == 28)
                        {
                            //空调是特殊的,它的开关是属性上报来着.已经接收到网关的反馈
                            this.dicDeviceRowControl[mainKeys].SetHadGetResponeResultStatu();
                        }
                        //已经接收到网关的反馈 2020.05.09:删除Ack主题
                        this.dicDeviceRowControl[mainKeys].SetHadGetResponeResultStatu();
                        //刷新控件
                        this.dicDeviceRowControl[mainKeys].RefreshControlInfo(locadevice);
                    }
                }, ShowErrorMode.NO);
            });
            //设备在线上报(缓存的修改交由 HdlGatewayReceiveLogic 处理)
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("UserHomeViewDeviceOnline", ReceiveComandDiv.A设备在线上报, (report) =>
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("CategoryMainFormDeviceOnline", ReceiveComandDiv.A设备在线上报, (report) =>
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
@@ -822,25 +830,9 @@
                    if (this.dicDeviceRowControl.ContainsKey(mainKeys) == true)
                    {
                        //刷新卡片状态
                        this.dicDeviceRowControl[mainKeys].SetRowOnlineStatu(report.IsOnline == 1);
                        bool bolOnline = LocalDevice.Current.CheckDeviceIsOnline(report);
                        this.dicDeviceRowControl[mainKeys].SetRowOnlineStatu(bolOnline);
                        return;
                    }
                }, ShowErrorMode.NO);
            });
            //设备控制反馈上报
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("UserHomeViewDeviceRespone", ReceiveComandDiv.A节点控制反馈, (report) =>
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    string mainKeys = LocalDevice.Current.GetDeviceMainKeys(report);
                    if (this.dicDeviceRowControl.ContainsKey(mainKeys) == true)
                    {
                        //设备卡片
                        var deviceCardContr = this.dicDeviceRowControl[mainKeys];
                        //已经接收到网关的反馈
                        deviceCardContr.SetHadGetResponeResultStatu();
                    }
                }, ShowErrorMode.NO);
@@ -857,7 +849,7 @@
        private void AddSensorDeviceReportEvent()
        {
            //传感器上报(缓存的修改交由 HdlGatewayReceiveLogic 处理)
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("UserHomeViewSensor", ReceiveComandDiv.A传感器上报, (report) =>
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("CategoryMainFormSensor", ReceiveComandDiv.A传感器上报, (report) =>
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
@@ -911,7 +903,7 @@
                    string path1 = string.Empty;
                    string path2 = string.Empty;
                    //获取图片
                    LocalDevice.Current.GetDeviceObjectIcon(typeInfo.ConcreteType, ref path1, ref path2);
                    LocalDevice.Current.GetDeviceFunctionTypeMenuIcon(typeInfo.ConcreteType, ref path1, ref path2);
                    dic[typeInfo.BeloneTextId].IconPath = path1;
                    dic[typeInfo.BeloneTextId].IconPathSelected = path2;
                    dic[typeInfo.BeloneTextId].TextId = typeInfo.BeloneTextId;
@@ -932,6 +924,9 @@
        {
            //把静态变量的这个东西置空
            instance = null;
            HdlGatewayReceiveLogic.Current.RemoveEvent("CategoryMainFormDeviceStatus");
            HdlGatewayReceiveLogic.Current.RemoveEvent("CategoryMainFormDeviceOnline");
            HdlGatewayReceiveLogic.Current.RemoveEvent("CategoryMainFormSensor");
            base.CloseFormBefore();
        }
@@ -994,18 +989,6 @@
            /// 设备回路主键
            /// </summary>
            public List<string> listDeviceKeys = new List<string>();
        }
        #endregion
        #region ◆ 自动化__________________________
        /// <summary>
        /// 自动化功能代码入口
        /// </summary>
        private void ShowAutotion()
        {
            Shared.Phone.Device.Logic.SkipView.ShowAutotionView(functionSceneAutoBodyView);
        }
        #endregion