tzy
2021-03-23 132ef8524e38d06da8cf74292a3ac1eff065bb1b
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -8,6 +8,36 @@
{
    public class Method
    {
        /// <summary>
        /// 程序主入口
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="function"></param>
        public void MainView(FrameLayout frame, Entity.Function function,Action action)
        {
            Pir pirDevice = new Pir();
            if (function != null)
            {//数据转换
                pirDevice.name = function.name;
                pirDevice.deviceId = function.deviceId;
                pirDevice.sid = function.sid;
                pirDevice.online = function.online;
            }
            Pir.currPir = pirDevice;
            GetControlList(frame, () =>
            {
                Application.RunOnMainThread(() =>
                {
                    var page = new PirMain();
                    MainPage.BasePageView.AddChidren(page);
                    page.Show();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    page.BackAction += () => {
                        action?.Invoke();
                    };
                });
            }, Pir.currPir);
        }
        /// <summary>
        /// 管理位置
@@ -181,10 +211,24 @@
                                var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Pir>(str);
                                if (pirJosn != null)
                                {
                                    if (null == Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
/* 项目“HDL-ON_iOS”的未合并的更改
在此之前:
                                    if (null == Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
在此之后:
                                    if (null == list.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
*/
                                    if (null == PirDevice.Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
                                    {
                                        Pir.pirDeviceList.Add(pirJosn);
/* 项目“HDL-ON_iOS”的未合并的更改
在此之前:
                                        Pir.pirDeviceList.Add(pirJosn);
在此之后:
                                        list.pirDeviceList.Add(pirJosn);
*/
                                        PirDevice.Pir.pirDeviceList.Add(pirJosn);
                                    }
                                }
@@ -227,7 +271,7 @@
        }
        /// <summary>
        /// 获取遥控器列表
        /// 获取所有红外宝遥控器列表
        /// </summary>
        /// <param name="action">回调函数</param>
        public static void GetControlList(Action action)
@@ -282,6 +326,64 @@
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 获取单个红外宝遥控器列表
        /// </summary>
        /// <param name="action">回调函数</param>
        public static void GetControlList(FrameLayout frame ,Action action, Pir pirDevice)
        {
            Loading loading = new Loading();
            frame.AddChidren(loading);
            loading.Start();
            new System.Threading.Thread(() =>
            {
                try
                {
                    try
                    {
                        var responsePackNew = PirSend.ControlList(pirDevice);
                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                        {
                            var jArray = JArray.Parse(responsePackNew.Data.ToString());
                            for (int a = 0; a < jArray.Count; a++)
                            {
                                var jay = jArray[a];
                                //数据返序列化为Logic对象
                                var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
                                var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(str);
                                if (pirJosn != null)
                                {
                                    if (null == pirDevice.FunctioList.Find((c) => c.sid == pirJosn.sid))
                                    {
                                        pirDevice.FunctioList.Add(pirJosn);
                                    }
                                }
                            }
                        }
                    }
                    catch { }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        action();
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 获取设备详情通过(spk,sid)
        /// </summary>
@@ -320,22 +422,72 @@
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 发送命令线程
        /// </summary>
        /// <param name="control">发送数据对象</param>
        /// <param name="action">回调函数</param>
        /// <param name="str">判断字符</param>
        /// <param name="view">判断log父控件</param>
        /// <param name="frame">log父控件</param>
        /// <param name="dialog">log父控件</param>
        public void ThreadSend(Control control, Action<HDL_ON.DAL.Server.ResponsePackNew> action, string str, FrameLayout frame, Dialog dialog)
        public static void ThreadSend(Control control, Action<ResponsePackNew> action, string str,string view, FrameLayout frame, Dialog dialog)
        {
            //加载log
            Loading loading = new Loading();
            if (view == "dialog")
            {
                dialog.AddChidren(loading);
            }
            else
            {
                frame.AddChidren(loading);
            }
            loading.Start();
            ResponsePackNew responsePackNew = null;
            new System.Threading.Thread(() =>
            {
                try
                {
                    if (str == "删除")
                    {
                        responsePackNew = PirSend.DeleteDevice(control.deviceId);
                    }
                    else if (str == "修改名称")
                    {
                        responsePackNew = PirSend.DeviceRename(control.deviceId, control.name);
                    }
                    else if (str == "删除按键") {
                       // responsePackNew = PirSend.CodeRemove(control.deviceId, control.name);
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                        {
                            action(responsePackNew);
                        }
                        else
                        {
                            Method method = new Method();
                            method.ErrorShow(responsePackNew, "");
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// MQTT主题推送下来的遥控器数据
        /// </summary>
@@ -358,11 +510,11 @@
            while ((DateTime.Now - dateTime).TotalMilliseconds < timeValue * 1000)
            {
                string str = "";
                if (str == "遥控器")
                if (text == "遥控器")
                {
                    str = controldata;
                }
                else if (str == "按键")
                else if (text == "按键")
                {
                    str = buttondata;
                }