From 66a9965c44ecc32a6696abca876ab9d1cd091584 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期五, 28 二月 2020 15:25:13 +0800
Subject: [PATCH] 2020.2.28

---
 ZigbeeApp/Shared/Phone/Device/CommonForm/SelectZone.cs |  174 +++++++++++++++------------------------------------------
 1 files changed, 47 insertions(+), 127 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/CommonForm/SelectZone.cs b/ZigbeeApp/Shared/Phone/Device/CommonForm/SelectZone.cs
index 78d0cef..6f5a522 100644
--- a/ZigbeeApp/Shared/Phone/Device/CommonForm/SelectZone.cs
+++ b/ZigbeeApp/Shared/Phone/Device/CommonForm/SelectZone.cs
@@ -4,149 +4,69 @@
 
 namespace Shared.Phone.Device.CommonForm
 {
-    public class SelectZone : FrameLayout
+    public class SelectZone
     {
         public Action<Common.Room> ZoneAction;
-
-        private UIPickerView pickView;
-
-        private List<string> floorList = new List<string> { };
-        private List<string> roomList = new List<string> { };
-        private List<string> roomIdList = new List<string> { };
-        private string currentId;
-        public SelectZone()
-        {
-        }
-
+        /// <summary>
+        /// curRoom
+        /// </summary>
+        private Common.Room curRoom;
+        /// <summary>
+        /// 鏍囬
+        /// </summary>
+        public string title = Language.StringByID(R.MyInternationalizationString.BelongZone);
         /// <summary>
         /// Init
         /// </summary>
         public void Init()
         {
-            var dialog = new FrameLayout()
+            List<string> floorIds = new List<string> { };
+            List<string> floorNames = new List<string> { };
+            List<List<string>> roomNames = new List<List<string>> { };
+            List<List<Common.Room>> rooms = new List<List<Common.Room>> { };
+            List<Common.Room> rs = new List<Common.Room> { };
+            List<string> rNames = new List<string> { };
+            if (Config.Instance.Home.FloorDics.Count > 0)
             {
-                BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
-            };
-            AddChidren(dialog);
-
-            dialog.MouseUpEventHandler += (sender, e) =>
-            {
-                RemoveFromParent();
-            };
-
-            var backgroundFL = new FrameLayout
-            {
-                Y = Application.GetRealHeight(1115),
-                Height = Application.GetRealHeight(805),
-                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
-                Radius = (uint)Application.GetRealHeight(20)
-            };
-            dialog.AddChidren(backgroundFL);
-
-            var topView = new FrameLayout
-            {
-                Height = Application.GetRealHeight(138)
-            };
-            backgroundFL.AddChidren(topView);
-
-            var cancle = new Button
-            {
-                X = Application.GetRealWidth(80),
-                Width = Application.GetRealWidth(300),
-                TextAlignment = TextAlignment.CenterLeft,
-                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
-                TextID = R.MyInternationalizationString.Cancel,
-                TextSize = 14
-            };
-            topView.AddChidren(cancle);
-
-            var title = new Button
-            {
-                Width = Application.GetRealWidth(300),
-                Gravity = Gravity.CenterHorizontal,
-                TextColor = ZigbeeColor.Current.GXCTextBlackColor2,
-                TextID = R.MyInternationalizationString.AddTo,
-                TextSize = 16
-            };
-            topView.AddChidren(title);
-
-            var confrim = new Button
-            {
-                X = Application.GetRealWidth(CommonFormResouce.AppRealWidth - 80 - 300),
-                Width = Application.GetRealWidth(300),
-                TextAlignment = TextAlignment.CenterRight,
-                TextColor = ZigbeeColor.Current.GXCTextSelectedColor2,
-                TextID = R.MyInternationalizationString.Confrim,
-                TextSize = 14
-            };
-            topView.AddChidren(confrim);
-
-            pickView = new UIPickerView
-            {
-                Y = Application.GetRealHeight(20 + 138),
-                Height = Application.GetRealHeight(450)
-            };
-            backgroundFL.AddChidren(pickView);
-
-            foreach (var floor in Config.Instance.Home.FloorDics)
-            {
-                floorList.Add(floor.Value);
-            }
-            foreach (var room in Shared.Common.Room.Lists)
-            {
-                if(room.IsLove)
+                foreach (var floor in Config.Instance.Home.FloorDics)
                 {
-                    continue;
+                    if (Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key).Count > 0)
+                    {
+                        floorIds.Add(floor.Key);
+                        floorNames.Add(floor.Value);
+
+                        roomNames.Add(Common.Room.CurrentRoom.GetRoomNamesByFloorId(floor.Key));
+                        rooms.Add(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key));
+                    }
                 }
-                roomList.Add(room.Name);
-                roomIdList.Add(room.Id);
-            }
-
-            if (floorList.Count == 0)
-            {
-                pickView.setNPicker(roomList, null, null);
-                currentId = roomIdList[0];
-                pickView.OnSelectChangeEvent += (l1, l2, l3) =>
+                PickerView.ShowSecondary(floorNames, roomNames, (index1, index2) =>
                 {
-                    currentId = roomIdList[l1];
-                };
+                    curRoom = rooms[index1][index2];
+                    ZoneAction?.Invoke(curRoom);
+                }, 0, 0, title,
+               Language.StringByID(R.MyInternationalizationString.Confrim),
+               Language.StringByID(R.MyInternationalizationString.Cancel));
             }
             else
             {
-                pickView.setNPicker(floorList, roomList, null);
-                currentId = roomIdList[0];
-                pickView.OnSelectChangeEvent += (l1, l2, l3) =>
+                for (int i = 0; i < Common.Room.Lists.Count; i++)
                 {
-                    currentId = roomIdList[l2];
-                };
+                    var r = Common.Room.Lists[i];
+                    if (r.IsLove)
+                    {
+                        continue;
+                    }
+                    rs.Add(r);
+                    rNames.Add(r.Name);
+                }
+                PickerView.Show(rNames, (index1) =>
+                {
+                    curRoom = rs[index1];
+                    ZoneAction?.Invoke(curRoom);
+                }, 0, title,
+               Language.StringByID(R.MyInternationalizationString.Confrim),
+               Language.StringByID(R.MyInternationalizationString.Cancel));
             }
-
-            cancle.MouseUpEventHandler += Close;
-            confrim.MouseUpEventHandler += Confrim_MouseEvent;
-        }
-
-        /// <summary>
-        /// Close
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="mouseEventArgs"></param>
-        private void Close(object sender, MouseEventArgs mouseEventArgs)
-        {
-            RemoveFromParent();
-        }
-
-        /// <summary>
-        /// Confrim_MouseEvent
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="mouseEventArgs"></param>
-        private void Confrim_MouseEvent(object sender, MouseEventArgs mouseEventArgs)
-        {
-            if (Shared.Common.Room.CurrentRoom.GetRoomById(currentId) != null)
-            {
-                ZoneAction?.Invoke(Shared.Common.Room.CurrentRoom.GetRoomById(currentId));
-            }
-            RemoveFromParent();
         }
     }
 }

--
Gitblit v1.8.0