From 50b7b7a486f56fab27c83b59eb45673c6d9f0935 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 24 二月 2021 18:33:57 +0800
Subject: [PATCH] 2021-02-24 1.新增场景上传。2.优化

---
 Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs | 1180 +++++++++++++++++++---------------------------------------
 1 files changed, 385 insertions(+), 795 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs
index 3d5a60a..d3d3a4c 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs
@@ -3,844 +3,210 @@
 
 namespace Shared.SimpleControl.Phone
 {
-    public class AlexaDeviceListPage : FrameLayout
+    public class AlexaDeviceListPage : BasePage
     {
-        public AlexaDeviceListPage ()
+        ///// <summary>
+        ///// 鏆傛椂娴嬭瘯鍚庨潰鍘绘帀
+        ///// </summary>
+        //string AlexaTestURL = "https://developer.hdlcontrol.com";
+
+        /// <summary>
+        /// 褰撳墠闊崇銆佺敤鎴枫�佷綇瀹呯瓑鏁版嵁
+        /// </summary>
+        SpeakerInfo mAlexa = new SpeakerInfo ();
+        /// <summary>
+        /// 璁惧銆佸満鏅垪琛�
+        /// </summary>
+        List<TargetInfo> targetInfoList = new List<TargetInfo> ();
+
+        /////// <summary>
+        /////// 璇煶鎴块棿鏁版嵁
+        /////// </summary>
+        ////List<AlexaRoomsItem> alexaRoomsList = new List<AlexaRoomsItem> ();
+        ///// <summary>
+        ///// 璁惧鍒楄〃
+        ///// </summary>
+        //List<AlexaDeviceListItem> alexaDeviceList = new List<AlexaDeviceListItem> ();
+        ///// <summary>
+        ///// 鍦烘櫙鍒楄〃
+        ///// </summary>
+        //List<SceneListItem> alexaSceneList = new List<SceneListItem> ();
+        //AlexaRoomsItem mAlexaRoomsItem = new AlexaRoomsItem ();
+
+        VerticalScrolViewLayout bodyView;
+
+        bool IsDeviceList = true;
+
+        public AlexaDeviceListPage (SpeakerInfo speakerInfo)
         {
             BackgroundColor = SkinStyle.Current.MainColor;
+            mAlexa = speakerInfo;
         }
 
-        public void ShowPage ()
+        /// <summary>
+        /// 鏄剧ず椤甸潰
+        /// </summary>
+        public override void ShowPage ()
         {
-            #region 鏍囬
-            var topView = new FrameLayout () {
-                Y = Application.GetRealHeight (36),
-                Height = Application.GetRealHeight (90),
+            #region ---TopView---
+            base.ShowPage ();
+            this.topTitleBtn.Text = "Alexa";
+            //娣诲姞鎸夐挳鐐瑰嚮浜嬩欢
+            EventHandler<MouseEventArgs> addSubaccountHandler = (sender, e) => {
+                OpenAlexaSettingPage ();
             };
-            AddChidren (topView);
+            this.topItemButton.MouseUpEventHandler += addSubaccountHandler;
+            #endregion
 
-            var title = new Button () {
-                TextAlignment = TextAlignment.Center,
-                Text = "Alexa",
-                TextSize = 19,
+            #region 璁惧-鍦烘櫙
+            var topView = new FrameLayout () {
+                Height = Application.GetRealHeight (110),
+                BackgroundColor = SkinStyle.Current.TitileView,
+            };
+            BaseContentView.AddChidren (topView);
+
+            var btnDevice = new Button () {
+                Width = Application.GetRealWidth (320),
+                TextSize = 16,
+                TextID = R.MyInternationalizationString.Device,
+                TextColor = SkinStyle.Current.SelectedColor
+            };
+            topView.AddChidren (btnDevice);
+            var btnScene = new Button () {
+                Width = Application.GetRealWidth (320),
+                X = btnDevice.Right,
+                TextSize = 16,
+                TextID = R.MyInternationalizationString.Scenes,
                 TextColor = SkinStyle.Current.TextColor1
             };
-            topView.AddChidren (title);
-
-            Button ItemButton = new Button () {
-                Width = Application.GetRealWidth (55),
-                Height = Application.GetRealHeight (55),
-                UnSelectedImagePath = "Item/+.png",
-                SelectedImagePath = "Item/+.png",
-                X = Application.GetRealWidth (640 - 80),
-                Y = Application.GetRealHeight (17),
+            var btnLine = new Button () {
+                Width = 1,
+                BackgroundColor = SkinStyle.Current.White20Transparent,
+                X = btnDevice.Right,
             };
-            topView.AddChidren (ItemButton);
+            topView.AddChidren (btnLine);
+            btnDevice.MouseUpEventHandler += (sender, e) => {
+                btnDevice.TextColor = SkinStyle.Current.SelectedColor;
+                btnScene.TextColor = SkinStyle.Current.TextColor1;
+                if (!IsDeviceList) {
+                    IsDeviceList = true;
+                    InitDevcieRow (bodyView);
+                }
 
-            var back = new Button () {
-                Height = Application.GetRealHeight (90),
-                Width = Application.GetRealWidth (85),
-                UnSelectedImagePath = "Item/Back.png",
-                SelectedImagePath = "Item/BackSelected.png",
+
             };
-            topView.AddChidren (back);
-            back.MouseUpEventHandler += (sender, e) => {
-                (Parent as PageLayout).PageIndex -= 1;
+            topView.AddChidren (btnScene);
+            btnScene.MouseUpEventHandler += (sender, e) => {
+                btnDevice.TextColor = SkinStyle.Current.TextColor1;
+                btnScene.TextColor = SkinStyle.Current.SelectedColor;
+
+                if (IsDeviceList) {
+                    IsDeviceList = false;
+                    InitSceneRow (bodyView);
+                }
             };
             #endregion
 
-            var bodyView = new VerticalScrolViewLayout () {
+            bodyView = new VerticalScrolViewLayout () {
                 Y = topView.Bottom,
-                Height = Application.GetRealHeight (1136 - 126),
+                Height = BaseContentView.Height - topView.Bottom,
                 BackgroundColor = SkinStyle.Current.ViewColor,
             };
-            AddChidren (bodyView);
-            var alexaDeviceLista = new List<UpdateDeviceObj> ();
-            var alexaSceneList = new List<SceneByRegion> ();
+            BaseContentView.AddChidren (bodyView);
 
-            System.Threading.Tasks.Task.Factory.StartNew (() => {
-                Application.RunOnMainThread (() => {
-                    MainPage.Loading.Start ("Please wait...");
-                });
+            ///璇锋眰鑾峰彇璁惧鍜屽満鏅垪琛�
+            GetDeviceAndSceneList ();
+        }
+
+        #region 鎺ュ彛璇锋眰鏂规硶
+        /// <summary>
+        /// 璇锋眰鑾峰彇璁惧鍜屽満鏅垪琛�
+        /// </summary>
+        void GetDeviceAndSceneList ()
+        {
+
+            System.Threading.Tasks.Task.Run (() => {
                 try {
-                    alexaDeviceLista = ReadDeviceList ();
-                    alexaSceneList = ReadSceneList ();
+                    Application.RunOnMainThread (() => {
+                        MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load));
+                    });
 
-                    if (alexaDeviceLista.Count > 0) {
+                    var revertObj = HttpServerRequest.Current.GetSpeakerDeviceList (0, mAlexa.tokenId);
+
+                    if (revertObj.Code == StateCode.SUCCESS) {
+                        var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TargetInfo>> (revertObj.Data.ToString ());
                         Application.RunOnMainThread (() => {
-                            InitDevcieRow (alexaDeviceLista, bodyView);
+                            if (list != null && list.Count > 0) {
+                                targetInfoList = list;
+                            } else {
+                                targetInfoList = new List<TargetInfo> ();
+                            }
+                            RefreshListView ();
                         });
-                    }
-                    if (alexaSceneList.Count > 0) {
-                        Application.RunOnMainThread (() => {
-                            InitSceneRow (alexaSceneList, bodyView);
-                        });
-                    }
-                } catch (Exception ex) {
-                    Utlis.WriteLine (ex.Message);
+                    } else {
+                        //鎻愮ず閿欒
+                        IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
+                    }   
+                } catch {
+
                 } finally {
                     Application.RunOnMainThread (() => {
                         MainPage.Loading.Hide ();
                     });
                 }
             });
-
-            ItemButton.MouseUpEventHandler += (sender, e) => {
-                Action action = () => {
-                    Application.RunOnMainThread (() => {
-                        MainPage.Loading.Start ("Please wait...");
-                    });
-                    System.Threading.Tasks.Task.Run (() => {
-                        try {
-                            alexaDeviceLista = ReadDeviceList ();
-                            alexaSceneList = ReadSceneList ();
-                            Application.RunOnMainThread (() => {
-                                InitDevcieRow (alexaDeviceLista, bodyView);
-                            });
-                        } catch (Exception ex) {
-                            Utlis.WriteLine (ex.Message);
-                        } finally {
-                            Application.RunOnMainThread (() => {
-                                MainPage.Loading.Hide ();
-                            });
-                        }
-                    });
-                };
-
-                Action<List<string>, List<string>> saveAction = (roomSceneFilePathList, roomDeviceFilePathList) => {
-                    System.Threading.Tasks.Task.Factory.StartNew (() => {
-                        try {
-                            Application.RunOnMainThread (() => {
-                                MainPage.Loading.Start ("Please wait...");
-                            });
-                            foreach (var newDevicePath in roomDeviceFilePathList) {
-                                var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (newDevicePath)));
-                                //newDeviceList.Add (new UpdateDeviceObj () {
-                                //    DeviceName = common.Name, DeviceID = common.DeviceID, Id = 1, DeviceType = common.Type.ToString (), LoopID = common.LoopID,
-                                //    MAC = UserConfig.Instance.GatewayMAC, RegionID = UserConfig.Instance.CurrentRegion.RegionID, SubnetID = common.SubnetID
-                                //});
-                              
-
-                                if (common != null) {
-                                    var commonType = common.Type.ToString ();
-                                    if (commonType == "CurtainModel") {
-                                        commonType = "CurtainModule";
-                                    } else if (commonType == "LightEnergySwitch" || commonType == "LightSwitchSocket" || commonType == "LightEnergySocket") {
-                                        commonType = "LightSwitch";
-                                    } else if (commonType == "ACInfrared") {
-                                        commonType = "HVAC";
-                                    }
-                                    var oldDevice = alexaDeviceLista.Find ((obj) => obj.SubnetID == common.SubnetID && obj.DeviceID == common.DeviceID && obj.LoopID == common.LoopID && obj.DeviceType == commonType);
-                                    if (oldDevice == null) {
-                                        var isSuccess = AddDevice (common);
-                                        if (!isSuccess) {
-                                            //璺冲嚭寰幆
-                                            break;
-                                        }
-                                    } else {
-                                        //2020-07-21 濡傛灉宸茬粡瀛樺湪 鍖归厤璁惧澶囨敞鏄惁闇�瑕佹洿鏂�
-                                        if (oldDevice.DeviceName != common.Name) {
-                                            //Utlis.WriteLine ("鍚嶅瓧涓嶅尮閰嶏紝鎻愪氦鏇存柊锛�" + common.Name);
-                                            var oldName = oldDevice.DeviceName;
-                                            oldDevice.DeviceName = common.Name;
-                                            var isSuccess = UpdateDevice (oldDevice);
-                                            if (!isSuccess) {
-                                                //杩樺師
-                                                oldDevice.DeviceName = oldName;
-                                                //Utlis.WriteLine ("鏇存柊澶辫触锛侊紒锛侊紒");
-                                            } else {
-                                                //Utlis.WriteLine ("鏇存柊鎴愬姛锛�");
-                                            }
-                                        } else {
-                                            //Utlis.WriteLine ("鍚嶅瓧涓�鏍蜂笉鐢ㄦ洿鏂帮細"+ common.Name);
-                                        }
-
-                                    }
-                                }
-                            }
-
-                            var roomDeviceFilePathListNew = new List<string> ();
-                            foreach (var path in roomDeviceFilePathList) {
-                                var deviceFilePath = path;
-                                if (deviceFilePath.Contains ("LightEnergySocket")) {
-                                    deviceFilePath = deviceFilePath.Replace ("LightEnergySocket", "LightSwitch");
-                                } else if (deviceFilePath.Contains ("LightEnergySwitch")) {
-                                    deviceFilePath = deviceFilePath.Replace ("LightEnergySwitch", "LightSwitch");
-                                } else if (deviceFilePath.Contains ("LightSwitchSocket")) {
-                                    deviceFilePath = deviceFilePath.Replace ("LightSwitchSocket", "LightSwitch");
-                                } else if (deviceFilePath.Contains ("ACInfrared")) {
-                                    deviceFilePath = deviceFilePath.Replace ("ACInfrared", "HVAC");
-                                } else if (deviceFilePath.Contains ("CurtainModel")) {
-                                    deviceFilePath = deviceFilePath.Replace ("CurtainModel", "CurtainModule");
-                                }
-                                roomDeviceFilePathListNew.Add (deviceFilePath);
-                            }
-
-                           foreach (var oldDevice in alexaDeviceLista) {
-                                var oldDevicePath = "Equipment_" + oldDevice.DeviceType + "_" + oldDevice.SubnetID + "_" + oldDevice.DeviceID + "_" + (oldDevice.LoopID.ToString ().Length < 2 ? "0" + oldDevice.LoopID.ToString () : oldDevice.LoopID.ToString ());
-                                if (!roomDeviceFilePathListNew.Contains (oldDevicePath)) {
-                                    DelDevice (oldDevice.Id);
-                                    Utlis.WriteLine ("delDevice " + oldDevice.DeviceName);
-                                }
-                            }
-
-                            foreach (var newScenePath in roomSceneFilePathList) {
-                                var tempScene = Scene.GetSceneByFilePath (newScenePath);
-                                if (tempScene != null) {
-                                    var oldScene = alexaSceneList.Find ((obj) => obj.SceneName == tempScene.Name);
-                                    if (oldScene == null) {
-                                        int sceneDeviceCount = tempScene.DeviceFilePathList.Count;
-                                        var uploadScene = new SceneAndDeviceList () { MAC = UserConfig.Instance.GatewayMAC, RegionID = UserConfig.Instance.CurrentRegion.Id, SceneName = tempScene.Name };
-
-                                        byte [] replyBytes = null;
-                                        if (!tempScene.busScene) {
-                                            foreach (var deviceFilePath in tempScene.DeviceFilePathList) {
-                                                var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                if (common.Type == DeviceType.FanModule) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "FanModule", LoopId = device.LoopID,
-                                                            DataString = device.WindSpeed.ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.LightDimming) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "LightDimming", LoopId = device.LoopID,
-                                                            DataString = device.CurrentBrightness.ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.LightDALI) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDALI> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "LightDimming", LoopId = device.LoopID,
-                                                            DataString = device.CurrentBrightness.ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.LightRGB) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetLogicLoopColor, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "LightRGB", LoopId = device.LoopID,
-                                                            DataString = device.CurrentBrightness + "," + device.RStatus + "," + device.GStatus + "," + device.BStatus
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightSwitchSocket) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "LightSwitch", LoopId = device.LoopID,
-                                                            DataString = device.CurrentBrightness.ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.LightEnergySocket) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "LightSwitch", LoopId = device.LoopID,
-                                                            DataString = device.CurrentBrightness.ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.LightEnergySwitch) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "LightSwitch", LoopId = device.LoopID,
-                                                            DataString = device.CurrentBrightness.ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.CurtainModel) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.UpdataCurtainModelStutas, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "CurtainModule", LoopId = device.LoopID,
-                                                            DataString = ((byte)device.Status).ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.CurtainRoller) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.UpdataCurtainModelStutas, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "CurtainRoller", LoopId = device.LoopID,
-                                                            DataString = ((byte)device.CurtainProress + 3).ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.CurtainTrietex) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.UpdataCurtainModelStutas, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "CurtainRoller", LoopId = device.LoopID,
-                                                            DataString = ((byte)device.CurtainProress + 3).ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetACMode, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "HVAC", LoopId = device.LoopID,
-                                                            DataString = device.Power + "," + device.TemperatureMode + "," + device.SetMode + "," + device.SetFanSpeed + "," + device.SetTemperature
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.FoolHeat) {
-                                                    //var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    //if (device == null) {
-                                                    //    continue;
-                                                    //}
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, device.SubnetID, device.DeviceID,
-                                                    //new byte [] { device.LoopID, (byte)(device.Status + device.WorkingMode * 16), 0,device.WorkingMode,device.NormalTemperature, device.DayTemperature,
-                                                    //device.NightTemperature, device.AwayTemperature , 0, 0 });
-
-                                                } else if (common.Type == DeviceType.FanModule) {
-                                                    //var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    //if (device == null) {
-                                                    //    continue;
-                                                    //}
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.WindSpeed });
-                                                } else if (common.Type == DeviceType.LogicModule) {
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetScene, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "SceneControl", LoopId = device.AreaID,
-                                                            DataString = device.AreaSceneID.ToString ()
-                                                        });
-                                                    }
-                                                } else if (common.Type == DeviceType.UniversalDevice) {//2020-09-02 鏂板閫氱敤寮�鍏�
-                                                    var device = Newtonsoft.Json.JsonConvert.DeserializeObject<UniversalDevice> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
-                                                    if (device != null) {
-                                                        uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                            Command = (int)Command.SetCommonSwitch, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
-                                                            DeviceName = device.Name, DeviceType = "UniversalDevice", LoopId = device.LoopID,
-                                                            DataString = device.SendBytes[1].ToString(),
-                                                        });
-                                                    }
-                                                }
-
-                                            }
-                                        } else {
-                                            foreach (var common in tempScene.GlobalSceneDeviceList) {
-                                                switch (common.obj1) {
-                                                case 0://0   鏃犳晥 Invalid
-                                                    break;
-                                                case 85://0x55  鍦烘櫙 Scene ||0x0002
-                                                    uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                        Command = (int)Command.SetScene, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
-                                                        DeviceName = common.Name, DeviceType = "SceneControl", LoopId = common.obj2,
-                                                        DataString = common.obj3.ToString ()
-                                                    });
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    break;
-                                                case 86://0x56  搴忓垪 Sequence ||0x001A
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.SetSeries, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    break;
-                                                case 88://0x58  閫氱敤寮�鍏� Universal Switch ||0xe01c
-                                                    uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                        Command = (int)Command.SetCommonSwitch, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
-                                                        DeviceName = common.Name, DeviceType = "UVSwitch", LoopId = common.obj2,
-                                                        DataString = common.obj3.ToString ()
-                                                    });
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.SetCommonSwitch, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    break;
-                                                case 89: //0x59  鍗曡矾璋冭妭 Single Channel Lighting Control  0031
-                                                    uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                        Command = (int)Command.SetSingleLight, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
-                                                        DeviceName = common.Name, DeviceType = "LightDimming", LoopId = common.obj2,
-                                                        DataString = common.obj3.ToString ()
-                                                    });
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    break;
-                                                case 92://0x5c  绐楀笜寮�鍏� Curtain Switch e3e0
-                                                    uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                        Command = (int)Command.UpdataCurtainModelStutas, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
-                                                        DeviceName = common.Name, DeviceType = "CurtainModel", LoopId = common.obj2,
-                                                        DataString = common.obj3.ToString ()
-                                                    });
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    break;
-                                                case 94://0x5e  GPRS鎺у埗 GPRS Control E3D4
-                                                    replyBytes = Control.ControlBytesSendHasReturn (Command.GPRSControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    break;
-                                                case 95://0x5f  闈㈡澘鎺у埗 Panel Control e3d8
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.InstructionPanelKey, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    break;
-                                                case 100://0x64 骞挎挱鍦烘櫙 Broadcast Scene ||0x0002  
-                                                    uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                        Command = (int)Command.SetScene, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
-                                                        DeviceName = common.Name, DeviceType = "SceneControl", LoopId = common.obj2,
-                                                        DataString = common.obj3.ToString ()
-                                                    });
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    break;
-                                                case 101://0x65 骞挎挱鍥炶矾 Broadcast Channel 0031
-                                                    uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
-                                                        Command = (int)Command.SetSingleLight, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
-                                                        DeviceName = common.Name, DeviceType = "LightDimming", LoopId = common.obj2,
-                                                        DataString = common.obj3.ToString ()
-                                                    });
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    break;
-                                                    //case 102://0x66 娑堥槻妯″潡 Security Module 011E
-                                                    //    replyBytes = Control.ControlBytesSendHasReturn (Command.SecurityModule, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    //    break;
-                                                    //case 103://0x67 闊充箰鎾斁 Music Control 0218
-                                                    //replyBytes = Control.ControlBytesSendHasReturn (Command.MusicControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    //break;
-                                                    //104 閫氱敤鎺у埗 Universal Control
-                                                    //105 杩炴帴椤� Link Page
-                                                    //107 RGB璋冭妭 RGB Control
-                                                    //108 绾㈠鎺у埗 Infrared Control
-                                                    //case 109://109 閫昏緫鐏皟鑺� Logic Light Adjust ||  0xE45E
-                                                    //    replyBytes = Control.ControlBytesSendHasReturn (Command.LogicLightAdjust, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
-                                                    //    break;
-                                                    //}
-                                                    //110 閫昏緫鍦烘櫙 Logic Scene
-                                                    //112 LCD & LED浼戠湢 LCD & LED Sleep
-                                                    //113 鏈嶅姟鍣ㄦ帶鍒�   Server control
-                                                }
-                                            }
-                                        }
-
-                                        var isSuccess = AddScene (uploadScene);
-                                        if (!isSuccess) {
-                                            //璺冲嚭寰幆
-                                            break;
-                                        }
-                                    }
-                                }
-
-                            }
-
-
-                            alexaDeviceLista = ReadDeviceList ();
-                            Application.RunOnMainThread (() => {
-                                InitDevcieRow (alexaDeviceLista, bodyView);
-                            });
-                            alexaSceneList = ReadSceneList ();
-                            Application.RunOnMainThread (() => {
-                                InitSceneRow (alexaSceneList, bodyView);
-                            });
-
-                        } catch (Exception ex) {
-                            Utlis.WriteLine (ex.Message);
-                        } finally {
-                            Application.RunOnMainThread (() => {
-                                MainPage.Loading.Hide ();
-                            });
-                        }
-                    });
-                };
-
-                System.Threading.Tasks.Task.Factory.StartNew (() => {
-                    try {
-                        Application.RunOnMainThread (() => {
-                            MainPage.Loading.Start ("Please wait...");
-                        });
-                        var tempRoom = new Room ();
-                        foreach (var device in alexaDeviceLista) {//鐗规畩澶勭悊鏈嶅姟鍣ㄤ笌鏈湴璁惧绫诲瀷涓嶄竴鏍风殑璁惧
-                            var deviceTypeSaveString = device.DeviceType;
-                            if (deviceTypeSaveString == "CurtainModel") {
-                                deviceTypeSaveString = "CurtainModule";
-                            } else if (deviceTypeSaveString == "LightEnergySwitch") {
-                                deviceTypeSaveString = "LightSwitch";
-                            } else if (deviceTypeSaveString == "LightEnergySocket") {
-                                deviceTypeSaveString = "LightSwitch";
-                            } else if (deviceTypeSaveString == "LightSwitchSocket") {
-                                deviceTypeSaveString = "LightSwitch";
-                            } else if (deviceTypeSaveString == "LightLogic") {
-                                deviceTypeSaveString = "LightRGB";
-                            }else if (deviceTypeSaveString == "ACInfrared") {
-                                deviceTypeSaveString = "HVAC";
-                            }
-                            
-                            var devicePath = "Equipment_" + deviceTypeSaveString + "_" + device.SubnetID + "_" + device.DeviceID + "_" + (device.LoopID.ToString ().Length < 2 ? "0" + device.LoopID.ToString () : device.LoopID.ToString ());
-                            tempRoom.DeviceFilePathList.Add (devicePath);
-                        }
-                        foreach (var scene in alexaSceneList) {
-                            tempRoom.SceneFilePathList.Add (scene.SceneName);
-                        }
-                        Application.RunOnMainThread (() => {
-                            var userDeviceListPage = new AlexaSettingPage (tempRoom);
-                            userDeviceListPage.Show ();
-                            userDeviceListPage.ShowPage (action, saveAction);
-                        });
-                    } catch (Exception ex) {
-                        Utlis.WriteLine (ex.Message);
-                    } finally {
-                        Application.RunOnMainThread (() => {
-                            MainPage.Loading.Hide ();
-                        });
-                    }
-                });
-            };
-        }
-
-        #region 鍏充簬璁惧鐨勬柟娉�
-        /// <summary>
-        /// 璇诲彇Alexa璁惧鍒楄〃
-        /// </summary>
-        public List<UpdateDeviceObj> ReadDeviceList ()
-        {
-            var deviceList = new List<UpdateDeviceObj> ();
-            var requestObj = new GetDeviceListObj () { RegionID = UserConfig.Instance.CurrentRegion.Id };
-            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
-            var revertObj = MainPage.RequestHttps (API.GetDeviceList, requestJson);
-            if (revertObj.StateCode.ToUpper () == StateCode.SUCCESS) {
-                deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UpdateDeviceObj>> (revertObj.ResponseData.ToString ());
-            } else {
-                //2020-06-29 寮圭獥鎻愮ず閿欒
-                ShowErrorInfo (revertObj.StateCode);
-
-            }
-            return deviceList;
         }
 
         /// <summary>
-        /// 娣诲姞璁惧
+        /// 娣诲姞鎴栬�呮洿鏂拌澶囧拰鍦烘櫙璁惧鍒楄〃
         /// </summary>
-        public bool AddDevice (Common device)
+        bool UpdateSpeakerDeviceList (List<TargetInfo> mList)
         {
-            var uploadDevice = new AlexaDeviceObj () {
-                RegionID = UserConfig.Instance.CurrentRegion.Id, MAC = UserConfig.Instance.GatewayMAC.Replace (".", ""),
-                DeviceName = device.Name, DeviceID = device.DeviceID, SubnetID = device.SubnetID, LoopID = device.LoopID, DeviceType = device.Type.ToString ()
+            var updateSpeakerDeviceListObj = new UpdateSpeakerDeviceListObj () {
+                homeId = mAlexa.homeId,
+                tokenId = mAlexa.tokenId,
+                targetInfos = mList
             };
-            if (device.Type.ToString () == "CurtainModel") {
-                uploadDevice.DeviceType = "CurtainModule";
-            } else if (device.Type.ToString () == "LightEnergySwitch" || device.Type.ToString () == "LightSwitchSocket" || device.Type.ToString () =="LightEnergySocket") {
-                uploadDevice.DeviceType = "LightSwitch";
-            } else if (device.Type.ToString () == "ACInfrared") {
-                uploadDevice.DeviceType = "HVAC";
-            }
-            //var requestObj = new UploadDevicesObj () { Device = uploadDevice };
-            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (uploadDevice);
-            var revertObj = MainPage.RequestHttps (API.UploadDevices, requestJson);
-            if (revertObj.StateCode.ToUpper() == StateCode.SUCCESS) {
-                return true;
-            }else if (revertObj.StateCode == "Exist") {
-                Application.RunOnMainThread (() => {
-                    MainPage.AddTip (ErrorCode.AddFailed + " " + ErrorCode.NameExist + " ( " + device.Name + " )");
-                });
+            var revertObj = HttpServerRequest.Current.UpdateSpeakerDeviceList (updateSpeakerDeviceListObj);
+            if (revertObj.Code == StateCode.SUCCESS) {
                 return true;
             } else {
-                //2020-06-29 寮瑰嚭鎻愮ず閿欒
-                ShowUploadDevicesInfo (revertObj.StateCode);
+                //鐧诲綍澶辫触
+                IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
             }
             return false;
         }
 
-        /// <summary>
-        /// 涓婁紶璁惧 閿欒鎻愮ず
-        /// </summary>
-        /// <param name="stateCodeStr"></param>
-        void ShowUploadDevicesInfo (string stateCodeStr,bool bUpload = true)
-        {
-            string mes = "";
-            if (stateCodeStr == "NoRecord") {
-                //浣忓畢鏈粦瀹氱綉鍏筹紒
-                mes = ErrorCode.HomeNoRecord;
-            } else if (stateCodeStr == "NoExist") {
-                //浣忓畢涓嶅瓨鍦紒
-                mes = ErrorCode.HomeNoExist;
-            } else if (stateCodeStr == "Exist") {
-                //璁惧鍚嶇О宸插瓨鍦�
-                mes = ErrorCode.NameExist;
-            } else if (stateCodeStr == ErrorCode.NetworkError) {
-                mes = ErrorCode.NetworkError;
-            } else {
-                mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr;
-
-            }
-            if (!string.IsNullOrEmpty (mes)) {
-                Application.RunOnMainThread (() => {
-                    if (bUpload) {
-                        MainPage.AddTip (ErrorCode.AddFailed + " " + mes);
-                    } else {
-                        MainPage.AddTip ("Update failed! " + mes);
-                    }
-
-                    //new Alert ("", ErrorCode.AddFailed + " " + mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
-                });
-            }
-
-        }
-
-        /// <summary>
-        /// 閿欒鎻愰啋
-        /// </summary>
-        /// <param name="stateCodeStr"></param>
-        void ShowErrorInfo (string stateCodeStr)
-        {
-            string mes = "";
-            if (stateCodeStr == ErrorCode.NetworkError) {
-                mes = ErrorCode.NetworkError;
-            } else {
-                mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr;
-
-            }
-            if (!string.IsNullOrEmpty (mes)) {
-                Application.RunOnMainThread (() => {
-                    MainPage.AddTip (ErrorCode.OperationFailed + " " + mes);
-                });
-            }
-
-        }
-
-        /// <summary>
-        /// 鍒锋柊璁惧鍚嶅瓧
-        /// </summary>
-        public bool UpdateDevice (UpdateDeviceObj mUpdateDeviceObj)
-        {
-            var mUpdateAlexaDeviceObj = new UpdateAlexaDeviceObj () {
-                Id = mUpdateDeviceObj.Id,
-                DeviceType = mUpdateDeviceObj.DeviceType,
-                SubnetID = mUpdateDeviceObj.SubnetID,
-                DeviceID = mUpdateDeviceObj.DeviceID,
-                LoopID = mUpdateDeviceObj.LoopID,
-                DeviceName = mUpdateDeviceObj.DeviceName,
-                MAC = mUpdateDeviceObj.MAC,
-                RegionID = UserConfig.Instance.CurrentRegion.Id,
-            };
-
-            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (mUpdateAlexaDeviceObj);
-            var revertObj = MainPage.RequestHttps (API.UpdateDevice, requestJson);
-            if (revertObj.StateCode.ToUpper () == StateCode.SUCCESS) {
-                return true;
-            } else if (revertObj.StateCode == "Exist") {
-                Application.RunOnMainThread (() => {
-                    MainPage.AddTip ("Update failed!" + " " + ErrorCode.NameExist + " ( " + mUpdateDeviceObj.DeviceName + " )");
-                });
-                return true;
-            } else {
-                //2020-06-29 寮瑰嚭鎻愮ず閿欒
-                ShowUploadDevicesInfo (revertObj.StateCode, false);
-            }
-            return false;
-        }
-
-        /// <summary>
-        /// 鍒犻櫎璁惧
-        /// </summary>
-        public bool DelDevice(string commonId)
-        {
-            var requestObj = new DelDeviceObj () { Id = commonId };
-            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
-            var revertObj = MainPage.RequestHttps (API.DeleteDevice, requestJson);
-            if (revertObj.StateCode.ToUpper() == StateCode.SUCCESS) {
-                return true;
-            } else {
-                //2020-06-29 寮圭獥鎻愮ず閿欒
-                ShowErrorInfo (revertObj.StateCode);
-            }
-            return false;
-        }
         #endregion
 
-        #region 鍏充簬鍦烘櫙鐨勬柟娉�
+
+        #region 鍔犺浇View
         /// <summary>
-        /// 璇诲彇Alexa鍦烘櫙鍒楄〃
+        /// 鍒锋柊鍒楄〃View
         /// </summary>
-        public List<SceneByRegion> ReadSceneList ()
+        void RefreshListView ()
         {
-            var sceneList = new List<SceneByRegion> ();
-            var requestObj = new SceneByRegionListObj () { RegionID = UserConfig.Instance.CurrentRegion.Id };
-            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
-            var revertObj = MainPage.RequestHttps (API.GetSceneList, requestJson);
-            if (revertObj.StateCode.ToUpper() == StateCode.SUCCESS) {
-                sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SceneByRegion>> (revertObj.ResponseData.ToString ());
+            //褰撳墠閫夋嫨鐨勬槸璁惧
+            if (IsDeviceList) {
+                InitDevcieRow (bodyView);
             } else {
-                //2020-06-29 寮圭獥鎻愮ず閿欒
-                ShowErrorInfo (revertObj.StateCode);
-            }
-            return sceneList;
-        }
-
-        /// <summary>
-        /// 娣诲姞鍦烘櫙
-        /// </summary>
-        public bool AddScene (SceneAndDeviceList sceneMark)
-        {
-            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (sceneMark);
-            var revertObj = MainPage.RequestHttps (API.AddSceneAndDeviceList, requestJson);
-            if (revertObj.StateCode.ToUpper() == StateCode.SUCCESS) {
-                //var requestAddDeviceObj = new BindDeviceToSceneItemObj () { SceneId = sceneId, Command = command, DeviceID = 0, DataString = dataString };
-                //var requestAddDeviceJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestAddDeviceObj);
-                //var revertAddDeviceObj = MainPage.RequestHttps ("BindDeviceToSceneItem", requestAddDeviceJson);
-                //if (revertAddDeviceObj.StateCode.ToUpper() == StateCode.SUCCESS) {
-                    return true;
-                //}
-            } else if (revertObj.StateCode == "Exist") {
-                Application.RunOnMainThread (() => {
-                    MainPage.AddTip (ErrorCode.AddFailed + " " + ErrorCode.NameExist + " ( " + sceneMark.SceneName + " )");
-                });
-                return true;
-            } else {
-                //2020-06-29 寮瑰嚭鎻愮ず閿欒
-                ShowUploadDevicesInfo (revertObj.StateCode);
-            }
-
-            return false;
-        }
-
-        /// <summary>
-        /// 涓婁紶鍦烘櫙璁惧鎺у埗鏁版嵁
-        /// </summary>
-        //public bool AddDeviceDateToScene (int sceneId,string command,string dataString)
-        //{
-        //    var requestAddDeviceObj = new BindDeviceToSceneItemObj () { SceneId = sceneId, Command = command, DeviceID = 0, DataString = dataString };
-        //    var requestAddDeviceJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestAddDeviceObj);
-        //    var revertAddDeviceObj = MainPage.RequestHttps ("BindDeviceToSceneItem", requestAddDeviceJson);
-        //    if (revertAddDeviceObj.StateCode.ToUpper() == StateCode.SUCCESS) {
-        //        return true;
-        //    }
-        //    return false;
-        //}
-
-        /// <summary>
-        /// 鍒犻櫎鍦烘櫙
-        /// </summary>
-        public bool DelScene (string sceneId)
-        {
-            var requestObj = new DeleteSceneObj () { Id = sceneId };
-            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
-            var revertObj = MainPage.RequestHttps (API.DeleteScene, requestJson);
-            if (revertObj.StateCode.ToUpper() == StateCode.SUCCESS) {
-                return true;
-            } else {
-                //2020-06-29 寮圭獥鎻愮ず閿欒
-                ShowErrorInfo (revertObj.StateCode);
-            }
-            return false;
-        }
-        #endregion
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="bodyView"></param>
-        /// <param name="isScene"></param>
-        void AddTopTitleView (VerticalScrolViewLayout bodyView, bool isScene = false) {
-            var chooseTypeView = new RowLayout () {
-                Height = Application.GetRealHeight (80),
-                BackgroundColor = SkinStyle.Current.TitileView,
-            };
-            bodyView.AddChidren (chooseTypeView);
-            Button btnEquipmentIcon = new Button () {
-                Width = Application.GetRealHeight (65),
-                Height = Application.GetRealHeight (65),
-                UnSelectedImagePath = "Item/LogicModule.png",
-                X = Application.GetRealWidth (30),
-                Gravity = Gravity.CenterVertical,
-            };
-            chooseTypeView.AddChidren (btnEquipmentIcon);
-         
-            Button btnEquipmentType = new Button () {
-                Width = Application.GetRealHeight (460),
-                X = btnEquipmentIcon.Right,
-                TextAlignment = TextAlignment.CenterLeft,
-                Text = Language.StringByID (R.MyInternationalizationString.Device),
-                TextColor = SkinStyle.Current.TextColor1,
-                SelectedTextColor = SkinStyle.Current.DialogTextColor
-            };
-            chooseTypeView.AddChidren (btnEquipmentType);
-
-            if (isScene) {
-                btnEquipmentIcon.UnSelectedImagePath = "Scene/Scene.png";
-                btnEquipmentType.Text = Language.StringByID (R.MyInternationalizationString.Scenes);
+                InitSceneRow (bodyView);
             }
         }
 
         /// <summary>
-        /// 娣诲姞璁惧鐣岄潰
+        /// 娣诲姞璁惧RowView
         /// </summary>
-        public void InitDevcieRow (List<UpdateDeviceObj> list, VerticalScrolViewLayout bodyView)
+        public void InitDevcieRow (VerticalScrolViewLayout bodyView)
         {
             bodyView.RemoveAll ();
 
-            if (list.Count > 0) {
-                //娣诲姞鏍囬
-                AddTopTitleView (bodyView);
-            }
+            if (targetInfoList == null) return;
 
-            foreach (var device in list) {
-                var rowView = new RowLayout () {
-                    Height = Application.GetRealHeight (110),
-                };
-                bodyView.AddChidren (rowView);
-                var btn = new Button () {
-                    X = Application.GetRealWidth(60),
-                    Width = Application.GetRealWidth (640 - 60),
-                    Text = device.DeviceName,
-                    TextAlignment = TextAlignment.CenterLeft,
-                    TextColor = SkinStyle.Current.TextColor1,
-                };
-                rowView.AddChidren (btn);
+            foreach (var device in targetInfoList) {
+                //杩囨护鍦烘櫙鏁版嵁
+                if (device.isDevice == false) continue;
 
-                var btnDel = new Button () { 
-                    Text = "Delete",
-                    BackgroundColor = SkinStyle.Current.DelColor,
-                };
-                rowView.AddRightView (btnDel);
-
-                btnDel.MouseUpEventHandler += (sender, e) => {
-                    var alert = new Alert ("", "Do you want to delete device?", "No", "Yes");
-                    alert.Show ();
-                    alert.ResultEventHandler += (s, dd) => {
-                        if (dd) {
-                            //if (DelDevice (device.Id)) {
-                            //    rowView.RemoveFromParent ();
-                            //    list.Remove (device);
-                            //}
-
-                            System.Threading.Tasks.Task.Run (() => {
-                                Application.RunOnMainThread (() => {
-                                    MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load));
-                                });
-                                try {
-                                    var result = DelDevice (device.Id);
-                                    Application.RunOnMainThread (() => {
-                                        if (result) {
-                                            rowView.RemoveFromParent ();
-                                            list.Remove (device);
-                                        }
-                                    });
-
-                                } catch { } finally {
-
-                                    Application.RunOnMainThread (() => {
-                                        MainPage.Loading.Hide ();
-                                    });
-                                }
-                            });
-                        }
-                    };
-                };
-            }
-        }
-
-        /// <summary>
-        /// 娣诲姞鍦烘櫙鐣岄潰
-        /// </summary>
-        public void InitSceneRow (List<SceneByRegion> list, VerticalScrolViewLayout bodyView)
-        {
-            if (list.Count > 0) {
-                //娣诲姞鏍囬
-                AddTopTitleView (bodyView, true);
-            }
-
-            foreach (var scene in list) {
                 var rowView = new RowLayout () {
                     Height = Application.GetRealHeight (110),
                 };
@@ -848,45 +214,44 @@
                 var btn = new Button () {
                     X = Application.GetRealWidth (60),
                     Width = Application.GetRealWidth (640 - 60),
-                    Text = scene.SceneName,
+                    Text = device.targetName,
                     TextAlignment = TextAlignment.CenterLeft,
                     TextColor = SkinStyle.Current.TextColor1,
                 };
                 rowView.AddChidren (btn);
-                btn.MouseUpEventHandler += (dd,ff) => {
-                    //var alexaSceneSettingPage = new AlecaSceneEditPage ();
-                    //UserMiddle.SettingPageView.AddChidren (alexaSceneSettingPage);
-                    //alexaSceneSettingPage.ShowScene (scene);
-                    //UserMiddle.SettingPageView.PageIndex = 2;
-                };
 
                 var btnDel = new Button () {
-                    Text = "Delete",
+                    TextID = R.MyInternationalizationString.Delete,
                     BackgroundColor = SkinStyle.Current.DelColor,
                 };
                 rowView.AddRightView (btnDel);
 
                 btnDel.MouseUpEventHandler += (sender, e) => {
-                    var alert = new Alert ("", "Do you want to delete scene?", "No", "Yes");
+                    Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipDeleteEquipmentMessage), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
                     alert.Show ();
                     alert.ResultEventHandler += (s, dd) => {
                         if (dd) {
-                            //if (DelScene (scene.SceneId)) {
-                            //    rowView.RemoveFromParent ();
-                            //    list.Remove (scene);
-                            //}
 
                             System.Threading.Tasks.Task.Run (() => {
                                 Application.RunOnMainThread (() => {
                                     MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load));
                                 });
                                 try {
-                                    var result = DelScene (scene.SceneId);
+                                    var newList = new List<TargetInfo> (targetInfoList);
+                                    newList.Remove (device);
+
+                                    bool result = UpdateSpeakerDeviceList (newList);
+
                                     Application.RunOnMainThread (() => {
                                         if (result) {
                                             rowView.RemoveFromParent ();
-                                            list.Remove (scene);
+                                            targetInfoList.Remove (device);
+                                        } else {
+                                            new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.DeleteFailed),
+                                          Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+
                                         }
+
                                     });
 
                                 } catch { } finally {
@@ -896,11 +261,236 @@
                                     });
                                 }
                             });
+
+                        }
+                    };
+                };
+            }
+        }
+
+
+        /// <summary>
+        /// 娣诲姞鍦烘櫙鐣岄潰
+        /// </summary>
+        public void InitSceneRow (VerticalScrolViewLayout bodyView)
+        {
+            bodyView.RemoveAll ();
+
+            if (targetInfoList == null) return;
+
+            foreach (var scene in targetInfoList) {
+
+                if (scene.isDevice) continue;
+
+                var rowView = new RowLayout () {
+                    Height = Application.GetRealHeight (110),
+                };
+                bodyView.AddChidren (rowView);
+                var btn = new Button () {
+                    X = Application.GetRealWidth (60),
+                    Width = Application.GetRealWidth (640 - 60),
+                    Text = scene.targetName,
+                    TextAlignment = TextAlignment.CenterLeft,
+                    TextColor = SkinStyle.Current.TextColor1,
+                };
+                rowView.AddChidren (btn);
+                btn.MouseUpEventHandler += (dd, ff) => {
+                    //var alexaSceneSettingPage = new AlecaSceneEditPage ();
+                    //UserMiddle.SettingPageView.AddChidren (alexaSceneSettingPage);
+                    //alexaSceneSettingPage.ShowScene (scene);
+                    //UserMiddle.SettingPageView.PageIndex = 2;
+                };
+
+                var btnDel = new Button () {
+                    //Text = "Delete",
+                    TextID = R.MyInternationalizationString.Delete,
+                    BackgroundColor = SkinStyle.Current.DelColor,
+                };
+                rowView.AddRightView (btnDel);
+
+                btnDel.MouseUpEventHandler += (sender, e) => {
+                    Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.SureDelete), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
+                    alert.Show ();
+                    alert.ResultEventHandler += (s, dd) => {
+                        if (dd) {
+                            System.Threading.Tasks.Task.Run (() => {
+                                Application.RunOnMainThread (() => {
+                                    MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load));
+                                });
+                                try {
+                                    var newList = new List<TargetInfo> (targetInfoList);
+                                    newList.Remove (scene);
+                                    bool result = UpdateSpeakerDeviceList (newList);
+                                    //var result = true;
+                                    Application.RunOnMainThread (() => {
+                                        if (result) {
+                                            rowView.RemoveFromParent ();
+                                            targetInfoList.Remove (scene);
+                                        } else {
+                                            new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.DeleteFailed),
+                                          Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+
+                                        }
+
+                                    });
+
+                                } catch { } finally {
+
+                                    Application.RunOnMainThread (() => {
+                                        MainPage.Loading.Hide ();
+                                    });
+                                }
+                            });
+
+
                         }
                     };
                 };
             }
 
         }
+        #endregion
+
+
+        #region 娣诲姞璁惧鍜屽満鏅鐞嗘柟娉�
+
+        ///// <summary>
+        ///// 鐢熸垚璁惧鐩爣鏁版嵁
+        ///// </summary>
+        ///// <param name="device"></param>
+        ///// <param name="path"></param>
+        ///// <returns></returns>
+        //AlexaDeviceListItem GetAlexaDeviceListItem (Common device, string path)
+        //{
+        //    var mAlexaDeviceTyp = HDLCommon.Current.GetAlexaDeviceType (device.Type);
+        //    var deviceControl = new Obj_Buspro_DeviceControl () {
+        //        SubnetID = device.SubnetID,
+        //        DeviceID = device.DeviceID,
+        //        LoopID = device.LoopID,
+        //        GatewayID = UserConfig.Instance.MacMark,
+        //        DevicePath = device.SavePath,
+        //    };
+        //    var mAlexaDeviceItem = new AlexaDeviceListItem () {
+        //        DeviceName = device.Name,
+        //        NicksName = device.Name,
+        //        DeviceType = (int)mAlexaDeviceTyp,
+        //        ControlObj = deviceControl,
+        //    };
+        //    return mAlexaDeviceItem;
+        //}
+
+        ///// <summary>
+        ///// 娣诲姞鎴栬�呯紪杈� 璁惧鍜屽満鏅垪琛�
+        ///// 鍚屾椂鍒锋柊鍒楄〃
+        ///// </summary>
+        //void AddAlexaDeviceAndSceneWithRefresh (List<AlexaDeviceListItem> mDeviceList, List<SceneListItem> mSceneList)
+        //{
+        //    if (AddAlexaDeviceAndSceneWithOneRoom (mDeviceList, mSceneList)) {
+        //        //缂栬緫鎴愬姛锛岄噸鏂板埛鏂拌幏鍙�
+        //        GetDeviceAndSceneList ();
+        //    }
+        //}
+
+        ///// <summary>
+        ///// 娣诲姞鎴栬�呯紪杈� 璁惧鍜屽満鏅垪琛�
+        ///// </summary>
+        ///// <param name="mDeviceList"></param>
+        ///// <param name="mSceneList"></param>
+        ///// <returns></returns>
+        //bool AddAlexaDeviceAndSceneWithOneRoom (List<TargetInfo> mList)
+        //{
+        //    //鎻愪氦鏇存柊璁惧鏁版嵁
+        //    var mAlexaRooms = new AlexaRoomsItem () {
+        //        RoomName = UserConfig.Instance.CurrentRegion.homeName,
+        //        LayerName = UserConfig.Instance.CurrentRegion.homeName,
+        //        DeviceList = mDeviceList,
+        //        SceneList = mSceneList
+        //    };
+        //    var AlexaRoomsList = new List<AlexaRoomsItem> ();
+        //    AlexaRoomsList.Add (mAlexaRooms);
+        //    return AddDevicesScene (AlexaRoomsList);
+        //}
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="lsit"></param>
+        void AddDevicesSceneList (List<TargetInfo> lsit)
+        {
+            System.Threading.Tasks.Task.Run (() => {
+                Application.RunOnMainThread (() => {
+                    MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load));
+                });
+                try {
+                    
+                    bool result = UpdateSpeakerDeviceList (lsit);
+                    //var result = true;
+                    Application.RunOnMainThread (() => {
+                        if (result) {
+                            GetDeviceAndSceneList ();
+                        } 
+                    });
+
+                } catch { } finally {
+                    Application.RunOnMainThread (() => {
+                        MainPage.Loading.Hide ();
+                    });
+                }
+            });
+        }
+
+        /// <summary>
+        /// 鎵撳紑鍦烘櫙鎴栬�呰澶囨坊鍔犻〉闈�
+        /// </summary>
+        void OpenAlexaSettingPage ()
+        {
+            Action<List<TargetInfo>> saveAction = (lsit) => {
+                AddDevicesSceneList (lsit);
+            };
+
+            System.Threading.Tasks.Task.Factory.StartNew (() => {
+                try {
+                    Application.RunOnMainThread (() => {
+                        MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load));
+                    });
+                    var tempRoom = new Room ();
+                    //if (IsDeviceList) {
+                    //    foreach (var device in alexaDeviceList) {
+                    //        tempRoom.DeviceFilePathList.Add (device.ControlObj.DevicePath);
+                    //    }
+                    //} else {
+                    //    foreach (var scene in alexaSceneList) {
+                    //        tempRoom.SceneFilePathList.Add (scene.SceneName);
+                    //    }
+                    //}
+                    Application.RunOnMainThread (() => {
+                        if (IsDeviceList) {
+                            var userDeviceListPage = new AlexaSettingPage (tempRoom);
+                            userDeviceListPage.Show ();
+                            userDeviceListPage.ShowPage (null,null);
+                        } else {
+                            var mAlexaSettingScenePage = new AlexaSettingScenePage (targetInfoList);
+                            mAlexaSettingScenePage.Show ();
+                            mAlexaSettingScenePage.ShowPage (saveAction);
+
+                        }
+
+
+                    });
+                } catch (Exception ex) {
+                    Shared.Utlis.WriteLine (ex.Message);
+                } finally {
+                    Application.RunOnMainThread (() => {
+                        MainPage.Loading.Hide ();
+                    });
+                }
+            });
+        }
+
+
+
+
+        #endregion
+
     }
 }

--
Gitblit v1.8.0