| | |
| | | using 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 |
| | |
| | | private FrameLayout contentLayout = null; |
| | | public int CurrentIndex = 0; |
| | | private MostRightIconControl btnAddDeviceIcon = null; |
| | | /// <summary> |
| | | /// 智能音箱数据 |
| | | /// </summary> |
| | | private static SmartSoundInfo.SoundInfo mSoundInfo = null; |
| | | |
| | | public SmartSoundControlForm() |
| | | public SmartSoundControlForm(SmartSoundInfo.SoundInfo soundInfo) |
| | | { |
| | | mSoundInfo = soundInfo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建) |
| | | /// </summary> |
| | | public void ShowForm() |
| | | { |
| | | |
| | | { |
| | | //设置标题信息 |
| | | base.SetTitleText("语音控制"); |
| | | |
| | |
| | | btnAddDeviceIcon.InitControl(); |
| | | btnAddDeviceIcon.ButtonClickEvent += (sender, e) => |
| | | { |
| | | var smartSoundDataAdd = new SmartSoundControlContentForm(); |
| | | var smartSoundDataAdd = new SmartSoundControlContentForm(mSoundInfo); |
| | | smartSoundDataAdd.AddForm(); |
| | | }; |
| | | } |
| | | |
| | | //初始化中部控件 |
| | | this.InitMiddleFrame(); |
| | | |
| | | } |
| | | |
| | | |
| | | private void InitMiddleFrame() |
| | | { |
| | | this.ClearBodyFrame(); |
| | | |
| | | if (SmartSound.CurretnData == null || SmartSound.CurretnData.Count < 1) |
| | | return; |
| | | |
| | | // 添加数据 |
| | | if (contentLayout != null) |
| | | HdlThreadLogic.Current.RunThread(async () => |
| | | { |
| | | contentLayout.RemoveAll(); |
| | | contentLayout = null; |
| | | } |
| | | |
| | | contentLayout = new FrameLayout(); |
| | | this.bodyFrameLayout.AddChidren(contentLayout); |
| | | contentLayout.RemoveAll(); |
| | | this.ShowProgressBar(); |
| | | |
| | | var pullLayout = new MyPullControl(this, SmartSound.CurretnData); |
| | | contentLayout.AddChidren(pullLayout); |
| | | pullLayout.InitControl(); |
| | | string json = await GetData();//获取数据 |
| | | SmartSoundDataInfo dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<SmartSoundDataInfo>(json); |
| | | if (dataInfo != null) |
| | | { |
| | | if (dataInfo.StateCode == "SUCCESS") |
| | | { |
| | | SmartSound.getInstantiate().LayerList = dataInfo.ResponseData.LayerList; |
| | | SmartSound.getInstantiate().TokenID = mSoundInfo.Id; |
| | | SmartSound.getInstantiate().UserID = mSoundInfo.UserID; |
| | | } |
| | | } |
| | | |
| | | LoadAllRoomListView(); |
| | | 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.CurretnData == null || SmartSound.CurretnData.Count < 1) |
| | | if (SmartSound.getInstantiate().LayerList == null || SmartSound.getInstantiate().LayerList.Count < 1) |
| | | return; |
| | | |
| | | |
| | | // 加载当前楼层的所有房间 ListView |
| | | if (listView == null) |
| | | { |
| | |
| | | |
| | | listView.RemoveAll(); |
| | | |
| | | SmartSound.Layer layer = SmartSound.CurretnData[CurrentIndex]; |
| | | SmartSound.Layer layer = SmartSound.getInstantiate().LayerList[CurrentIndex]; |
| | | |
| | | foreach (SmartSound.Room room in layer.RoomList) |
| | | { |
| | |
| | | |
| | | roomRowLayout.frameTable.ButtonClickEvent += (sender, e) => |
| | | { |
| | | // 点击房间,进入选择设备界面 |
| | | var deviceChange = new SmartSoundContentForDeviceChange(room); |
| | | deviceChange.AddForm(); |
| | | }; |
| | | |
| | | roomRowLayout.btnDelect.ButtonClickEvent += (sender, e) => |
| | | { |
| | | try |
| | | { |
| | | var delBtn = sender as NormalViewControl; |
| | | var tag = (SmartSound.Room)delBtn.GetTagByKey("obj"); |
| | | |
| | | if (SmartSound.CurretnData == null) |
| | | return; |
| | | |
| | | for (int i = 0; i < SmartSound.CurretnData.Count; i++) |
| | | { |
| | | SmartSound.Layer _layer = SmartSound.CurretnData[i]; |
| | | |
| | | for (int j = 0; j < _layer.RoomList.Count; j++) |
| | | { |
| | | SmartSound.Room _room = _layer.RoomList[j]; |
| | | |
| | | if (_room.RoomID == tag.RoomID) |
| | | { |
| | | _layer.RoomList.Remove(_room); |
| | | this.LoadAllRoomListView(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | string error = ex.Message; |
| | | } |
| | | var delBtn = sender as NormalViewControl; |
| | | DelectRoom(delBtn); |
| | | }; |
| | | } |
| | | } |
| | | catch(Exception e) |
| | | catch (Exception e) |
| | | { |
| | | string error = e.Message; |
| | | } |
| | | } |
| | | |
| | | private void DelectRoom(NormalViewControl delBtn) |
| | | { |
| | | this.ShowMassage(ShowMsgType.Confirm, "确认删除该房间的控制内容?", async () => |
| | | { |
| | | |
| | | HdlThreadLogic.Current.RunThread(async () => |
| | | { |
| | | |
| | | this.ShowProgressBar("正在删除数据...."); |
| | | //删除房间 |
| | | 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() |
| | |
| | | { |
| | | ShowPullList(); |
| | | }; |
| | | |
| | | if (SmartSound.getInstantiate().LayerList.Count < 2) |
| | | { |
| | | right_icon.Visible = false; |
| | | layout.Visible = false; |
| | | } |
| | | } |
| | | catch(Exception e) |
| | | { |