From 3aa397ab145382935492b11c1f18c9634e69910b Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 10 十二月 2020 16:45:00 +0800
Subject: [PATCH] 请合并,门锁和晾衣架第一版代码

---
 ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundContentForDeviceChange.cs |  609 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 609 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundContentForDeviceChange.cs b/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundContentForDeviceChange.cs
new file mode 100755
index 0000000..e406171
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundContentForDeviceChange.cs
@@ -0,0 +1,609 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using Shared.Phone.UserCenter.SmartSound.Util;
+
+namespace Shared.Phone.UserCenter.SmartSound.Forms
+{
+    public class SmartSoundContentForDeviceChange : EditorCommonForm
+    {
+
+        /// <summary>
+        /// 褰撳墠閫変腑鐨勬埧闂�
+        /// </summary>
+        private SmartSound.Room CurrentRoom = null;
+
+        private FrameLayout ContentLayout = null;
+
+        private FrameLayout DeviceListViewFrameLayout = null;
+        /// <summary>
+        /// 鍦烘櫙 listView
+        /// </summary>
+        private VerticalListControl SceneListView = null;
+        /// <summary>
+        /// 璁惧 listView
+        /// </summary>
+        private VerticalListControl DeviceListView = null;
+        /// <summary>
+        /// 娌℃湁鏁版嵁鐨勬椂鍊欙紝鎻愮ず鐢�
+        /// </summary>
+        private FrameLayout TipLayout = null;
+
+        private List<string> TabList = new List<string>()
+        {
+            Language.StringByID(R.MyInternationalizationString.uLight),
+            Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100),
+            Language.StringByID(R.MyInternationalizationString.AC)
+        };
+
+        private int CurrentSelectIndex = 0;
+        private int imageWith = 683;
+        private int imageHeight = 392;
+
+        /// <summary>
+        /// 閫夋嫨鎴块棿涓殑璁惧
+        /// </summary>
+        /// <param name="_room"> 褰撳墠鎴块棿</param>       
+        public SmartSoundContentForDeviceChange(SmartSound.Room _room)
+        {
+            this.CurrentRoom = _room;
+        }
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        public void ShowForm()
+        {
+            //璁剧疆鏍囬淇℃伅
+            base.SetTitleText(CurrentRoom.RoomName);
+
+            //鍒濆鍖栦腑閮ㄦ帶浠�
+            this.InitMiddleFrame();
+        }
+
+        private void InitMiddleFrame()
+        {
+            //1.鍦烘櫙銆佸姛鑳藉鑸潯
+            var switchContr = new SceneFunctionSwitchControl();
+            this.bodyFrameLayout.AddChidren(switchContr);
+            switchContr.Gravity = Gravity.CenterVertical;
+            switchContr.Width = Application.GetRealWidth(650);
+            switchContr.Y = Application.GetRealHeight(40);
+            
+            ContentLayout = new FrameLayout();
+            this.bodyFrameLayout.AddChidren(ContentLayout);
+            ContentLayout.Height = this.bodyFrameLayout.Height - switchContr.Height - Application.GetRealHeight(40);
+            ContentLayout.Y = switchContr.Height + Application.GetRealHeight(40);
+
+            var listTitle = new List<string>();
+            listTitle.Add(Language.StringByID(R.MyInternationalizationString.uScence));
+            listTitle.Add(Language.StringByID(R.MyInternationalizationString.uFunction));
+
+            //璁剧疆鍒濆鍊�
+            switchContr.SetDefultIndex(0);
+
+            //閫夋嫨浜嬩欢
+            switchContr.SelectTabEvent += (selectIndex) =>
+            {
+                //鍒锋柊bodyView
+                if (selectIndex == 0)
+                {
+                    LoadSceneView();
+                }
+                else
+                {
+                    LoadFunction();
+                }
+            };
+
+            //寮�濮嬪垵濮嬪寲
+            switchContr.InitControl(listTitle);
+
+        }
+
+        /// <summary>
+        /// 鍔犺浇鍦烘櫙鐣岄潰
+        /// </summary>
+        private void LoadSceneView()
+        {
+            try
+            {
+                //3.璁惧鍒楄〃 ListView
+                ContentLayout.RemoveAll();
+
+                var tipLayout = new FrameLayout();
+                ContentLayout.AddChidren(tipLayout);
+                tipLayout.Visible = false;
+                ShowNoFunctionTip(tipLayout);
+
+                SceneListView = new VerticalListControl();
+                ContentLayout.AddChidren(SceneListView);
+                SceneListView.Y = Application.GetRealHeight(40);
+                SceneListView.RemoveAll();
+
+                for (int i = 0; i < CurrentRoom.SceneList.Count; i++)
+                {
+                    SmartSound.Scene scene = CurrentRoom.SceneList[i];
+                    var roomRowLayout = new SceneRowLayout(this, scene, i);
+                    SceneListView.AddChidren(roomRowLayout);
+                    roomRowLayout.InitControl();
+                }
+
+                if (SceneListView.ChildrenCount > 5)
+                {
+                    TextView textView = new TextView();
+                    textView.Height = Application.GetRealHeight(127 * 3);
+                    SceneListView.AddChidren(textView);
+                }
+
+                if (SceneListView.ChildrenCount == 0)
+                {
+                    tipLayout.Visible = true;
+                }
+                else
+                {
+                    tipLayout.Visible = false;
+                }
+            }
+            catch (Exception ex)
+            {
+                string eoor = ex.Message;
+            }
+        }
+
+        private void LoadFunction()
+        {
+            try
+            {
+                
+                ContentLayout.RemoveAll();
+
+                FrameLayout tab_layout = new FrameLayout();
+                ContentLayout.AddChidren(tab_layout);
+                tab_layout.Height = Application.GetRealHeight(170);
+                tab_layout.Y = 0;
+
+                //娣诲姞 ListView 鎻愮ず
+                TipLayout = new FrameLayout();
+                ContentLayout.AddChidren(TipLayout);
+                TipLayout.Visible = false;
+                TipLayout.Y = tab_layout.Height;
+                ShowNoFunctionTip(TipLayout);
+
+                Buttons.Clear();
+
+                //娣诲姞鍔熻兘椤�
+                for (int i = 0; i < TabList.Count; i++)
+                {
+                    Button button = new Button();
+                    tab_layout.AddChidren(button);
+                    button.Width = Application.GetRealWidth(250);
+                    button.Height= Application.GetRealWidth(250);
+                    button.Text = TabList[i];
+                    button.X = ControlCommonResourse.XXLeft / 2 + i * button.Width;
+                    button.AddTag("Index", i);
+                    Buttons.Add(button);
+
+                    button.MouseUpEventHandler += (sender, e) =>
+                    {
+                        Button btn = sender as Button;
+                        CurrentSelectIndex = (int)btn.GetTagByKey("Index");
+                        RefreshButtonState();
+                        RefreshFunctionListView();
+                    };
+                }
+
+                //娣诲姞 ListView
+                DeviceListViewFrameLayout = new FrameLayout();
+                ContentLayout.AddChidren(DeviceListViewFrameLayout);
+                DeviceListViewFrameLayout.Y = tab_layout.Height;
+                DeviceListViewFrameLayout.Height = ContentLayout.Height - tab_layout.Height;
+
+                RefreshButtonState();
+                RefreshFunctionListView();
+            }
+            catch (Exception ex)
+            {
+                string error = ex.Message;
+            }
+        }
+
+        private void RefreshFunctionListView()
+        {
+            try
+            {
+
+                DeviceListViewFrameLayout.RemoveAll();
+
+                DeviceListView = new VerticalListControl();
+                DeviceListViewFrameLayout.AddChidren(DeviceListView);
+                DeviceListView.Height = DeviceListViewFrameLayout.Height;
+                DeviceListView.RemoveAll();
+
+                switch (CurrentSelectIndex)
+                {
+                    case 0:// 鐏厜
+                        {
+                            int n = 0;
+                            for (int i = 0; i < CurrentRoom.DeviceList.Count; i++)
+                            {
+                                SmartSound.Device device = CurrentRoom.DeviceList[i];
+                                //鐏厜
+                                if (device.DeviceType == 1 || device.DeviceType == 2 || device.DeviceType == 3)
+                                {
+                                    var deviceRowLayout = new DeviceRowLayout(this, device, n);
+                                    DeviceListView.AddChidren(deviceRowLayout);
+                                    deviceRowLayout.InitControl();
+                                    n++;
+                                }
+                            }
+                        }
+                        break;
+                    case 1: // 绐楀笜
+                        {
+                            int n = 0;
+                            for (int i = 0; i < CurrentRoom.DeviceList.Count; i++)
+                            {
+                                SmartSound.Device device = CurrentRoom.DeviceList[i];
+                                //
+                                if (device.DeviceType == 4 || device.DeviceType == 5 || device.DeviceType == 6)
+                                {
+                                    var deviceRowLayout = new DeviceRowLayout(this, device, n);
+                                    DeviceListView.AddChidren(deviceRowLayout);
+                                    deviceRowLayout.InitControl();
+                                    n++;
+                                }
+                            }
+                        }
+                        break;
+                    case 2: // 绌鸿皟
+                        {
+                            int n = 0;
+                            for (int i = 0; i < CurrentRoom.DeviceList.Count; i++)
+                            {
+                                SmartSound.Device device = CurrentRoom.DeviceList[i];
+                                //
+                                if (device.DeviceType == 7)
+                                {
+                                    var deviceRowLayout = new DeviceRowLayout(this, device, n);
+                                    DeviceListView.AddChidren(deviceRowLayout);
+                                    deviceRowLayout.InitControl();
+                                    n++;
+                                }
+                            }
+                        }
+                        break;
+                }
+
+                if (DeviceListView.ChildrenCount > 5)
+                {
+                    TextView textView = new TextView();
+                    textView.Height = Application.GetRealHeight(127 * 3);
+                    DeviceListView.AddChidren(textView);
+                }
+
+                if (DeviceListView.ChildrenCount == 0)
+                {
+                    TipLayout.Visible = true;
+                }
+                else
+                {
+                    TipLayout.Visible = false;
+                }
+            }
+            catch (Exception e)
+            {
+                string error = e.Message;
+            }
+        }
+
+        /// <summary>
+        /// 淇敼鍦烘櫙鏄电О
+        /// </summary>
+        /// <param name="scene"></param>
+        /// <param name="sceneRowLayout"></param>
+        private void ShowSetNicknameDialog(SmartSound.Scene scene, SceneRowLayout sceneRowLayout)
+        {
+            //鐢熸垚涓�涓脊绐楃敾闈�
+            var dialogForm = new DialogInputControl();
+            //缂栬緫浣忓畢
+            dialogForm.SetTitleText("鑷畾涔夋樀绉�");
+            //璇疯緭鍏ヤ綇瀹呭悕绉�
+            dialogForm.SetTipText("璇疯緭鍏ユ樀绉�");
+            dialogForm.Text = scene.NicksName;
+
+            //鎸変笅纭鎸夐挳
+            dialogForm.ComfirmClickEvent += (async (textValue) =>
+            {
+                scene.NicksName = textValue;
+                string remark = scene.SceneName;
+                if (scene.NicksName.Trim() != string.Empty)
+                {
+                    remark += "(" + scene.NicksName + ")";
+                }
+                sceneRowLayout.btnCaption.Text = remark;
+                string json = await postBatchEdit();
+                //鐢婚潰鍏抽棴
+                dialogForm.CloseDialog();
+            });
+        }
+
+        /// <summary>
+        /// 淇敼璁惧鏄电О
+        /// </summary>
+        /// <param name="device"></param>
+        /// <param name="deviceRowLayout"></param>
+        private void ShowSetNicknameDialog(SmartSound.Device device, DeviceRowLayout deviceRowLayout)
+        {
+            //鐢熸垚涓�涓脊绐楃敾闈�
+            var dialogForm = new DialogInputControl();
+            //缂栬緫浣忓畢
+            dialogForm.SetTitleText("鑷畾涔夋樀绉�");
+            //璇疯緭鍏ヤ綇瀹呭悕绉�
+            dialogForm.SetTipText("璇疯緭鍏ユ樀绉�");
+            dialogForm.Text = device.NicksName;
+
+            //鎸変笅纭鎸夐挳
+            dialogForm.ComfirmClickEvent += (async (textValue) =>
+           {
+               device.NicksName = textValue;
+               string remark = device.DeviceName;
+               if (device.NicksName.Trim() != string.Empty)
+               {
+                   remark += "(" + device.NicksName + ")";
+               }
+               deviceRowLayout.btnCaption.Text = remark;
+
+               string json = await postBatchEdit();
+
+               //鐢婚潰鍏抽棴
+               dialogForm.CloseDialog();
+           });
+        }
+
+        /// <summary>
+        /// 鍦烘櫙鍒犻櫎
+        /// </summary>
+        private void ShowSceneDelectDialog(SmartSound.Scene scene)
+        {
+            this.ShowMassage(ShowMsgType.Confirm, "纭鍒犻櫎璇ユ帶鍒跺唴瀹癸紵", () =>
+           {
+               HdlThreadLogic.Current.RunThread(async () =>
+                {
+                    this.ShowProgressBar();
+                    CurrentRoom.SceneList.Remove(scene);
+                    string json = await postBatchEdit();
+
+                    HdlThreadLogic.Current.RunMainInThread(() =>
+                    {
+                        LoadSceneView();
+                        this.CloseProgressBar();
+                    });
+                });
+
+           }, Language.StringByID(R.MyInternationalizationString.OkMsg));
+        }
+
+        /// <summary>
+        /// 璁惧鍒犻櫎
+        /// </summary>
+        private void ShowDeviceDelectDialog(SmartSound.Device device)
+        {
+            this.ShowMassage(ShowMsgType.Confirm, "纭鍒犻櫎璇ユ帶鍒跺唴瀹癸紵",  () =>
+             {
+
+                 HdlThreadLogic.Current.RunThread(async () =>
+                 {
+                     this.ShowProgressBar();
+                     CurrentRoom.DeviceList.Remove(device);
+                     string json = await postBatchEdit();
+
+                     HdlThreadLogic.Current.RunMainInThread(() =>
+                     {
+                         RefreshFunctionListView();
+                         this.CloseProgressBar();
+                     });
+                 });
+
+             }, Language.StringByID(R.MyInternationalizationString.OkMsg));
+        }
+
+        /// <summary>
+        /// 鎻愮ず娌℃湁鍔熻兘
+        /// </summary>
+        private void ShowNoFunctionTip(FrameLayout layout, string tip = "娌℃湁鏁版嵁鍝�")
+        {
+            var noFunction = new Button()
+            {
+                Y = Application.GetRealHeight(320),
+                Width = Application.GetMinRealAverage(757),
+                Height = Application.GetMinRealAverage(435),
+                UnSelectedImagePath = "Item/NoFunction.png",
+                Gravity = Gravity.CenterHorizontal
+            };
+            layout.AddChidren(noFunction);
+
+            var noFunctionTip = new Button()
+            {
+                Y = noFunction.Bottom + Application.GetRealHeight(32),
+                Height = Application.GetRealHeight(200),
+                Width = Application.GetRealWidth(700),
+                Gravity = Gravity.CenterHorizontal,
+                Text = tip,
+                TextColor = UserCenterColor.Current.TextGrayColor1,
+                TextAlignment = TextAlignment.Center,
+                IsMoreLines = true
+            };
+            layout.AddChidren(noFunctionTip);
+        }
+
+        //涓轰簡鏂逛究鏇存柊鐘舵�侊紝瀛樿捣鏉�
+        private List<Button> Buttons = new List<Button>();
+        private void RefreshButtonState()
+        {
+            try
+            {
+                for (int i = 0; i < Buttons.Count; i++)
+                {
+                    Button btn = Buttons[i];
+                    if (i == CurrentSelectIndex)
+                    {
+                        btn.SelectedImagePath = "Item/RoomIconBackgroundSelected.png";
+                        btn.UnSelectedImagePath = "Item/RoomIconBackgroundSelected.png";
+                        btn.TextColor = UserCenterColor.Current.White;
+                    }
+                    else
+                    {
+                        btn.SelectedImagePath = "Item/RoomIconBackground.png";
+                        btn.UnSelectedImagePath = "Item/RoomIconBackground.png";
+                        btn.TextColor = UserCenterColor.Current.TextGrayColor1;
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                string error = e.Message;
+            }
+        }
+
+        private async Task<string> postBatchEdit()
+        {
+            // 鎻愪氦鏁版嵁鑷虫湇鍔″櫒
+            string url = "https://developer.hdlcontrol.com/zigbeespeakerservice/BatchEdit";
+            string json = Newtonsoft.Json.JsonConvert.SerializeObject(SmartSound.getInstantiate());
+            string response_str = MyHttpWebResponse.PostWebRequest(url, json, Encoding.UTF8);
+            return response_str;
+        }
+
+        #region 鈻� 鑷畾涔夊満鏅�夋嫨鎺т欢_____________________
+
+        /// <summary>
+        /// 鍦烘櫙鍒楄〃琛�
+        /// </summary>
+        private class SceneRowLayout : RowLayoutControl
+        {
+            private SmartSoundContentForDeviceChange smartSoundContentForDeviceChange = null;
+
+            private SmartSound.Scene scene = null;
+            /// <summary>
+            /// 鍒犻櫎鎸夐挳
+            /// </summary>
+            public NormalViewControl btnDelect = null;
+            public NormalViewControl btnCaption = null;
+            private int Index = 0;
+
+            public SceneRowLayout(SmartSoundContentForDeviceChange _smartSoundContentForDeviceChange, SmartSound.Scene _scene, int _index)
+            {
+                smartSoundContentForDeviceChange = _smartSoundContentForDeviceChange;
+                scene = _scene;
+                Index = _index;
+            }
+
+            /// <summary>
+            /// 鍒濆鍖栧唴閮ㄦ帶浠�
+            /// </summary>
+            public void InitControl()
+            {
+                this.BackgroundColor = UserCenterColor.Current.White;
+                this.Height = Application.GetRealHeight(175);
+                string remark = scene.SceneName;
+                if (scene.NicksName.Trim() != string.Empty)
+                {
+                    remark += " (" + scene.NicksName + ")";
+                }
+                btnCaption = frameTable.AddLeftCaption(remark, 2000);
+
+                var nicknameIcon = frameTable.AddRightArrow();//58
+                nicknameIcon.TextSize = 14;
+
+                nicknameIcon.SelectedImagePath = "SmartSound/Nickname.png";
+                nicknameIcon.UnSelectedImagePath = "SmartSound/Nickname.png";
+                nicknameIcon.AddTag("obj", scene);
+                nicknameIcon.ButtonClickEvent += (sender, e) =>
+                {
+                    // 娣诲姞鏄电О
+                    var btn = sender as IconViewControl;
+                    SmartSound.Scene tmpScene = (SmartSound.Scene)btn.GetTagByKey("obj");
+                    smartSoundContentForDeviceChange.ShowSetNicknameDialog(tmpScene, this);
+                };
+
+                //搴曠嚎
+                frameTable.AddBottomLine();
+                
+                btnDelect = base.AddDeleteControl();
+                btnDelect.Text = Language.StringByID(R.MyInternationalizationString.Delete);
+                btnDelect.ButtonClickEvent += (sender, e) =>
+                {
+                    //鍒犻櫎鍦烘櫙
+                    smartSoundContentForDeviceChange.ShowSceneDelectDialog(scene);
+                };
+            }
+        }
+        #endregion
+
+        #region 鈻� 鑷畾鐏厜閫夋嫨鎺т欢_____________________
+
+        /// <summary>
+        /// 鎴块棿鍒楄〃琛�
+        /// </summary>
+        private class DeviceRowLayout : RowLayoutControl
+        {
+            private SmartSoundContentForDeviceChange smartSoundContentForDeviceChange = null;
+
+            private SmartSound.Device device = null;
+            /// <summary>
+            /// 鍒犻櫎鎸夐挳
+            /// </summary>
+            public NormalViewControl btnDelect = null;
+            public NormalViewControl btnCaption = null;
+            private int Index = 0;
+
+            public DeviceRowLayout(SmartSoundContentForDeviceChange _smartSoundContentForDeviceChange, SmartSound.Device _device, int _index)
+            {
+                smartSoundContentForDeviceChange = _smartSoundContentForDeviceChange;
+                device = _device;
+                Index = _index;
+            }
+
+            /// <summary>
+            /// 鍒濆鍖栧唴閮ㄦ帶浠�
+            /// </summary>
+            public void InitControl()
+            {
+                this.BackgroundColor = UserCenterColor.Current.White;
+                this.Height = Application.GetRealHeight(175);
+                string remark = device.DeviceName;
+                if (device.NicksName.Trim() != string.Empty)
+                {
+                    remark += " (" + device.NicksName + ")";
+                }
+                btnCaption = frameTable.AddLeftCaption(remark, 2000);
+
+                var nicknameIcon = frameTable.AddRightArrow();//58
+                nicknameIcon.TextSize = 14;
+
+                nicknameIcon.SelectedImagePath = "SmartSound/Nickname.png";
+                nicknameIcon.UnSelectedImagePath = "SmartSound/Nickname.png";
+                nicknameIcon.AddTag("obj", device);
+                nicknameIcon.ButtonClickEvent += (sender, e) =>
+                {
+                    var btn = sender as IconViewControl;
+                    SmartSound.Device tmpDevice = (SmartSound.Device)btn.GetTagByKey("obj");
+                    smartSoundContentForDeviceChange.ShowSetNicknameDialog(tmpDevice, this);
+                };
+
+                //搴曠嚎
+                frameTable.AddBottomLine();
+
+                btnDelect = base.AddDeleteControl();
+                btnDelect.Text = "鍒犻櫎";
+                btnDelect.ButtonClickEvent += (sender, e) =>
+                {
+                    smartSoundContentForDeviceChange.ShowDeviceDelectDialog(device);
+                };
+            }
+        }
+        #endregion
+    }
+}

--
Gitblit v1.8.0