lss
2020-05-29 cc1012b077a91793c0edd6001cdf019e6bd9a57d
ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundListForm.cs
@@ -1,7 +1,11 @@
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 ZigBee.Device;
namespace Shared.Phone.UserCenter.SmartSound
@@ -13,7 +17,7 @@
        {
        }
        private List<SmartSound> smartSoundList = null;
        private SmartSoundInfo smartSoundInfo = null;
        /// <summary>
        /// 列表控件
@@ -24,6 +28,8 @@
        /// </summary>
        private RowLayoutControl oldShowRightMuneRow = null;
        private static string dataString = "";
        #region ■ 初始化_____________________________
@@ -32,7 +38,7 @@
        /// </summary>
        public void ShowForm()
        {
            iniData();//先加载模拟数据
            // iniData();//先加载模拟数据
            this.ScrollEnabled = false;
@@ -57,20 +63,13 @@
            {
                //这里是加载帮组的界面
            };
            string room_id = Common.Config.Instance.Home.Id;//住宅 ID
            string gu_id = Common.Config.Instance.Guid;
            Console.WriteLine("room_id =" + room_id);
            Console.WriteLine("gu_id =" + gu_id);
        }
        /// <summary>
        /// 初始化中部控件(外部可以调用)
        /// </summary>
        /// <param name="i_reGetDeviceOnlineStatu">重新获取设备的在线状态</param>
        public void InitMiddleFrame()
        public async void InitMiddleFrame()
        {
            // show出没有设备的图标文字提示
            this.ShowNotDataImage(bodyFrameLayout, new string[] { "还没有音箱哦,", "绑定智能音箱请前往第三方 APP 进行操作" });
@@ -88,8 +87,9 @@
            frame.AddChidren(listView);
            listView.BeginHeaderRefreshingAction += () =>
            {
                HdlThreadLogic.Current.RunThread(() =>
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    await getData();
                    //下拉刷新
                    iniView();
@@ -102,7 +102,62 @@
                });
            };
            this.ShowProgressBar();
            await getData();
            this.CloseProgressBar(ShowReLoadMode.NO);
            iniView();
        }
        /// <summary>
        /// 获取音箱列表
        /// </summary>
        /// <returns></returns>
        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);
            byte[] byteData = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(auth));
            //byte[] ResponseData = null;
            dataString = await UserCenterLogic.GetResponseDataByRequestHttps("zigbeespeakerservice/Auth", true, auth);
            //Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(pra)
            //dataString = System.Text.Encoding.UTF8.GetString(ResponseData);
            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 = await MyHttpWebResponse.PutWebRequest(url, json, Encoding.UTF8);
            JObject jObject = JObject.Parse(response_str);
            return jObject["StateCode"].ToString();
        }
        private void iniView()
@@ -110,33 +165,21 @@
            //
            listView.RemoveAll();
            if (smartSoundList == null)
            if (smartSoundInfo == null)
                return;
            for (int i = 0; i < smartSoundList.Count; i++)
            for (int i = 0; i < smartSoundInfo.ResponseData.Data.Count; i++)
            {
                //
                var smartSound = smartSoundList[i];
                var smartSound = smartSoundInfo.ResponseData.Data[i];
                var row = new SoundRowLayout();
                listView.AddChidren(row);
                switch (smartSound.Type)
                if (smartSound.Platform == "Baidu")
                {
                    case SmartSound.SMARTSOUND_XIAODU:
                        row.Account = "小度:" + smartSound.UserName;
                        row.ImagePath = "SmartSound/Xiaodu.png";
                        row.Remark = smartSound.Remark;
                        break;
                    case SmartSound.SMARTSOUND_XIAOAI:
                        row.Account = "小爱:" + smartSound.UserName;
                        row.ImagePath = "SmartSound/Xiaoai.png";
                        row.Remark = smartSound.Remark;
                        break;
                    case SmartSound.SMARTSOUND_TIANMAO:
                        row.Account = "天猫精灵:" + smartSound.UserName;
                        row.ImagePath = "SmartSound/Tianmao.png";
                        row.Remark = smartSound.Remark;
                        break;
                }
                row.InitControl();
@@ -148,7 +191,7 @@
                {
                    //
                    int index = (int)(((NormalViewControl)sender).GetTagByKey("index"));
                    var smartSound = smartSoundList[index];
                    var smartSound = smartSoundInfo.ResponseData.Data[index];
                    ShowRenameDialog(row, smartSound);
                };
@@ -164,6 +207,8 @@
                //跳转到控制内容界面
                row.frameTable.ButtonClickEvent += (sender, e) =>
                {
                    if (SmartSound.CurretnData != null)
                        SmartSound.CurretnData.Clear();
                    var smartSoundControlForm = new SmartSoundControlForm();
                    smartSoundControlForm.AddForm();
                };
@@ -177,17 +222,16 @@
        {
            this.ShowMassage(ShowMsgType.Confirm, "接触绑定需要第三方 APP 进行操作", () =>
            {
                //
                smartSoundList.RemoveAt(index);
                // 移除绑定的逻辑
                //smartSoundList.RemoveAt(index);
                listView.RemoveAt(index);
            },"跳转至小度 APP");
        }
        /// <summary>
        /// 重命名弹窗
        /// </summary>
        /// <returns></returns>
        private void ShowRenameDialog(SoundRowLayout soundRowLayout, SmartSound smartSound)
        private void ShowRenameDialog(SoundRowLayout soundRowLayout, SmartSoundInfo.SoundInfo smartSound)
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputControl();
@@ -197,45 +241,25 @@
            dialogForm.SetTipText(smartSound.Remark);
            //按下确认按钮
            dialogForm.ComfirmClickEvent += ((textValue) =>
            dialogForm.ComfirmClickEvent += (async (textValue) =>
            {
                //画面关闭
                dialogForm.CloseDialog();
                //上传备份
                smartSound.Remark = textValue;
                soundRowLayout.btnRemark.Text= textValue;
            });
        }
        /// <summary>
        /// 初始化模拟一些数据,用来加载界面用的
        /// </summary>
        private void iniData()
                string remark = textValue;
                string str = await setRemark(smartSound, remark); //上传备份
                if (str == "SUCCESS")
        {
            smartSoundList = new List<SmartSound>();
            // 增加小度音箱
            SmartSound smartSound = new SmartSound();
            smartSound.Remark = "我的音箱";
            smartSound.UserName = "123456@qq.com";
            smartSound.Type = SmartSound.SMARTSOUND_XIAODU;
            smartSoundList.Add(smartSound);
            // 增加小爱音箱
            smartSound = new SmartSound();
            smartSound.Remark = "我的音箱";
            smartSound.UserName = "234567@qq.com";
            smartSound.Type = SmartSound.SMARTSOUND_XIAOAI;
            smartSoundList.Add(smartSound);
            // 增加天猫精灵
            smartSound = new SmartSound();
            smartSound.Remark = "我的音箱";
            smartSound.UserName = "345678@qq.com";
            smartSound.Type = SmartSound.SMARTSOUND_TIANMAO;
            smartSoundList.Add(smartSound);
                    smartSound.Remark = remark;
                    soundRowLayout.btnRemark.Text = textValue;
                }
                else
                {
                    //错误弹窗提示
                    ShowMassage(ShowMsgType.Tip, "修改备注不成功!", null, "确认");
                }
            });
        }
        #endregion