From 94e4e5b9fd3da964c44b7b14227d6fe2bbb426d7 Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期四, 02 四月 2020 13:56:39 +0800
Subject: [PATCH] 2020-04-02-2

---
 ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs |  294 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 231 insertions(+), 63 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs b/ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs
index 51e053c..1b5cb52 100755
--- a/ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs
+++ b/ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs
@@ -2,6 +2,8 @@
 using System.Collections.Generic;
 using System.Globalization;
 using Shared.Common;
+using Shared.Phone.UserCenter;
+using ZigBee.Device;
 
 namespace Shared.Phone.Device.CommonForm
 {
@@ -19,7 +21,24 @@
         /// <summary>
         /// action
         /// </summary>
-        public Action action;
+        public Action<CommonDevice, Common.Room> EditAction;
+        /// <summary>
+        /// curRoom
+        /// </summary>
+        private Common.Room curRoom;
+        /// <summary>
+        /// curRoom
+        /// </summary>
+        private Common.Room befRoom;
+        /// <summary>
+        /// sharedRow
+        /// </summary>
+        private DeviceInfoRow sharedRow;
+        /// <summary>
+        /// functionTypeRow
+        /// </summary>
+        private DeviceInfoRow functionTypeRow;
+
 
         #endregion
 
@@ -29,7 +48,7 @@
         /// </summary>
         public override void RemoveFromParent()
         {
-            action();
+            EditAction = null;
             base.RemoveFromParent();
         }
         #endregion
@@ -51,13 +70,13 @@
         /// </summary>
         /// <param name="device"></param>
         /// <param name="room"></param>
-        public void Show(DeviceUI device, Common.Room room)
+        public void Show(CommonDevice device, Common.Room room)
         {
             Init(device);
 
             AddTop();
 
-            AddBodyView(device);
+            AddBodyView(device,room);
 
         }
 
@@ -83,7 +102,7 @@
         /// <summary>
         /// AddBodyView
         /// </summary>
-        public void AddBodyView(DeviceUI device)
+        public void AddBodyView(CommonDevice device, Common.Room room)
         {
             bodyFrameLayout = new FrameLayout()
             {
@@ -100,7 +119,7 @@
                 Height = Application.GetMinRealAverage(207),
                 Gravity = Gravity.CenterHorizontal,
                 BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
-                Radius=(uint)Application.GetMinRealAverage(207)
+                Radius = (uint)Application.GetMinRealAverage(207/2)
             };
             bodyFrameLayout.AddChidren(deviceBG);
 
@@ -111,7 +130,7 @@
                 Height = Application.GetMinRealAverage(184),
                 Gravity = Gravity.CenterHorizontal,
                 BackgroundColor = ZigbeeColor.Current.GXCSelectedBackgroundColor,
-                Radius = (uint)Application.GetMinRealAverage(184)
+                Radius = (uint)Application.GetMinRealAverage(184/2)
             };
             bodyFrameLayout.AddChidren(deviceBG2);
 
@@ -125,14 +144,17 @@
             };
             bodyFrameLayout.AddChidren(deviceIMG);
 
+            var info = Common.LocalDevice.Current.GetDeviceBelongEnumInfo(device);
+
             var deviceTypeName = new Button()
             {
                 Y = Application.GetRealHeight(360),
                 Width = Application.GetRealWidth(900),
                 Height = Application.GetRealHeight(80),
                 TextColor = ZigbeeColor.Current.GXCTextBlackColor,
-                Text = DeviceUI.GetDeviceTypeName(device.CommonDevice.Type),
-                Gravity = Gravity.CenterHorizontal
+                TextID = info.BeloneTextId,
+                Gravity = Gravity.CenterHorizontal,
+                TextSize = 15
             };
             bodyFrameLayout.AddChidren(deviceTypeName);
 
@@ -144,6 +166,8 @@
                 BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
             };
             bodyFrameLayout.AddChidren(infoFL);
+            var rectCornerID = HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight;
+            infoFL.SetCornerWithSameRadius(Application.GetRealHeight(58), rectCornerID);
 
             var tipBtn = new Button
             {
@@ -158,49 +182,153 @@
             };
             infoFL.AddChidren(tipBtn);
 
-            var nameRow = new DeviceInfoEditRow(170);
+            var infoScrolView = new VerticalScrolViewLayout
+            {
+                Y = Application.GetRealHeight(170-12),
+                Height = Application.GetRealHeight(600),
+                ScrollEnabled = false,
+                VerticalScrollBarEnabled = false
+            };
+            infoFL.AddChidren(infoScrolView);
+
+            var nameFL = new FrameLayout
+            {
+                Height = Application.GetRealHeight(127 + 12)
+            };
+            infoScrolView.AddChidren(nameFL);
+            var nameRow = new DeviceInfoEditRow(12);
             nameRow.Init();
             nameRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.FunctionName)} : ");
-            nameRow.SetTitle(string.IsNullOrEmpty(device.CommonDevice.DeviceEpointName) ? Language.StringByID(R.MyInternationalizationString.UNKnown) : device.CommonDevice.DeviceName);
-            infoFL.AddChidren(nameRow);
+            nameRow.SetTitle(string.IsNullOrEmpty(Common.LocalDevice.Current.GetDeviceEpointName(device)) ? Language.StringByID(R.MyInternationalizationString.UNKnown) : Common.LocalDevice.Current.GetDeviceEpointName(device));
+            nameFL.AddChidren(nameRow);
 
-            var zoneRow = new DeviceInfoRow(308);
+
+            var zoneFL = new FrameLayout
+            {
+                Height = Application.GetRealHeight(127 + 12)
+            };
+            if (room != null && room.IsLove == false)
+            {
+                infoScrolView.AddChidren(zoneFL);
+            }
+            var zoneRow = new DeviceInfoRow(12);
             zoneRow.Init();
             zoneRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.BelongZone)} : ");
             zoneRow.SetTitle(roomName);
-            infoFL.AddChidren(zoneRow);
+            zoneFL.AddChidren(zoneRow);
 
-            var modelRow = new DeviceInfoRow(446);
+            var modelFL = new FrameLayout
+            {
+                Height = Application.GetRealHeight(127 + 12)
+            };
+            infoScrolView.AddChidren(modelFL);
+            var modelRow = new DeviceInfoRow(12);
             modelRow.Init();
             modelRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.BelongModel)} : ");
-            modelRow.SetTitle(string.IsNullOrEmpty(device.CommonDevice.DeviceName) ? Language.StringByID(R.MyInternationalizationString.UNKnown) : device.CommonDevice.DeviceName);
-            infoFL.AddChidren(modelRow);
+            modelRow.SetTitle(string.IsNullOrEmpty(device.DeviceName) ? Language.StringByID(R.MyInternationalizationString.UNKnown) : device.DeviceName);
+            modelRow.HideNext(true);
+            modelFL.AddChidren(modelRow);
 
-            var sharedRow = new DeviceInfoRow(585);
-            sharedRow.Init();
-            sharedRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.Share)} : ");
-            sharedRow.SetTitle("2浜�");
-            infoFL.AddChidren(sharedRow);
+            if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.AirSwitch)
+            {
+                var typeFL = new FrameLayout
+                {
+                    Height = Application.GetRealHeight(127 + 12)
+                };
+                infoScrolView.AddChidren(typeFL);
+                functionTypeRow = new DeviceInfoRow(12);
+                functionTypeRow.Init();
+                functionTypeRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.FunctionType)} : ");
+                //functionTypeRow.SetTitle(device.CommonDevice.DfunctionType);
+                typeFL.AddChidren(functionTypeRow);
+                var dfunctionType = device.DfunctionType;
+
+                //鍔熻兘绫诲瀷鐨勭炕璇戝悕瀛�
+                string strT = string.Empty;
+                if (dfunctionType == DeviceFunctionType.A鐏厜)
+                {
+                    strT = Language.StringByID(R.MyInternationalizationString.uLight);
+                }
+                else if (dfunctionType == DeviceFunctionType.A寮�鍏�)
+                {
+                    strT = Language.StringByID(R.MyInternationalizationString.uSwitch);
+                }
+                else if (dfunctionType == DeviceFunctionType.A鎻掑骇)
+                {
+                    strT = Language.StringByID(R.MyInternationalizationString.uSocket1);
+                }
+                functionTypeRow.SetTitle(strT);
+
+                functionTypeRow.ClickBtn.MouseUpEventHandler += (sender, e) =>
+                {
+                    var DfunctionType = device.DfunctionType;
+
+                    //鍔熻兘绫诲瀷鐨勭炕璇戝悕瀛�
+                    int nowSelectNo = 1;
+                    string strType = string.Empty;
+                    if (DfunctionType == DeviceFunctionType.A鐏厜)
+                    {
+                        strType = Language.StringByID(R.MyInternationalizationString.uLight);
+                        nowSelectNo = 1;
+                    }
+                    else if (DfunctionType == DeviceFunctionType.A寮�鍏�)
+                    {
+                        strType = Language.StringByID(R.MyInternationalizationString.uSwitch);
+                        nowSelectNo = 0;
+                    }
+                    else if (DfunctionType == DeviceFunctionType.A鎻掑骇)
+                    {
+                        strType = Language.StringByID(R.MyInternationalizationString.uSocket1);
+                        nowSelectNo = 2;
+                    }
+                    //鏄剧ず鍒楄〃
+                    var listText = new List<string>();
+                    listText.Add(Language.StringByID(R.MyInternationalizationString.uSwitch));//寮�鍏�
+                    listText.Add(Language.StringByID(R.MyInternationalizationString.uLight));//鐏厜
+                    listText.Add(Language.StringByID(R.MyInternationalizationString.uSocket1));//鎻掑骇
+                                                                                               //鏍囬:閫夋嫨鍔熻兘绫诲瀷
+                    var title = Language.StringByID(R.MyInternationalizationString.uSelectFunctionType);
+
+                    var form = new BottomItemSelectForm();
+                    form.AddForm(title, listText, nowSelectNo);
+                    form.FinishSelectEvent += (selectNo) =>
+                    {
+                        functionTypeRow.NameText.Text = listText[selectNo];
+                        nowSelectNo = selectNo;
+                        //璁板綍璧峰綋鍓嶉�夋嫨鐨勫姛鑳界被鍨�
+                        if (selectNo == 0)
+                        {
+                            device.DfunctionType  = DeviceFunctionType.A寮�鍏�;
+                        }
+                        else if (selectNo == 1)
+                        {
+                            device.DfunctionType = DeviceFunctionType.A鐏厜;
+                        }
+                        else
+                        {
+                            device.DfunctionType = DeviceFunctionType.A鎻掑骇;
+                        }
+                    };
+                };
+            }
 
 
-            var confirmBtn = new CommonForm.CompleteButton(962, 907, 127);
-            confirmBtn.SetTitle(R.MyInternationalizationString.Confrim);
+            var confirmBtn = new CommonForm.CompleteButton(962, 900, 127);
+            confirmBtn.SetTitle(R.MyInternationalizationString.Save);
             infoFL.AddChidren(confirmBtn);
 
             #region event
             EventHandler<MouseEventArgs> selectZoneEvent = (sender, e) =>
             {
-                //UserCenter.SelectRoomForm selectedRoom = new UserCenter.SelectRoomForm();
-                //selectedRoom.AddForm(selectedRoom, roomNameList);
-                //selectedRoom.ActionSelectRoom += ((rList) =>
-                //{
-                //    roomNameList = rList;
-                //    zone.Text = Shared.Common.Room.CurrentRoom.GetRoomName(roomNameList);
-                //});
+                var zone = new SelectZone();
+                zone.Init();
+                zone.ZoneAction += (selectRoom) =>
+                {
+                    curRoom = selectRoom;
+                    zoneRow.SetTitle(HdlRoomLogic.Current.GetZoneName(selectRoom));
+                };
             };
-            //zoneRight.MouseUpEventHandler += selectZoneEvent;
-            //zoneFL.MouseUpEventHandler += selectZoneEvent;
-            //zone.MouseUpEventHandler += selectZoneEvent;
+            zoneRow.ClickBtn.MouseUpEventHandler += selectZoneEvent;
 
             EventHandler<MouseEventArgs> selectDeviceIconEvent = (sender, e) =>
             {
@@ -212,38 +340,76 @@
                 {
                     deviceIMG.UnSelectedImagePath = unSelectedImagePath;
                     deviceIMG.SelectedImagePath = selectedImagePath;
+                    device.IsCustomizeImage = true;
                 };
             };
             deviceIMG.MouseUpEventHandler += selectDeviceIconEvent;
 
-            confirmBtn.MouseUpEventHandler += async (sender, e) =>
+            confirmBtn.MouseUpEventHandler +=  (sender, e) =>
             {
-                //if (device.CommonDevice == null)
-                //{
-                //    CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
-                //    return;
-                //}
-                //var result = await Shared.Common.LocalDevice.Current.ReName(device.CommonDevice, deviceName.Text.Trim());
-                //if (result)
-                //{
-                //    var alertSuccess = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.Success), Language.StringByID(R.MyInternationalizationString.Confrim));
-                //    alertSuccess.Show();
-                //    alertSuccess.ResultEventHandler += (senderSuccess, eSuccess) =>
-                //    {
-                //        //鏀瑰浘鐗�
-                //        device.IconPath = deviceIMG.UnSelectedImagePath;
-                //        device.IsCustomizeImage = true;
-                //        device.ReSave();
-                //        //鏀规埧闂�
-                //        Shared.Common.Room.CurrentRoom.ChangedRoom(device.CommonDevice, roomNameList);
-                //        RemoveFromParent();
-                //    };
-                //}
-                //else
-                //{
-                //    return;
-                //    //CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
-                //}
+                try
+                {
+                    CommonPage.Loading.Start();
+                    if (device == null)
+                    {
+                        CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.FailedPleaseTryAgain));
+                        return;
+                    }
+                    if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.AirSwitch)
+                    {
+                        if (device.IsCustomizeImage == false)
+                        {
+                            if (device.DfunctionType == DeviceFunctionType.A寮�鍏�)
+                            {
+                                device.IconPath = "Device/Switch.png";
+                            }
+                            else if (device.DfunctionType == DeviceFunctionType.A鎻掑骇)
+                            {
+                                device.IconPath = "Device/Socket1.png";
+                            }
+                            else if (device.DfunctionType == DeviceFunctionType.A鐏厜)
+                            {
+                                device.IconPath = "Device/Light.png";
+                            }
+                        }
+                        else
+                        {
+                            //鏀瑰浘鐗�
+                            device.IconPath = deviceIMG.UnSelectedImagePath;
+                        }
+                    }
+                    else
+                    {
+                        //鏀瑰浘鐗�
+                        device.IconPath = deviceIMG.UnSelectedImagePath;
+                    }
+                    bool result;
+                    new System.Threading.Thread(async () =>
+                    {
+                        result = await LocalDevice.Current.ReName(device, nameRow.NameText.Text.Trim());
+                        Application.RunOnMainThread(() =>
+                        {
+                            CommonPage.Loading.Hide();
+                            if (result)
+                            {
+                                //鏀规埧闂�
+                                HdlRoomLogic.Current.ChangedRoom(device, curRoom.Id);
+                                device.ReSave();
+                                EditAction?.Invoke(device, curRoom);
+                                RemoveFromParent();
+                            }
+                            else
+                            {
+                                CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.FailedPleaseTryAgain));
+                            }
+                        });
+                    })
+                    { IsBackground = true }.Start();
+                }
+                catch
+                {
+                    CommonPage.Loading.Hide();
+                }
             };
 
             #endregion
@@ -253,9 +419,11 @@
         /// Init
         /// </summary>
         /// <param name="device"></param>
-        public void Init(DeviceUI device)
+        public void Init(CommonDevice device)
         {
-            roomName = Common.Room.CurrentRoom.GetRoomNameByDevice(device.CommonDevice);
+            roomName = HdlRoomLogic.Current.GetRoomNameByDevice(device, "锛�");
+            befRoom = HdlRoomLogic.Current.GetRoomByDevice(device);
+            curRoom = HdlRoomLogic.Current.GetRoomByDevice(device);
         }
         #endregion
     }

--
Gitblit v1.8.0