From 00ab3ddb140ba8bb88b5cf572b004a85e1da85e9 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期四, 02 一月 2020 19:51:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev-tzy' into DEV_GXC

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs |  631 +++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 454 insertions(+), 177 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs
index 1819ec7..953f73e 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs
@@ -25,32 +25,33 @@
         {
             this.currentKey = key;
             this.currentModeID = key.panelMode;
-            this.oldModeID = key.panelMode;
             this.curDeviceBindType = deviceBindType;
             this.targetList = targetSelectList;
         }
 
         #region 鈼� 鍙橀噺鐢虫槑__________________________
-        ZigBee.Device.Panel currentKey;
+        ZigBee.Device.Panel currentKey;//褰撳墠鎸夐敭
         //鏄剧ず琚粦瀹氳澶囨垨鍦烘櫙鐨剉iew
-        VerticalScrolViewLayout midVerticalScrolViewLayout;
-        HorizontalScrolViewLayout btnHorizontalScrolViewLayout;
+        VerticalScrolViewLayout midVerticalScrolViewLayout;//涓儴鍒锋柊鍒楄〃
+        HorizontalScrolViewLayout btnHorizontalScrolViewLayout;//鎴块棿鍒楄〃宸﹀彸婊戝姩甯冨眬
         /// <summary>
         /// 鎸夐敭閰嶇疆鐨勭洰鏍囧垪琛�
         /// </summary>
-        List<CommonDevice> targetList = new List<CommonDevice>();
+        List<CommonDevice> targetList = new List<CommonDevice>();//鏈湴涓存椂閫変腑鍒楄〃
         /// <summary>
         /// 鏂扮殑鎸夐敭閰嶇疆鐩爣鍒楄〃涓紝鐩爣瀹為檯瀛樺湪鎸夐敭涓紝姝ゆ椂瑕佸垹鎺夌殑鏁版嵁
         /// </summary>
-        List<CommonDevice> oldTargetList = new List<CommonDevice>();
-        List<Room> roomList = new List<Room>();
-        int currentClusterID = 6;
-        public Action<List<BindListResponseObj>> action;
-        int currentModeID = 0;
-        int oldModeID = 0;
-        string curDeviceBindType = "";
+        List<CommonDevice> oldTargetList = new List<CommonDevice>();//鏈湴鏃х殑閫変腑鍒楄〃
+        int currentClusterID = 6;//褰撳墠绨嘔D
+        public Action<List<BindListResponseObj>> action;//鍥炶皟缁戝畾鐩爣椤甸潰鍒锋柊
+        int currentModeID = 0;//褰撳墠妯″紡ID
+        string curDeviceBindType = "";//褰撳墠璁惧缁戝畾绫诲瀷
+        List<int> typeDetailModeList = new List<int> { };
         #endregion
 
+        /// <summary>
+        /// 鏄剧ず鎸夐敭妯″紡椤�
+        /// </summary>
         public void Show()
         {
             this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.ChooseKeyMode));
@@ -66,6 +67,9 @@
             MidFrameLayoutContent();
         }
 
+        /// <summary>
+        /// 涓儴甯冨眬
+        /// </summary>
         async void MidFrameLayoutContent()
         {
             #region UI
@@ -92,16 +96,13 @@
                 BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                 TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                 TextSize = 16,
+                IsBold = true,
             };
             bottomFrameLayout.AddChidren(btnFinifh);
             #endregion
 
             #region 鏁版嵁澶勭悊
-            roomList = Shared.Common.Room.Lists;
-            Shared.Common.Room curRoom = roomList[0];
-            int index = 0;
-            KeyModeList(roomList[index]);
-
+            KeyModeList();
             btnFinifh.MouseUpEventHandler += async (sender, e) =>
             {
                 oldTargetList.Clear();
@@ -115,17 +116,15 @@
                     if (currentKey.bindList != null)
                     {
                         var bindResult = await currentKey.ClearBindInfoAsync();
-
                         if (bindResult != null && bindResult.clearBindInfoResponseData != null)
                         {
                             if (bindResult.clearBindInfoResponseData.Result != 0)
                             {
                                 Application.RunOnMainThread(() =>
                                 {
+                                    CommonPage.Loading.Hide();
                                     new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
                                 });
-                                CommonPage.Loading.Hide();
-                                this.RemoveFromParent();
                                 btnFinifh.Enable = true;
                                 btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                 return;
@@ -139,9 +138,9 @@
                         {
                             Application.RunOnMainThread(() =>
                             {
+                                CommonPage.Loading.Hide();
                                 new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
                             });
-                            CommonPage.Loading.Hide();
                             btnFinifh.Enable = true;
                             btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                             return;
@@ -214,105 +213,97 @@
                                 }
                             }
 
+                            //鏄寒搴﹀啀娆″彂6鍛戒护
+                            if (currentClusterID == 8)
+                            {
+                                foreach (var de in targetList)
+                                {
+                                    if (de.DeviceAddr != null)
+                                    {
+                                        var addBindInfo = new AddBindListObj();
+                                        addBindInfo.BindType = 0;
+                                        addBindInfo.BindCluster = 6;
+                                        addBindInfo.BindMacAddr = de.DeviceAddr;
+                                        addBindInfo.BindEpoint = de.DeviceEpoint;
+                                        addBindeDev.BindList.Add(addBindInfo);
+                                    }
+                                }
+                            }
+
                             var dev = new AddedDeviceBindResponseAllData();
                             dev = await currentKey.AddDeviceBindAsync(addBindeDev);
                             if (dev.addedDeviceBindResponseData == null)
                             {
                                 Application.RunOnMainThread(() =>
                                 {
+                                    CommonPage.Loading.Hide();
                                     new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
                                 });
                                 btnFinifh.Enable = true;
                                 btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                return;
                             }
                             else
                             {
-                                foreach (var ab in dev.addedDeviceBindResponseData?.BindList)
+                                if (dev.addedDeviceBindResponseData.Result == 0)
                                 {
-                                    switch (ab.Result)
+                                    if (currentClusterID == 8)
                                     {
-                                        case 0:
-                                            currentKey.bindList.Add((BindListResponseObj)ab);
-
-                                            for (int i = 0; i < targetList.Count; i++)
+                                        foreach (var de in dev.addedDeviceBindResponseData.BindList)
+                                        {
+                                            if (de.BindCluster == 8)
                                             {
-                                                var de = targetList[i];
-                                                var sc1 = new SceneUI();
-                                                if (de.DeviceAddr == null)
-                                                {
-                                                    sc1 = (SceneUI)de;
-
-                                                    if (sc1.Id == ab.BindScenesId)
-                                                    {
-                                                        targetList.RemoveAt(i);
-                                                        i--;
-                                                    }
-                                                }
+                                                currentKey.bindList.Add(de);
                                             }
-                                            //isFinish = true;
-                                            break;
-                                        case 1:
-                                            Application.RunOnMainThread(() =>
-                                            {
-                                                new Tip()
-                                                {
-                                                    MaxWidth = 150,
-                                                    Text = Language.StringByID(R.MyInternationalizationString.BindErrorAbsence),
-                                                    Direction = AMPopTipDirection.Up,
-                                                    CloseTime = 1
-                                                }.Show(btnFinifh);
-                                            });
-                                            break;
-                                        case 2:
-                                            var abr = dev.addBindResultResponseData?.Result;
-                                            switch (dev.addBindResultResponseData?.Result)
-                                            {
-                                                case 0:
-                                                    currentKey.bindList.Add((BindListResponseObj)ab);
-                                                    for (int i = 0; i < targetList.Count; i++)
-                                                    {
-                                                        var de = targetList[i];
-                                                        if (de.DeviceAddr == ab.BindMacAddr && de.DeviceEpoint == ab.BindEpoint)
-                                                        {
-                                                            targetList.RemoveAt(i);
-                                                            i--;
-                                                        }
-                                                    }
-                                                    //isFinish = true;
-                                                    break;
-                                                case 140:
-                                                    Application.RunOnMainThread(() =>
-                                                    {
-                                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
-                                                    });
-                                                    break;
-                                                default:
-                                                    Application.RunOnMainThread(() =>
-                                                    {
-                                                        new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindUnknownError), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
-                                                    });
-                                                    break;
-                                            }
-                                            break;
-                                        case 3:
-                                            Application.RunOnMainThread(() =>
-                                            {
-                                                new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindErrorExisted), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
-                                            });
-                                            break;
-                                        case 4:
-                                            Application.RunOnMainThread(() =>
-                                            {
-                                                new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
-                                            });
-                                            break;
-                                        default:
-                                            Application.RunOnMainThread(() =>
-                                            {
-                                                new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindUnknownError), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
-                                            });
-                                            break;
+                                        }
                                     }
+                                    else
+                                    {
+                                        currentKey.bindList = dev.addedDeviceBindResponseData.BindList;
+                                    }
+                                    if (action != null)
+                                    {
+                                        action(currentKey.bindList);
+                                    }
+                                    this.RemoveFromParent();
+                                    targetList.Clear();
+                                    CommonPage.Loading.Hide();
+                                    btnFinifh.Enable = true;
+                                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                }
+                                else if (dev.addedDeviceBindResponseData.Result == 1)
+                                {
+                                    Application.RunOnMainThread(() =>
+                                    {
+                                        CommonPage.Loading.Hide();
+                                        new Tip()
+                                        {
+                                            MaxWidth = 150,
+                                            Text = Language.StringByID(R.MyInternationalizationString.BindFailed),
+                                            Direction = AMPopTipDirection.Up,
+                                            CloseTime = 1
+                                        }.Show(btnFinifh);
+                                    });
+                                    btnFinifh.Enable = true;
+                                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                    return;
+                                }
+                                else
+                                {
+                                    Application.RunOnMainThread(() =>
+                                    {
+                                        CommonPage.Loading.Hide();
+                                        new Tip()
+                                        {
+                                            MaxWidth = 150,
+                                            Text = Language.StringByID(R.MyInternationalizationString.BindUnknownError),
+                                            Direction = AMPopTipDirection.Up,
+                                            CloseTime = 1
+                                        }.Show(btnFinifh);
+                                    });
+                                    btnFinifh.Enable = true;
+                                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                    return;
                                 }
                             }
                         }
@@ -320,6 +311,7 @@
                         {
                             Application.RunOnMainThread(() =>
                             {
+                                CommonPage.Loading.Hide();
                                 new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh);
                             });
                             btnFinifh.Enable = true;
@@ -331,6 +323,7 @@
                     {
                         Application.RunOnMainThread(() =>
                         {
+                            CommonPage.Loading.Hide();
                             new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh);
                         });
                         btnFinifh.Enable = true;
@@ -338,26 +331,8 @@
                         return;
                     }
                 }
-                catch { }
-                finally
+                catch
                 {
-                    //if (isFinish)
-                    //{
-                    //    if (action != null)
-                    //    {
-                    //        action(currentKey.bindList); 
-                    //    }
-                    //    this.RemoveFromParent();
-                    //}
-                    //else
-                    //{
-                    //    this.RemoveFromParent();
-                    //}
-                    if (action != null)
-                    {
-                        action(currentKey.bindList);
-                    }
-                    this.RemoveFromParent();
                     CommonPage.Loading.Hide();
                     btnFinifh.Enable = true;
                     btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
@@ -371,31 +346,256 @@
         /// </summary>
         /// <param name="gateway">Gateway.</param>
         /// <param name="key">Key.</param>
-        void KeyModeList(Shared.Common.Room curRoom)
+        async private void KeyModeList()
         {
             midVerticalScrolViewLayout.RemoveAll();
-
             switch (curDeviceBindType)
             {
                 case "AddSwitch":
                     currentClusterID = 6;
-                    AddSwitchMode();
+                    typeDetailModeList = await GetAddSwitchMode();
+                    if (typeDetailModeList == null)
+                    {
+                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                    }
+                    else
+                    {
+                        AddSwitchMode();
+                    }
                     break;
                 case "AddDimmer":
-                    AddDimmerMode();
                     currentClusterID = 8;
+                    typeDetailModeList = await GetAddDimmerMode();
+                    if (typeDetailModeList == null)
+                    {
+                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                    }
+                    else
+                    {
+                        AddDimmerMode();
+                    }
                     break;
                 case "AddCurtain":
                     currentClusterID = 258;
-                    AddCurtainMode();
+                    typeDetailModeList = await GetAddCurtainMode();
+                    if (typeDetailModeList == null)
+                    {
+                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                    }
+                    else
+                    {
+                        AddCurtainMode();
+                    }
                     break;
             }
         }
 
-        public void AddSwitchMode()
+        /// <summary>
+        /// 鑾峰彇寮�鍏冲叿浣撶被鍨�
+        /// </summary>
+        /// <returns></returns>
+        System.Threading.Tasks.Task<List<int>> GetAddSwitchMode()
         {
+            return System.Threading.Tasks.Task.Run(async () =>
+             {
+                 Application.RunOnMainThread(() =>
+                 {
+                     CommonPage.Loading.Start();
+                 });
+                 typeDetailModeList.Clear();
+                 List<int> result3 = new List<int> { };
+                 try
+                 {
+                     //鑾峰彇绗笁绾у姛鑳�
+                     if (currentKey.privateFuncThirdLevelList.Count == 0 || currentKey.privateFuncThirdLevelList.Contains(100) == false || currentKey.privateFuncThirdLevelList.Contains(101) == false || currentKey.privateFuncThirdLevelList.Contains(102) == false)
+                     {
+                         result3 = await currentKey.GetPanelDeviceFunctionLevel3(256, 100);
+                         foreach (var l3 in result3)
+                         {
+                             currentKey.privateFuncThirdLevelList.Add(l3);
+                         }
+                     }
+                     else
+                     {
+                         if (currentKey.privateFuncThirdLevelList.Contains(100) == true)
+                         {
+                             result3.Add(100);
+                         }
+                         if (currentKey.privateFuncThirdLevelList.Contains(101) == true)
+                         {
+                             result3.Add(101);
+                         }
+                         if (currentKey.privateFuncThirdLevelList.Contains(102) == true)
+                         {
+                             result3.Add(102);
+                         }
+                     }
+                 }
+                 catch (Exception ex)
+                 {
+                     var aa = ex.Message;
+                 }
+                 finally
+                 {
+                     Application.RunOnMainThread(() =>
+                     {
+                         CommonPage.Loading.Hide();
+                     });
+                 }
+                 return result3;
+             });
+        }
+
+        /// <summary>
+        /// 鑾峰彇璋冨厜鍏蜂綋绫诲瀷
+        /// </summary>
+        /// <returns></returns>
+        System.Threading.Tasks.Task<List<int>> GetAddDimmerMode()
+        {
+            return System.Threading.Tasks.Task.Run(async () =>
+            {
+                Application.RunOnMainThread(() =>
+                {
+                    CommonPage.Loading.Start();
+                });
+                typeDetailModeList.Clear();
+                List<int> result3 = new List<int> { };
+                try
+                {
+                    //鑾峰彇绗笁绾у姛鑳�
+                    if (currentKey.privateFuncThirdLevelList.Count == 0
+                        || currentKey.privateFuncThirdLevelList.Contains(200) == false
+                        || currentKey.privateFuncThirdLevelList.Contains(201) == false
+                        || currentKey.privateFuncThirdLevelList.Contains(203) == false
+                        || currentKey.privateFuncThirdLevelList.Contains(204) == false
+                        || currentKey.privateFuncThirdLevelList.Contains(205) == false)
+                    {
+                        result3 = await currentKey.GetPanelDeviceFunctionLevel3(256, 200);
+                        foreach (var l3 in result3)
+                        {
+                            currentKey.privateFuncThirdLevelList.Add(l3);
+                        }
+                    }
+                    else
+                    {
+                        if (currentKey.privateFuncThirdLevelList.Contains(200) == true)
+                        {
+                            result3.Add(200);
+                        }
+                        if (currentKey.privateFuncThirdLevelList.Contains(201) == true)
+                        {
+                            result3.Add(201);
+                        }
+                        if (currentKey.privateFuncThirdLevelList.Contains(203) == true)
+                        {
+                            result3.Add(203);
+                        }
+                        if (currentKey.privateFuncThirdLevelList.Contains(204) == true)
+                        {
+                            result3.Add(204);
+                        }
+                        if (currentKey.privateFuncThirdLevelList.Contains(205) == true)
+                        {
+                            result3.Add(205);
+                        }
+                    }
+                }
+                catch { }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        CommonPage.Loading.Hide();
+                    });
+                }
+                return result3;
+            });
+        }
+
+        /// <summary>
+        /// 鑾峰彇绐楀笜鍏蜂綋绫诲瀷
+        /// </summary>
+        /// <returns></returns>
+        System.Threading.Tasks.Task<List<int>> GetAddCurtainMode()
+        {
+            Application.RunOnMainThread(() =>
+            {
+                CommonPage.Loading.Start();
+            });
+            return System.Threading.Tasks.Task.Run(async () =>
+            {
+                typeDetailModeList.Clear();
+                List<int> result3 = new List<int> { };
+                try
+                {
+                    //鑾峰彇绗笁绾у姛鑳�
+                    if (currentKey.privateFuncThirdLevelList.Count == 0
+                        || currentKey.privateFuncThirdLevelList.Contains(300) == false
+                        || currentKey.privateFuncThirdLevelList.Contains(301) == false
+                        || currentKey.privateFuncThirdLevelList.Contains(302) == false
+                        || currentKey.privateFuncThirdLevelList.Contains(303) == false
+                        || currentKey.privateFuncThirdLevelList.Contains(304) == false)
+                    {
+                        result3 = await currentKey.GetPanelDeviceFunctionLevel3(256, 300);
+                        foreach (var l3 in result3)
+                        {
+                            currentKey.privateFuncThirdLevelList.Add(l3);
+                        }
+                    }
+                    else
+                    {
+                        if (currentKey.privateFuncThirdLevelList.Contains(300) == true)
+                        {
+                            result3.Add(300);
+                        }
+                        if (currentKey.privateFuncThirdLevelList.Contains(301) == true)
+                        {
+                            result3.Add(301);
+                        }
+                        if (currentKey.privateFuncThirdLevelList.Contains(302) == true)
+                        {
+                            result3.Add(302);
+                        }
+                        if (currentKey.privateFuncThirdLevelList.Contains(303) == true)
+                        {
+                            result3.Add(303);
+                        }
+                        if (currentKey.privateFuncThirdLevelList.Contains(304) == true)
+                        {
+                            result3.Add(304);
+                        }
+                    }
+                }
+                catch { }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        CommonPage.Loading.Hide();
+                    });
+                }
+                return result3;
+            });
+        }
+
+        async private void AddSwitchMode()
+        {
+            if (typeDetailModeList == null)
+            {
+                //鍐嶆鍔ㄦ�佽幏鍙栨寜閿敮鎸佺殑绫�
+                typeDetailModeList = await GetAddSwitchMode();
+                if (typeDetailModeList == null)
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                    });
+                    return;
+                }
+            }
             Button oldMode = null;
-            for (int i = 0; i < 3; i++)
+            int i = 0;
+            foreach (var modeSwitchValue in typeDetailModeList)
             {
                 #region 缁戝畾琛║I鏄撅紙鏃犳暟鎹鐞嗭級
                 var rowLayout = new FrameLayout()
@@ -413,6 +613,7 @@
                     Y = Application.GetRealHeight(58),
                     TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
                     TextAlignment = TextAlignment.CenterLeft,
+                    TextSize = 14,
                 };
                 rowLayout.AddChidren(btnModeText);
 
@@ -438,17 +639,21 @@
                 rowLayout.AddChidren(line2);
                 #endregion
 
-                if (i == 0)
+                switch (modeSwitchValue)
                 {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOn);
+                    case 100:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOn);
+                        break;
+                    case 101:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffoFF);
+                        break;
+                    case 102:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOnOff);
+                        break;
                 }
-                if (i == 1)
+
+                if (i == typeDetailModeList.Count - 1)
                 {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffoFF);
-                }
-                if (i == 2)
-                {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOnOff);
                     line2.Visible = false;
                 }
 
@@ -469,6 +674,15 @@
                     btnChoose.IsSelected = true;
                     btnChoose.Visible = true;
                     oldMode = btnChoose;
+                }
+                else if ((currentKey.panelMode == 65535) && i == 0)
+                {
+                    //榛樿绗竴涓�
+                    btnChoose.IsSelected = true;
+                    btnChoose.Visible = true;
+                    oldMode = btnChoose;
+                    currentModeID = 100;
+                    currentKey.panelMode = currentModeID;
                 }
 
                 EventHandler<MouseEventArgs> hander = async (sender, e) =>
@@ -505,13 +719,39 @@
                 rowLayout.MouseUpEventHandler += hander;
                 btnModeText.MouseUpEventHandler += hander;
                 btnChoose.MouseUpEventHandler += hander;
+                i++;
             }
         }
 
-        public void AddDimmerMode()
+        async private void AddDimmerMode()
         {
+            if (typeDetailModeList == null)
+            {
+                //鍐嶆鍔ㄦ�佽幏鍙栨寜閿敮鎸佺殑绫�
+                typeDetailModeList = await GetAddDimmerMode();
+                if (typeDetailModeList == null)
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                    });
+                    return;
+                }
+            }
             Button oldMode = null;
-            for (int i = 0; i < 5; i++)
+            int i = 0;
+
+            List<int> typeDetailModeListTemp = new List<int> { };
+            foreach (var modeSwitchValue in typeDetailModeList)
+            {
+                if (modeSwitchValue == 202)
+                {
+                    continue;
+                }
+                typeDetailModeListTemp.Add(modeSwitchValue);
+            }
+
+            foreach (var modeSwitchValue in typeDetailModeListTemp)
             {
                 #region 缁戝畾琛║I鏄撅紙鏃犳暟鎹鐞嗭級
                 var rowLayout = new FrameLayout()
@@ -529,6 +769,7 @@
                     Y = Application.GetRealHeight(58),
                     TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
                     TextAlignment = TextAlignment.CenterLeft,
+                    TextSize = 14,
                 };
                 rowLayout.AddChidren(btnModeText);
 
@@ -553,26 +794,27 @@
                 };
                 rowLayout.AddChidren(line2);
                 #endregion
+                switch (modeSwitchValue)
+                {
+                    case 200:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode1);
+                        break;
+                    case 201:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode2);
+                        break;
+                    case 203:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode3);
+                        break;
+                    case 204:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode4);
+                        break;
+                    case 205:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode5);
+                        break;
+                }
 
-                if (i == 0)
+                if (i == typeDetailModeListTemp.Count - 1)
                 {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode1);
-                }
-                if (i == 1)
-                {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode2);
-                }
-                if (i == 2)
-                {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode3);
-                }
-                if (i == 3)
-                {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode4);
-                }
-                if (i == 4)
-                {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode5);
                     line2.Visible = false;
                 }
 
@@ -605,6 +847,15 @@
                     btnChoose.IsSelected = true;
                     btnChoose.Visible = true;
                     oldMode = btnChoose;
+                }
+                else if ((currentKey.panelMode == 65535) && i == 0)
+                {
+                    //榛樿绗竴涓�
+                    btnChoose.IsSelected = true;
+                    btnChoose.Visible = true;
+                    oldMode = btnChoose;
+                    currentModeID = 200;
+                    currentKey.panelMode = currentModeID;
                 }
 
                 EventHandler<MouseEventArgs> hander = (sender, e) =>
@@ -650,14 +901,28 @@
                 rowLayout.MouseUpEventHandler += hander;
                 btnModeText.MouseUpEventHandler += hander;
                 btnChoose.MouseUpEventHandler += hander;
-
+                i++;
             }
         }
 
-        public void AddCurtainMode()
+        async private void AddCurtainMode()
         {
+            if (typeDetailModeList == null)
+            {
+                //鍐嶆鍔ㄦ�佽幏鍙栨寜閿敮鎸佺殑绫�
+                typeDetailModeList = await GetAddSwitchMode();
+                if (typeDetailModeList == null)
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                    });
+                    return;
+                }
+            }
             Button oldMode = null;
-            for (int i = 0; i < 5; i++)
+            int i = 0;
+            foreach (var modeSwitchValue in typeDetailModeList)
             {
                 #region 缁戝畾琛║I鏄撅紙鏃犳暟鎹鐞嗭級
                 var rowLayout = new FrameLayout()
@@ -675,6 +940,7 @@
                     Y = Application.GetRealHeight(58),
                     TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
                     TextAlignment = TextAlignment.CenterLeft,
+                    TextSize = 14,
                 };
                 rowLayout.AddChidren(btnModeText);
 
@@ -699,26 +965,27 @@
                 };
                 rowLayout.AddChidren(line2);
                 #endregion
+                switch (modeSwitchValue)
+                {
+                    case 300:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdUp);
+                        break;
+                    case 301:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdDown);
+                        break;
+                    case 302:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdStop);
+                        break;
+                    case 303:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdUpStop);
+                        break;
+                    case 304:
+                        btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdDownStop);
+                        break;
+                }
 
-                if (i == 0)
+                if (i == typeDetailModeList.Count - 1)
                 {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdUp);
-                }
-                if (i == 1)
-                {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdDown);
-                }
-                if (i == 2)
-                {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdStop);
-                }
-                if (i == 3)
-                {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdUpStop);
-                }
-                if (i == 4)
-                {
-                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdDownStop);
                     line2.Visible = false;
                 }
 
@@ -751,6 +1018,15 @@
                     btnChoose.IsSelected = true;
                     btnChoose.Visible = true;
                     oldMode = btnChoose;
+                }
+                else if ((currentKey.panelMode == 65535) && i == 0)
+                {
+                    //榛樿绗竴涓�
+                    btnChoose.IsSelected = true;
+                    btnChoose.Visible = true;
+                    oldMode = btnChoose;
+                    currentModeID = 300;
+                    currentKey.panelMode = currentModeID;
                 }
 
                 EventHandler<MouseEventArgs> hander = (sender, e) =>
@@ -796,6 +1072,7 @@
                 rowLayout.MouseUpEventHandler += hander;
                 btnModeText.MouseUpEventHandler += hander;
                 btnChoose.MouseUpEventHandler += hander;
+                i++;
             }
         }
 

--
Gitblit v1.8.0