using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json.Linq; using Shared.Common; using Shared.Phone.UserCenter.Device; using Shared.Phone.UserCenter.SmartSound.Util; using Shared.Phone.UserCenter.SmartSound.Widget; using ZigBee.Device; namespace Shared.Phone.UserCenter.SmartSound { //智能音箱列表界面 public class SmartSoundListForm : EditorCommonForm { public SmartSoundListForm() { } private SmartSoundInfo smartSoundInfo = null; /// /// 列表控件 /// private VerticalListRefreshControl listView = null; /// /// 前一次显示出左滑菜单的RowLayout /// private RowLayoutControl oldShowRightMuneRow = null; private static string dataString = ""; #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// public void ShowForm() { this.ScrollEnabled = false; //设置标题信息 base.SetTitleText("智能音箱"); Dictionary floorDictionary = Config.Instance.Home.FloorDics;//楼层列表 var helpBtn = new MyButton(); helpBtn.TextColor = UserCenterColor.Current.TextOrangeColor; helpBtn.Text = "帮助"; helpBtn.Gravity = Gravity.CenterRight; helpBtn.TextAlignment = TextAlignment.CenterRight; topFrameLayout.AddChidren(helpBtn); helpBtn.X -= Application.GetRealWidth(58); //初始化中部控件 this.InitMiddleFrame(); helpBtn.MouseUpEventHandler += (sernder, e) => { //生成一个弹窗画面 var dialogForm = new TextDialog("绑定智能音箱到第三方 APP 进行操作", "跳转至小度"); dialogForm.SetTitleText("帮助"); //按下确认按钮 dialogForm.ComfirmClickEvent += () => { //画面关闭 dialogForm.CloseDialog(); }; }; } /// /// 初始化中部控件(外部可以调用) /// /// 重新获取设备的在线状态 public void InitMiddleFrame() { this.ClearBodyFrame(); var frame = new FrameLayout(); this.bodyFrameLayout.AddChidren(frame); frame.BackgroundColor = UserCenterColor.Current.White; frame.Y = 0; frame.Height = this.bodyFrameLayout.Height; // 初始化 lisetView listView = new VerticalListRefreshControl(29); listView.Y = 0; listView.Height = bodyFrameLayout.Height; frame.AddChidren(listView); listView.BeginHeaderRefreshingAction += () => { HdlThreadLogic.Current.RunThread(() => { HdlThreadLogic.Current.RunMain(() => { //隐藏下拉刷新特效 listView.EndHeaderRefreshing(); this.InitMiddleFrame(); }); }); }; HdlThreadLogic.Current.RunThread(async () => { this.ShowProgressBar(); await getData(); HdlThreadLogic.Current.RunMainInThread(() => { iniView(); if (smartSoundInfo == null || smartSoundInfo.ResponseData == null || smartSoundInfo.ResponseData.RowCount == 0) { // show出没有设备的图标文字提示 this.ShowNotDataImage(bodyFrameLayout, new string[] { "还没有音箱哦,", "绑定智能音箱请前往第三方 APP 进行操作" }); } this.CloseProgressBar(); }); }); } /// /// 获取音箱列表 /// /// private async Task getData() { //SmartSoundInfo.Auth auth = new SmartSoundInfo.Auth(); //auth.HomeID = Common.Config.Instance.Home.Id; //auth.UserID = Common.Config.Instance.Guid; //auth.Platform = ""; string url = string.Format("https://developer.hdlcontrol.com/zigbeespeakerservice/Auth?Platform&PageSetting.PageSize=100&PageSetting.PageIndex=1&UserID={0}&HomeID={1}", Common.Config.Instance.Guid,Common.Config.Instance.Home.Id); dataString = await MyHttpWebResponse.GetWebRequest(url); smartSoundInfo = Newtonsoft.Json.JsonConvert.DeserializeObject(dataString); } /// /// 设置备注 /// /// /// /// private async Task setRemark(SmartSoundInfo.SoundInfo soundInfo, string new_remark) { if (soundInfo == null) return ""; string url = "https://developer.hdlcontrol.com/zigbeespeakerservice/Auth"; string json = "{" + "\"AuthID\":" + "\"" + soundInfo.Id + "\"" + "," + "\"Remark\":" + "\"" + new_remark + "\"" + "," + "\"UserID\":" + "\"" + soundInfo.UserID + "\"" + "," + "\"HomeID\":" + "\"" + soundInfo.HomeID + "\"" + "}"; string response_str = await MyHttpWebResponse.PutWebRequest(url, json, Encoding.UTF8); JObject jObject = JObject.Parse(response_str); return jObject["StateCode"].ToString(); } private void iniView() { // listView.RemoveAll(); if (smartSoundInfo == null) return; for (int i = 0; i < smartSoundInfo.ResponseData.Data.Count; i++) { // var smartSound = smartSoundInfo.ResponseData.Data[i]; var row = new SoundRowLayout(); listView.AddChidren(row); if (smartSound.Platform == "Baidu") { row.Account = "小度:" + smartSound.UserName; row.ImagePath = "SmartSound/Xiaodu.png"; row.Remark = smartSound.Remark; } row.InitControl(); row.btnDelect.AddTag("index", i); row.btnRename.AddTag("index", i); row.frameTable.AddTag("index", i); //重命名 row.btnRename.ButtonClickEvent += (sender, e) => { int index = (int)((NormalViewControl)sender).GetTagByKey("index"); var smartSound1 = smartSoundInfo.ResponseData.Data[index]; ShowRenameDialog(row, smartSound1); }; // 解除绑定 row.btnDelect.ButtonClickEvent += (sender, e) => { int index = (int)(((NormalViewControl)sender).GetTagByKey("index")); ShowDelectDialog(index); }; //跳转到控制内容界面 FrameRowControl row.frameTable.ButtonClickEvent += (sender, e) => { int index = (int)row.frameTable.GetTagByKey("index"); if (SmartSound.getInstantiate().LayerList != null) SmartSound.getInstantiate().LayerList.Clear(); var smartSoundControlForm = new SmartSoundControlForm(smartSoundInfo.ResponseData.Data[index]); smartSoundControlForm.AddForm(); }; } } /// /// 解除绑定弹窗 /// private void ShowDelectDialog(int index) { //生成一个弹窗画面 var dialogForm = new TextDialog("解除绑定需要到第三方 APP 进行操作", "跳转至小度"); dialogForm.SetTitleText("解除绑定"); //按下确认按钮 dialogForm.ComfirmClickEvent += () => { //画面关闭 dialogForm.CloseDialog(); }; } /// /// 重命名弹窗 /// /// private void ShowRenameDialog(SoundRowLayout soundRowLayout, SmartSoundInfo.SoundInfo smartSound) { //生成一个弹窗画面 var dialogForm = new DialogInputControl(); //添加备份 dialogForm.SetTitleText("重命名"); //请输入备份名称 dialogForm.SetTipText(smartSound.Remark); //按下确认按钮 dialogForm.ComfirmClickEvent += (async (textValue) => { //画面关闭 dialogForm.CloseDialog(); string remark = textValue; string str = await setRemark(smartSound, remark); //上传备份 if (str == "SUCCESS") { smartSound.Remark = remark; soundRowLayout.btnRemark.Text = textValue; } else { //错误弹窗提示 ShowMassage(ShowMsgType.Tip, "修改备注不成功!", null, "确认"); } }); } #endregion #region ■ 界面重新激活事件___________________ /// /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件 /// public override int FormActionAgainEvent() { return 1; } #endregion #region ■ 关闭界面___________________________ /// /// 画面关闭 /// public override void CloseFormBefore() { base.CloseFormBefore(); } #endregion } }