From a4924de3136289d10cabbf2f61a228387d44ded7 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期四, 07 十一月 2019 13:48:36 +0800
Subject: [PATCH] Merge branch 'dev-tzy' into DEV_GXC

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorTargetSelectForm.cs |  417 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 417 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorTargetSelectForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorTargetSelectForm.cs
new file mode 100755
index 0000000..46cdbef
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorTargetSelectForm.cs
@@ -0,0 +1,417 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shared.Phone.UserCenter.DevicePirSensor
+{
+    /// <summary>
+    /// PIR浼犳劅鍣ㄧ殑瑙﹀彂鐩爣閫夋嫨鐣岄潰
+    /// </summary>
+    public class PirSensorTargetSelectForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 缁撴潫閫夋嫨鐨勪簨浠�(璁惧涓婚敭)
+        /// </summary>
+        public Action<List<string>> FinishSelectEvent = null;
+        /// <summary>
+        /// 褰撳墠閫夋嫨鐨勬ゼ灞侷D
+        /// </summary>
+        private string nowSelectFloorId = string.Empty;
+        /// <summary>
+        /// 妗屽竷鎺т欢
+        /// </summary>
+        private FrameLayout frameTable = null;
+        /// <summary>
+        /// 鎴块棿瀵硅薄
+        /// </summary>
+        private Dictionary<string, List<Common.Room>> dicRoom = new Dictionary<string, List<Common.Room>>();
+        /// <summary>
+        /// 宸茬粡瀛樺湪鐨勭粦瀹氳澶�
+        /// </summary>
+        private List<string> listEsixtDevice = new List<string>();
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        /// <param name="i_listEsixtDevice">瀛樺湪鐨勮澶�</param>
+        public void ShowForm(List<string> i_listEsixtDevice)
+        {
+            this.listEsixtDevice.AddRange(i_listEsixtDevice);
+
+            //璁剧疆澶撮儴淇℃伅
+            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uTriggerTarget));
+
+            //鍒濆鍖栧彸涓婅鐨勬帶浠�
+            this.InitTopRightMenuControl();
+
+            //鍒濆鍖栦腑閮ㄤ俊鎭�
+            this.InitMiddleFrame();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            //娓呯┖bodyFrame
+            this.ClearBodyFrame();
+
+            //鎴块棿鐨勫鍣ㄦ帶浠�
+            var frameBack = new FrameLayout();
+            frameBack.Height = Application.GetRealHeight(204);
+            bodyFrameLayout.AddChidren(frameBack);
+            var scrolContr = new HorizontalScrolViewLayout();
+            scrolContr.Gravity = Gravity.CenterVertical;
+            scrolContr.Height = frameBack.Height;
+            frameBack.AddChidren(scrolContr);
+
+            //妗屽竷鎺т欢
+            this.frameTable = new FrameLayout();
+            frameTable.Y = frameBack.Bottom;
+            frameTable.Height = bodyFrameLayout.Height - frameBack.Height;
+            bodyFrameLayout.AddChidren(frameTable);
+
+            HdlThreadLogic.Current.RunMainInThread(() =>
+            {
+                if (dicRoom.ContainsKey(nowSelectFloorId) == true && dicRoom[nowSelectFloorId].Count > 0)
+                {
+                    //鍒濆鍖栨埧闂存帶浠�
+                    this.InitRoomControl(scrolContr, dicRoom[nowSelectFloorId]);
+
+                    //纭畾鎸夐挳
+                    var btnOk = new BottomClickButton();
+                    btnOk.TextID = R.MyInternationalizationString.uConfirm1;
+                    bodyFrameLayout.AddChidren(btnOk);
+                    btnOk.ButtonClickEvent += (sender, e) =>
+                    {
+                        //璋冪敤鍥炶皟鍑芥暟
+                        this.FinishSelectEvent?.Invoke(listEsixtDevice);
+                        //鐣岄潰鍏抽棴
+                        this.CloseForm();
+                    };
+                }
+                else
+                {
+                    //娌℃湁鍙互娣诲姞鐨勭洰鏍�
+                    this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotHadAddTarget));
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖栧彸涓婅鐨勬帶浠禵________________
+
+        /// <summary>
+        /// 鍒濆鍖栧彸涓婅鐨勬帶浠�
+        /// </summary>
+        private void InitTopRightMenuControl()
+        {
+            //鎴块棿鍒嗙粍
+            foreach (var room in Common.Room.Lists)
+            {
+                //妫�娴嬭鎴块棿鑳藉惁鏄剧ず
+                if (this.CheckCanShowRow(room) == false)
+                {
+                    continue;
+                }
+                if (dicRoom.ContainsKey(room.FloorId) == false)
+                {
+                    dicRoom[room.FloorId] = new List<Common.Room>();
+                }
+                dicRoom[room.FloorId].Add(room);
+            }
+            if (dicRoom.Count == 0)
+            {
+                //榛樿涓�涓┖鐨勪笢瑗�
+                dicRoom[string.Empty] = new List<Common.Room>();
+            }
+
+            //鑾峰彇妤煎眰
+            var dicFloor = Common.Room.CurrentRoom.GetFloorSortList();
+            if (dicFloor.Count == 0)
+            {
+                return;
+            }
+            var btnIconContr = new MostRightIconControl(69, 69);
+            btnIconContr.UnSelectedImagePath = "Item/Drop_Down.png";
+            topFrameLayout.AddChidren(btnIconContr);
+            btnIconContr.InitControl();
+
+            var btnFloor = new NormalViewControl(300, 69, true);
+            btnFloor.Gravity = Gravity.CenterVertical;
+            btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(300);
+            btnFloor.TextAlignment = TextAlignment.CenterRight;
+            topFrameLayout.AddChidren(btnFloor);
+
+            foreach (var floorId in dicFloor.Keys)
+            {
+                //绗竴涓ゼ灞�
+                this.nowSelectFloorId = floorId;
+                btnFloor.Text = dicFloor[floorId];
+                break;
+            }
+
+            btnIconContr.ButtonClickEvent += (sender, e) =>
+            {
+                //妤煎眰鑿滃崟
+                var contr = new TopRightMenuControl(dicFloor.Count, 449, Language.StringByID(R.MyInternationalizationString.SelectFloor));
+                foreach (var floorId in dicFloor.Keys)
+                {
+                    contr.AddRowMenu(dicFloor[floorId], "Floor/Floor.png", "Floor/FloorSelected.png", () =>
+                    {
+                        //璁板綍璧烽�夋嫨鐨処D
+                        this.nowSelectFloorId = floorId;
+                        btnFloor.Text = dicFloor[this.nowSelectFloorId];
+                        //鍒濆鍖栦腑閮ㄤ俊鎭�
+                        this.InitMiddleFrame();
+                    });
+                }
+            };
+        }
+        #endregion
+
+        #region 鈻� 鍒濆鍖栨埧闂存帶浠禵____________________
+
+        /// <summary>
+        /// 鍒濆鍖栨埧闂存帶浠�
+        /// </summary>
+        /// <param name="scrolContr">瀹瑰櫒</param>
+        /// <param name="listRoom">鎴块棿鍒楄〃</param>
+        private void InitRoomControl(HorizontalScrolViewLayout scrolContr, List<Common.Room> listRoom)
+        {
+            string oldRoomId = listRoom[0].Id;
+            FrameLayoutControl oldFrameBack = null;
+            NormalViewControl oldBtnText = null;
+
+            //寮勪釜绌虹殑杩涘幓鍗犱綅缃�
+            var frameTemp = new FrameLayout();
+            frameTemp.Height = scrolContr.Height;
+            frameTemp.Width = ControlCommonResourse.XXLeft / 2;
+            scrolContr.AddChidren(frameTemp);
+
+            for (int i = 0; i < listRoom.Count; i++)
+            {
+                var room = listRoom[i];
+                //甯﹀浘鐗囩殑
+                var frameBack = new FrameLayoutControl();
+                frameBack.UseClickStatu = false;
+                frameBack.Gravity = Gravity.Center;
+                frameBack.Height = Application.GetRealHeight(159);
+                frameBack.Width = Application.GetRealWidth(255);
+                if (i == 0)
+                {
+                    frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
+                    oldFrameBack = frameBack;
+                }
+                else
+                {
+                    frameBack.BackgroundImagePath = "Item/RoomIconBackground.png";
+                }
+                scrolContr.AddChidren(frameBack);
+                //鏂囧瓧
+                var btnText = new NormalViewControl(frameBack.Width - (int)(frameBack.Height * 0.47), frameBack.Height, false);
+                btnText.Gravity = Gravity.CenterHorizontal;
+                btnText.Text = room.Name;
+                btnText.TextSize = 12;
+                btnText.TextAlignment = TextAlignment.Center;
+                if (i == 0)
+                {
+                    btnText.TextColor = UserCenterColor.Current.White;
+                    oldBtnText = btnText;
+                }
+                else
+                {
+                    btnText.TextColor = UserCenterColor.Current.TextGrayColor1;
+                }
+                frameBack.AddChidren(btnText, ChidrenBindMode.BindEventOnly);
+
+                frameBack.ButtonClickEvent += (sender, e) =>
+                {
+                    if (oldRoomId == room.Id)
+                    {
+                        //鍚屼竴涓笢瑗�
+                        return;
+                    }
+                    oldRoomId = room.Id;
+
+                    //鐘舵�佸彉鏇�
+                    frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
+                    btnText.TextColor = UserCenterColor.Current.White;
+
+                    oldFrameBack.BackgroundImagePath = "Item/RoomIconBackground.png";
+                    oldBtnText.TextColor = UserCenterColor.Current.TextGrayColor1;
+                    oldFrameBack = frameBack;
+                    oldBtnText = btnText;
+                    //鍒濆鍖栬澶囪
+                    this.InitDeviceControl(room);
+                };
+            }
+            //鍒濆鍖栬澶囪
+            this.InitDeviceControl(listRoom[0]);
+        }
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖栬澶囨帶浠禵____________________
+
+        /// <summary>
+        /// 鍒濆鍖栬澶囨帶浠�
+        /// </summary>
+        /// <param name="room"></param>
+        private void InitDeviceControl(Common.Room room)
+        {
+            //鍏堟竻绌�
+            this.frameTable.RemoveAll();
+
+            var frameBack = new FrameLayout();
+            frameBack.Height = Application.GetRealHeight(11);
+            frameBack.BackgroundColor = UserCenterColor.Current.White;
+            frameTable.AddChidren(frameBack);
+
+            var listView = new VerticalListControl(12);
+            listView.Y = frameBack.Bottom;
+            listView.Height = frameTable.Height - frameBack.Height;
+            listView.BackgroundColor = UserCenterColor.Current.White;
+            frameTable.AddChidren(listView);
+
+            var listDevice = new List<ZigBee.Device.CommonDevice>();
+            foreach (var deviceUi in room.DeviceUIList)
+            {
+                var device = deviceUi.CommonDevice;
+                //妫�娴嬭澶�
+                if (this.CheckCanShowDevice(device) == true)
+                {
+                    listDevice.Add(device);
+                }
+            }
+
+            for (int i = 0; i < listDevice.Count; i++)
+            {
+                var device = listDevice[i];
+                string mainKey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+
+                var rowDevice = new FrameRowControl(listView.rowSpace / 2);
+                listView.AddChidren(rowDevice);
+                //鍥炬爣
+                var btnIcon = rowDevice.AddLeftIcon(81);
+                Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
+                //璁惧鍚嶇О
+                var btnName = rowDevice.AddLeftCaption(Common.LocalDevice.Current.GetDeviceEpointName(device), 600);
+                btnName.TextSize = 15;
+                //閫夋嫨
+                var btnSelect = rowDevice.AddMostRightEmptyIcon(58, 58);
+                if (listEsixtDevice.Contains(mainKey) == false)
+                {
+                    btnSelect.Visible = false;
+                }
+                btnSelect.UnSelectedImagePath = "Item/ItemSelected.png";
+                if (i != listDevice.Count - 1)
+                {
+                    //搴曠嚎
+                    rowDevice.AddBottomLine();
+                }
+
+                rowDevice.ButtonClickEvent += (sender, e) =>
+                {
+                    btnSelect.Visible = !btnSelect.Visible;
+                    if (btnSelect.Visible == true)
+                    {
+                        listEsixtDevice.Add(mainKey);
+                    }
+                    else
+                    {
+                        listEsixtDevice.Remove(mainKey);
+                    }
+                };
+            }
+            listDevice = null;
+            //璋冩暣鎺т欢鐪熷疄楂樺害
+            listView.AdjustRealHeight(Application.GetRealHeight(23));
+            //鍊熺敤杩欎釜涓滆タ杩涜妫�娴�
+            var btnTemp = new BottomClickButton();
+            //濡傛灉鐪熷疄楂樺害宸茬粡瓒呰繃浜嗙‘瀹氭寜閿�
+            if (listView.Bottom + frameTable.Y > btnTemp.Yaxis)
+            {
+                listView.Height = frameTable.Height - frameBack.Height;
+                var frameTemp = new FrameLayout();
+                frameTemp.Height = bodyFrameLayout.Height - btnTemp.Yaxis;
+                listView.AddChidren(frameTemp);
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 妫�娴嬭鎴块棿鑳藉惁鏄剧ず
+        /// </summary>
+        /// <param name="room"></param>
+        /// <returns></returns>
+        private bool CheckCanShowRow(Common.Room room)
+        {
+            if (room.DeviceUIList.Count == 0)
+            {
+                return false;
+            }
+            if (room.IsLove == true)
+            {
+                return false;
+            }
+            foreach (var deviceUi in room.DeviceUIList)
+            {
+                //妫�娴嬭璁惧鑳藉惁鏄剧ず
+                if (this.CheckCanShowDevice(deviceUi.CommonDevice) == false)
+                {
+                    continue;
+                }
+
+                //瀛樺湪璁惧鐨勮瘽锛屾鎴块棿鍙互鏄剧ず
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 妫�娴嬭璁惧鑳藉惁鏄剧ず
+        /// </summary>
+        /// <param name="device"></param>
+        /// <returns></returns>
+        private bool CheckCanShowDevice(ZigBee.Device.CommonDevice device)
+        {
+            if (device == null)
+            {
+                return false;
+            }
+            //濡傛灉鏄紶鎰熷櫒锛屾垨鑰呮槸娌℃湁寮�鍏崇皣鐨勮瘽(杩欓噷鍒ゆ柇鐨勬槸杈撳叆绨�)
+            if ((device.Type == ZigBee.Device.DeviceType.IASZone) || Common.LocalDevice.Current.InDeviceIsCanOnOff(device) == false)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 鐣岄潰鍏抽棴___________________________
+
+        /// <summary>
+        /// 鐣岄潰鍏抽棴
+        /// </summary>
+        public override void CloseForm()
+        {
+            this.FinishSelectEvent = null;
+
+            base.CloseForm();
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0