From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期一, 14 十二月 2020 09:59:01 +0800 Subject: [PATCH] 请合并代码,完成晾衣架最终功能。 --- ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundListForm.cs | 432 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 432 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundListForm.cs b/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundListForm.cs new file mode 100755 index 0000000..0c08901 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundListForm.cs @@ -0,0 +1,432 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using Shared.Common; +using Shared.Phone.SmartSound.Forms; +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; + + /// <summary> + /// 鍒楄〃鎺т欢 + /// </summary> + private VerticalListRefreshControl listView = null; + /// <summary> + /// 鍓嶄竴娆℃樉绀哄嚭宸︽粦鑿滃崟鐨凴owLayout + /// </summary> + private RowLayoutControl oldShowRightMuneRow = null; + + private static string dataString = ""; + private MostRightIconControl btnAddDeviceIcon = null; + + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + public void ShowForm() + { + + this.ScrollEnabled = false; + + //璁剧疆鏍囬淇℃伅 + base.SetTitleText("鏅鸿兘闊崇"); + Dictionary<string, string> floorDictionary = Config.Instance.Home.FloorDics;//妤煎眰鍒楄〃 + + //鍙充笂娣诲姞鎸夐挳 + if (btnAddDeviceIcon == null) + { + btnAddDeviceIcon = new MostRightIconControl(69, 69); + btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png"; + topFrameLayout.AddChidren(btnAddDeviceIcon); + btnAddDeviceIcon.InitControl(); + btnAddDeviceIcon.ButtonClickEvent += (sender, e) => + { + var helpForm = new AddSmartSound(); + helpForm.AddForm(); + }; + } + + //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 helpForm = new AddSmartSound(); + // helpForm.AddForm(); + // /* + // //鐢熸垚涓�涓脊绐楃敾闈� + // var dialogForm = new TextDialog("缁戝畾鏅鸿兘闊崇鍒扮涓夋柟 APP 杩涜鎿嶄綔", "璺宠浆鑷冲皬搴PP"); + // dialogForm.SetTitleText("甯姪"); + + // //鎸変笅纭鎸夐挳 + // dialogForm.ComfirmClickEvent += () => + // { + // //鐢婚潰鍏抽棴 + // dialogForm.CloseDialog(); + // OpenXiaoDuAPP(); + // };*/ + //}; + } + + /// <summary> + /// 鍒濆鍖栦腑閮ㄦ帶浠�(澶栭儴鍙互璋冪敤) + /// </summary> + /// <param name="i_reGetDeviceOnlineStatu">閲嶆柊鑾峰彇璁惧鐨勫湪绾跨姸鎬�</param> + 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(); + }); + }); + } + + /// <summary> + /// 鑾峰彇闊崇鍒楄〃 + /// </summary> + /// <returns></returns> + private async Task getData() + { + 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<SmartSoundInfo>(dataString); + } + + /// <summary> + /// 璁剧疆澶囨敞 + /// </summary> + /// <param name="soundInfo"></param> + /// <param name="new_remark"></param> + /// <returns></returns> + private async Task<string> 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 = 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++) + { + try + { + // + var smartSound = smartSoundInfo.ResponseData.Data[i]; + var row = new SoundRowLayout(); + listView.AddChidren(row); + + if (smartSound.PlatfromName == "Baidu") + { + string remark = "灏忓害"; + if (smartSound.Remark != null && smartSound.Remark.Trim() != "") + remark += "(" + smartSound.Remark + ")"; + + row.ImagePath = "SmartSound/Xiaodu.png"; + row.Remark = remark; + }else if (smartSound.PlatfromName == "AISpeech") + { + string remark = "鎬濆繀椹�"; + if (smartSound.Remark != null && smartSound.Remark.Trim() != "") + remark += "(" + smartSound.Remark + ")"; + + row.ImagePath = "SmartSound/Sibici.png"; + row.Remark = 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); + }; + + // 瑙i櫎缁戝畾 + row.btnDelect.ButtonClickEvent += (sender, e) => + { + int index = (int)(((NormalViewControl)sender).GetTagByKey("index")); + var smartSound1 = smartSoundInfo.ResponseData.Data[index]; + ShowDelectDialog(smartSound1); + }; + + //璺宠浆鍒版帶鍒跺唴瀹圭晫闈� 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(); + }; + } + catch (Exception e) + { + this.ShowMassage(ShowMsgType.Tip, e.Message); + } + } + } + + private void OpenXiaoDuAPP() + { + bool bol = false; + try + { +#if Android + bol = HDLUtils.OpenAppWithPackageName("com.baidu.duer.superapp"); +#else + bol=HDLUtils.OpenApp("xiaoduapp://"); +#endif + + if (!bol) + { +#if Android + HDLUtils.OpenUrl("market://details?id=com.baidu.duer.superapp"); +#else + HDLUtils.OpenUrl("https://apps.apple.com/cn/app/%E5%B0%8F%E5%BA%A6/id1437733193"); +#endif + } + } + catch (Exception e) + { + string error = e.Message; + bol = false; + } + } + + /// <summary> + /// 鎬濆繀椹� + /// </summary> + private void OpenSBCAPP() + { + bool bol = false; + try + { +#if Android + bol = HDLUtils.OpenAppWithPackageName("com.aispeech.companionapp"); +#else + bol=HDLUtils.OpenApp("AispeechMobile://"); +#endif + + if (!bol) + { +#if Android + HDLUtils.OpenUrl("market://details?id=com.aispeech.companionapp"); +#else + HDLUtils.OpenUrl("https://apps.apple.com/cn/app/id1460767442"); +#endif + } + } + catch (Exception e) + { + string error = e.Message; + bol = false; + } + } + + /// <summary> + /// 瑙i櫎缁戝畾寮圭獥 + /// </summary> + private void ShowDelectDialog(SmartSoundInfo.SoundInfo smartSound) + { + //鐢熸垚涓�涓脊绐楃敾闈� + var dialogForm = new TextDialog("瑙i櫎缁戝畾闇�瑕佸埌绗笁鏂� APP 杩涜鎿嶄綔", "璺宠浆鑷崇涓夋柟APP"); + dialogForm.SetTitleText("瑙i櫎缁戝畾"); + + //鎸変笅纭鎸夐挳 + dialogForm.ComfirmClickEvent += () => + { + if (smartSound.PlatfromName == "Baidu") + { + OpenXiaoDuAPP(); + } + else if (smartSound.PlatfromName == "AISpeech") { + OpenSBCAPP(); + } + }; + } + /// <summary> + /// 閲嶅懡鍚嶅脊绐� + /// </summary> + /// <returns></returns> + private void ShowRenameDialog(SoundRowLayout soundRowLayout, SmartSoundInfo.SoundInfo smartSound) + { + //鐢熸垚涓�涓脊绐楃敾闈� + var dialogForm = new DialogInputControl(); + //娣诲姞澶囦唤 + dialogForm.SetTitleText("閲嶅懡鍚�"); + //璇疯緭鍏ュ浠藉悕绉� + dialogForm.SetTipText("璇疯緭鍏ュ悕绉�"); + dialogForm.Text = smartSound.Remark; + + //鎸変笅纭鎸夐挳 + dialogForm.ComfirmClickEvent += (async (textValue) => + { + //鐢婚潰鍏抽棴 + dialogForm.CloseDialog(); + + string remark = textValue; + string str = await setRemark(smartSound, remark); //涓婁紶澶囦唤 + if (str == "SUCCESS") + { + smartSound.Remark = remark; + if (smartSound.PlatfromName == "Baidu") + { + soundRowLayout.btnRemark.Text = "灏忓害" + "(" + textValue + ")"; + } + else if (smartSound.PlatfromName == "AISpeech") + { + soundRowLayout.btnRemark.Text = "鎬濆繀椹�" + "(" + textValue + ")"; + } + else + { + soundRowLayout.btnRemark.Text = textValue; + } + + } + else + { + //閿欒寮圭獥鎻愮ず + ShowMassage(ShowMsgType.Tip, "淇敼澶囨敞涓嶆垚鍔燂紒", null, "纭"); + } + }); + } + + #endregion + + /// <summary> + /// 鍒犻櫎鏁版嵁 + /// </summary> + /// <param name="soundInfo"></param> + /// <returns></returns> + private string DelectSmartSound(SmartSoundInfo.SoundInfo soundInfo) + { + if (soundInfo == null) + return ""; + + string url = "https://developer.hdlcontrol.com/zigbeespeakerservice/Auth"; + string json = "{" + + "\"AuthID\":" + "\"" + soundInfo.Id + "\"" + "," + + "\"UserID\":" + "\"" + soundInfo.UserID + "\"" + "," + + "\"HomeID\":" + "\"" + soundInfo.HomeID + "\"" + "}"; + + string response_str = MyHttpWebResponse.DeleteWebRequest(url, json, Encoding.UTF8); + JObject jObject = JObject.Parse(response_str); + + return jObject["StateCode"].ToString(); + } + +#region 鈻� 鐣岄潰閲嶆柊婵�娲讳簨浠禵__________________ + + /// <summary> + /// 鑷韩鐨勪笂灞傜晫闈㈠叧闂悗,瀹冭嚜韬浜庢渶涓婂眰鏃�,瑙﹀彂鐨勪簨浠� + /// </summary> + public override int FormActionAgainEvent() + { + return 1; + } + +#endregion + +#region 鈻� 鍏抽棴鐣岄潰___________________________ + + /// <summary> + /// 鐢婚潰鍏抽棴 + /// </summary> + public override void CloseFormBefore() + { + base.CloseFormBefore(); + } + +#endregion + + } +} \ No newline at end of file -- Gitblit v1.8.0