From d0396d3f30d46810f8453bf21f86bd93fe5dbdec Mon Sep 17 00:00:00 2001 From: lss <316519258@qq.com> Date: 星期三, 10 六月 2020 15:54:37 +0800 Subject: [PATCH] test --- ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs | 450 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 358 insertions(+), 92 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs index af113da..b352d26 100644 --- a/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs @@ -1,119 +1,385 @@ 锘縰sing System; using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; using Shared.Common; +using Shared.Phone.UserCenter.SmartSound.Forms; +using Shared.Phone.UserCenter.SmartSound.Util; +using Shared.Phone.UserCenter.SmartSound.Widget; +using ZigBee.Device; namespace Shared.Phone.UserCenter.SmartSound { + public class SmartSoundControlForm : EditorCommonForm { - private SmartSound mSmartSound; - public SmartSoundControlForm() + /// <summary> + /// 鍒楄〃鎺т欢 + /// </summary> + private VerticalListControl listView = null; + private FrameLayout contentLayout = null; + public int CurrentIndex = 0; + private MostRightIconControl btnAddDeviceIcon = null; + /// <summary> + /// 鏅鸿兘闊崇鏁版嵁 + /// </summary> + private static SmartSoundInfo.SoundInfo mSoundInfo = null; + + public SmartSoundControlForm(SmartSoundInfo.SoundInfo soundInfo) { - } - - /// <summary> - /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) - /// </summary> - public void ShowForm() - { - // iniData();//鍏堝姞杞芥ā鎷熸暟鎹� - - this.ScrollEnabled = false; - - //璁剧疆鏍囬淇℃伅 - base.SetTitleText("璇煶鎺у埗"); - - //鍙充笂娣诲姞鎸夐挳 - var btnAddDeviceIcon = new MostRightIconControl(69, 69); - btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png"; - topFrameLayout.AddChidren(btnAddDeviceIcon); - btnAddDeviceIcon.InitControl(); - btnAddDeviceIcon.ButtonClickEvent += (sender, e) => - { - iniView(); - }; - - //鍒濆鍖栦腑閮ㄦ帶浠� - //this.InitMiddleFrame(); - + mSoundInfo = soundInfo; } /// <summary> - /// 灏嗘暟鎹浆鎹负鏅鸿兘闊崇浣跨敤鐨勬暟鎹� + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) /// </summary> - private void iniData(bool isAdd) - { - //1.浠庢湇鍔″櫒鑾峰彇鐨勬暟鎹紝json鍙嶅簭鍒楀寲寰楁潵 - //2.鐐瑰嚮"+"灏嗙綉鍏崇殑鏁版嵁杞崲涓� 鏅鸿兘闊崇浣跨敤鐨勬暟鎹� - /*{ + public void ShowForm() + { + //璁剧疆鏍囬淇℃伅 + base.SetTitleText("璇煶鎺у埗"); - Dictionary<string, string> ss = Config.Instance.Home.FloorDics;//妤煎眰鍒楄〃 - string currentFloor = Config.Instance.Home.CurrentFloorId;//褰撳墠妤煎眰鐨勯敭 - - var listRoom = HdlRoomLogic.Current.GetFloorSortRoom("妤煎眰鐨勪富閿�");//鑾峰彇褰撳墠妤煎眰鐨勬墍鏈夋埧闂� - var room = listRoom[0]; - for (int i=0;i<room.ListDevice.Count;i++) - {//璁惧鏁版嵁 - var device = LocalDevice.Current.GetDevice(room.ListDevice[i]); - var myType = LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device }); - - if (myType.BeloneType == DeviceBeloneType.A鐏厜) - { - //杩欓噷闈㈢殑灏辨槸鐏厜浜� - var light = device; - // light.DeviceAddr; 璁惧鐨勫湴鍧� - // light.DeviceEpoint;//璁惧鐨勭鍙� - } - } - - for (int i = 0; i < room.ListSceneId.Count; i++) - { //鍦烘櫙鏁版嵁 - var device = HdlSceneLogic.Current.GetSceneUIBySceneId(room.ListSceneId[i]); - // device.Id;鍦烘櫙 id - } - }*/ - - if (isAdd) + //鍙充笂娣诲姞鎸夐挳 + if (btnAddDeviceIcon == null) { - mSmartSound = new SmartSound(); - Dictionary<string, string> floorDictionary = Config.Instance.Home.FloorDics;//妤煎眰鍒楄〃 - if (floorDictionary.Count < 1) + btnAddDeviceIcon = new MostRightIconControl(69, 69); + btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png"; + topFrameLayout.AddChidren(btnAddDeviceIcon); + btnAddDeviceIcon.InitControl(); + btnAddDeviceIcon.ButtonClickEvent += (sender, e) => { - //娌℃湁妤煎眰 - } - - - - - + var smartSoundDataAdd = new SmartSoundControlContentForm(mSoundInfo); + smartSoundDataAdd.AddForm(); + }; } - + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); } - private void iniView() + private void InitMiddleFrame() { - //鎴块棿鍒楄〃琛寋鎴块棿鍒楄〃 textView锛屾ゼ灞備笅鎷夌獥} - //鏄剧ず鎴块棿{甯﹂�夋嫨妗嗙殑锛涘綋閫変腑浜嗘埧闂村悗闇�瑕佸湪搴曢儴寮瑰嚭纭鎸夐挳锛岀偣鍑荤‘璁よ烦杞埌鏂扮殑鐣岄潰} - var frame = new TopRightMenuControl(2, 2); - //鍒涘缓妤煎眰 - frame.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uCreatFloor), "Item/CreatFloor.png", "Item/CreatFloorSelected.png", () => + this.ClearBodyFrame(); + + HdlThreadLogic.Current.RunThread(async () => { - //鍒涘缓妤煎眰 - //this.CreatOrEditorFloor(null, null, string.Empty, string.Empty); - }); - //鍒涘缓鎴块棿 - frame.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uCreatRoom), "Item/RoomIcon.png", "Item/RoomIconSelected.png", () => - { - /*var form = new AddNewRoomForm(); - form.AddForm(string.Empty); - form.FinishEditorEvent += () => + this.ShowProgressBar(); + + string json = await GetData();//鑾峰彇鏁版嵁 + SmartSoundDataInfo dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<SmartSoundDataInfo>(json); + if (dataInfo != null) { - //鏍规嵁鎸囧畾妯″紡,鍒濆鍖栨甯冩帶浠� - this.InitFrameTableByMode(); - };*/ + if (dataInfo.StateCode == "SUCCESS") + { + SmartSound.getInstantiate().LayerList = dataInfo.ResponseData.LayerList; + SmartSound.getInstantiate().TokenID = mSoundInfo.Id; + SmartSound.getInstantiate().UserID = mSoundInfo.UserID; + } + } + + HdlThreadLogic.Current.RunMainInThread(() => + { + if (SmartSound.getInstantiate().LayerList == null || SmartSound.getInstantiate().LayerList.Count < 1) + { + this.CloseProgressBar(); + return; + } + + contentLayout = new FrameLayout(); + this.bodyFrameLayout.AddChidren(contentLayout); + contentLayout.RemoveAll(); + + var pullLayout = new MyPullControl(this, SmartSound.getInstantiate().LayerList); + contentLayout.AddChidren(pullLayout); + pullLayout.InitControl(); + + LoadAllRoomListView(); + + //鏃犳暟鎹殑鏃跺�欒鍋氫竴涓彁绀� + { + bool bol = false; + for (int i = 0; i < SmartSound.getInstantiate().LayerList.Count; i++) + { + if (SmartSound.getInstantiate().LayerList[i].RoomList.Count > 0) + { + bol = true; + break; + } + } + + if (!bol) + { + pullLayout.Visible = false; + this.ShowNotDataImage(this.bodyFrameLayout, new string[] { "杩樻病鏈夋帶鍒跺唴瀹瑰摝锛�", "鐐瑰嚮\"+\"娣诲姞" }); + } + } + + this.CloseProgressBar(); + + }); }); } + + /// <summary> + /// 鍔犺浇鎴块棿鍒楄〃 + /// </summary> + private void LoadAllRoomListView() + { + try + { + if (SmartSound.getInstantiate().LayerList == null || SmartSound.getInstantiate().LayerList.Count < 1) + return; + + // 鍔犺浇褰撳墠妤煎眰鐨勬墍鏈夋埧闂� ListView + if (listView == null) + { + listView = new VerticalListControl(); + contentLayout.AddChidren(listView); + listView.Y = Application.GetRealHeight(173); + listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(173); + + } + else if (listView.Parent == null) + { + listView = new VerticalListControl(); + contentLayout.AddChidren(listView); + listView.Y = Application.GetRealHeight(173); + listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(173); + } + + listView.RemoveAll(); + + SmartSound.Layer layer = SmartSound.getInstantiate().LayerList[CurrentIndex]; + + foreach (SmartSound.Room room in layer.RoomList) + { + var roomRowLayout = new RoomRowLayout(this, room); + listView.AddChidren(roomRowLayout); + roomRowLayout.InitControl(); + + roomRowLayout.frameTable.ButtonClickEvent += (sender, e) => + { + // 鐐瑰嚮鎴块棿锛岃繘鍏ラ�夋嫨璁惧鐣岄潰 + var deviceChange = new SmartSoundContentForDeviceChange(room); + deviceChange.AddForm(); + }; + + roomRowLayout.btnDelect.ButtonClickEvent += (sender, e) => + { + var delBtn = sender as NormalViewControl; + DelectRoom(delBtn); + }; + } + } + catch (Exception e) + { + string error = e.Message; + } + } + + private void DelectRoom(NormalViewControl delBtn) + { + this.ShowMassage(ShowMsgType.Confirm, "纭鍒犻櫎璇ユ埧闂寸殑鎺у埗鍐呭锛�", async () => + { + + HdlThreadLogic.Current.RunThread(async () => + { + + this.ShowProgressBar("姝e湪鍒犻櫎鏁版嵁...."); + //鍒犻櫎鎴块棿 + var tag = (SmartSound.Room)delBtn.GetTagByKey("obj"); + + if (SmartSound.getInstantiate().LayerList == null) + return; + + for (int i = 0; i < SmartSound.getInstantiate().LayerList.Count; i++) + { + SmartSound.Layer _layer = SmartSound.getInstantiate().LayerList[i]; + + for (int j = 0; j < _layer.RoomList.Count; j++) + { + SmartSound.Room _room = _layer.RoomList[j]; + + if (_room.RoomName == tag.RoomName) + { + _layer.RoomList.Remove(_room); + } + } + } + + // 閲嶆柊涓婁紶鏁版嵁 + string json = await postBatchEdit(); + + HdlThreadLogic.Current.RunMainInThread(() => + { + //this.InitMiddleFrame(); + this.LoadAllRoomListView(); + }); + this.CloseProgressBar(); + }); + + }, Language.StringByID(R.MyInternationalizationString.OkMsg)); + } + + private async Task<string> GetData() + { + // 浠庢湇鍔″櫒鑾峰彇鏁版嵁 + string url = string.Format("https://developer.hdlcontrol.com/zigbeespeakerservice/BatchEdit?Platform&UserID={0}&TokenID={1}", mSoundInfo.UserID, mSoundInfo.Id); + return await MyHttpWebResponse.GetWebRequest(url); + } + + private async Task<string> postBatchEdit() + { + // 鎻愪氦鏁版嵁鑷虫湇鍔″櫒 + string url = "https://developer.hdlcontrol.com/zigbeespeakerservice/BatchEdit"; + string json = Newtonsoft.Json.JsonConvert.SerializeObject(SmartSound.getInstantiate()); + string response_str = await MyHttpWebResponse.PostWebRequest(url, json, Encoding.UTF8); + return response_str; + } + + public override int FormActionAgainEvent() + { + ShowForm(); + return base.FormActionAgainEvent(); + } + + #region 鈻� 鑷畾涔夋ゼ灞傞�夋嫨鎺т欢_____________________ + + /// <summary> + /// 鎴块棿鍒楄〃琛� + /// </summary> + private class MyPullControl : FrameRowControl + { + + private SmartSoundControlForm smartSoundControlData = null; + private List<SmartSound.Layer> Layers = null; + /// <summary> + /// 鎴块棿鍒楄〃 + /// </summary> + private NormalViewControl btnName = null; + + /// <summary> + /// 鎴块棿鍒楄〃琛� + /// </summary> + public MyPullControl(SmartSoundControlForm _SmartSoundDataAdd, List<SmartSound.Layer> _layers) + { + this.smartSoundControlData = _SmartSoundDataAdd; + this.Layers = _layers; + this.UseClickStatu = false; + this.BackgroundColor = UserCenterColor.Current.White; + this.Height = Application.GetRealHeight(173); + } + + /// <summary> + /// 鍒濆鍖栨帶浠� + /// </summary> + public void InitControl() + { + try + { + //鏄剧ず鏂囨湰 + btnName = this.AddLeftCaption(string.Empty, 700); + btnName.Height = Application.GetRealHeight(60); + btnName.TextSize = 17; + btnName.Y = Application.GetRealHeight(57); + btnName.Text = "鎴块棿鍒楄〃"; + + var right_icon = this.AddRightArrow(); + right_icon.SelectedImagePath = "SmartSound/PullDown.png"; + right_icon.UnSelectedImagePath = "SmartSound/PullDown.png"; + right_icon.ButtonClickEvent += (sender, e) => + { + ShowPullList(); + }; + + var layout = this.AddMostRightView(Layers[smartSoundControlData.CurrentIndex].LayerName, 300, false); + layout.Name = "pullLayout"; + layout.ButtonClickEvent += (sender, e) => + { + ShowPullList(); + }; + + if (SmartSound.getInstantiate().LayerList.Count < 2) + { + right_icon.Visible = false; + layout.Visible = false; + } + } + catch(Exception e) + { + string error = e.Message; + } + } + + private void ShowPullList() + { + //鎴块棿鍒楄〃琛寋鎴块棿鍒楄〃 textView锛屾ゼ灞備笅鎷夌獥} + //鏄剧ず鎴块棿{甯﹂�夋嫨妗嗙殑锛涘綋閫変腑浜嗘埧闂村悗闇�瑕佸湪搴曢儴寮瑰嚭纭鎸夐挳锛岀偣鍑荤‘璁よ烦杞埌鏂扮殑鐣岄潰} + var pull_frame = new TopRightMenuControl(Layers.Count, 2); + pull_frame.Y = this.Height; + + for (int i = 0; i < Layers.Count; i++) + { + //鍒涘缓妤煎眰 + pull_frame.AddRowMenu(Layers[i].LayerName, "Item/CreatFloor.png", "Item/CreatFloorSelected.png", () => + { + smartSoundControlData.CurrentIndex = i; + smartSoundControlData.LoadAllRoomListView(); + }); + } + } + } + #endregion + + #region 鈻� 鑷畾涔夋櫤鑳介煶绠辨帶浠禵____________________ + + /// <summary> + /// 璇煶鎺у埗鎴块棿琛� + /// </summary> + private class RoomRowLayout : RowLayoutControl + { + + /// <summary> + /// 鎴块棿鍚嶅瓧 + /// </summary> + private NormalViewControl btnName = null; + + /// <summary> + /// 鍒犻櫎鎸夐挳 + /// </summary> + public NormalViewControl btnDelect = null; + + private SmartSoundControlForm smartSoundControlForm; + private SmartSound.Room room; + + /// <summary> + /// 鑷畾闊崇鍏虫帶浠� + /// </summary> + public RoomRowLayout(SmartSoundControlForm _smartSoundControlForm, SmartSound.Room _room) + { + this.smartSoundControlForm = _smartSoundControlForm; + this.room = _room; + this.BackgroundColor = UserCenterColor.Current.White; + this.Height = Application.GetRealHeight(173); + } + + /// <summary> + /// 鍒濆鍖栧唴閮ㄦ帶浠� + /// </summary> + public void InitControl() + { + //璁惧 + frameTable.AddLeftCaption(this.room.RoomName, 800); + frameTable.AddRightArrow(); + //搴曠嚎 + frameTable.AddBottomLine(); + + btnDelect = base.AddDeleteControl(); + btnDelect.Text = "鍒犻櫎"; + btnDelect.AddTag("obj", room); + } + } + + #endregion } -} +} \ No newline at end of file -- Gitblit v1.8.0