tzy
2021-03-26 3cebdfad56d78ba04a214fccd1b942a010aeba77
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -8,12 +8,13 @@
{
    public class Method
    {
        /// <summary>
        /// 程序主入口
        /// 红外宝程序主入口
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="function"></param>
        public void MainView(FrameLayout frame, Entity.Function function,Action action)
        public void MainView(FrameLayout frame, Entity.Function function, Action action)
        {
            Pir pirDevice = new Pir();
            if (function != null)
@@ -22,6 +23,7 @@
                pirDevice.deviceId = function.deviceId;
                pirDevice.sid = function.sid;
                pirDevice.online = function.online;
                pirDevice.versions = function.versions;
            }
            Pir.currPir = pirDevice;
            GetControlList(frame, () =>
@@ -32,8 +34,10 @@
                    MainPage.BasePageView.AddChidren(page);
                    page.Show();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    page.BackAction += () => {
                    PirMain.BackAction += () =>
                    {
                        action?.Invoke();
                        PirMain.BackAction = null;
                    };
                });
            }, Pir.currPir);
@@ -139,7 +143,13 @@
                            {
                                if (device != null)
                                {
                                    control.deviceId = device.deviceId;
                                    //遥控器添加到列表;
                                    if (null == Pir.currPir.FunctioList.Find((c) => c.deviceId == device.deviceId))
                                    {
                                        Pir.currPir.FunctioList.Add(device);
                                    }
                                    frame.RemoveFromParent();//添加成功关闭弹窗
                                    action(control);
                                }
@@ -211,25 +221,10 @@
                                var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Pir>(str);
                                if (pirJosn != null)
                                {
/* 项目“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))
                                    {
/* 项目“HDL-ON_iOS”的未合并的更改
在此之前:
                                        Pir.pirDeviceList.Add(pirJosn);
在此之后:
                                        list.pirDeviceList.Add(pirJosn);
*/
                                    {
                                        PirDevice.Pir.pirDeviceList.Add(pirJosn);
                                    }
                                }
                            }
@@ -258,7 +253,7 @@
                            {
                                loading.Hide();
                                Method method = new Method();
                                method.ErrorShow(null,"读取红外宝列表失败");
                                method.ErrorShow(null, "读取红外宝列表失败");
                            }
                        }
                        catch { }
@@ -286,7 +281,7 @@
                        var pirDevice = Pir.pirDeviceList[i];
                        try
                        {
                            var responsePackNew = PirSend.ControlList(pirDevice);
                            var responsePackNew = PirSend.ControlList(pirDevice.deviceId);
                            if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                            {
                                var jArray = JArray.Parse(responsePackNew.Data.ToString());
@@ -331,57 +326,27 @@
        /// 获取单个红外宝遥控器列表
        /// </summary>
        /// <param name="action">回调函数</param>
        public static void GetControlList(FrameLayout frame ,Action action, Pir pirDevice)
        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();
            ThreadSend(new Control { deviceId = pirDevice.deviceId }, (responsePackNew) =>
             {
                 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.deviceId == pirJosn.deviceId))
                         {
                             pirDevice.FunctioList.Add(pirJosn);
                         }
                     }
                 }
                 action();
             }, "获取遥控器列表", "frame", frame, null);
        }
        /// <summary>
@@ -392,37 +357,12 @@
        /// <param name="action">回调函数</param>
        public void GetControl(FrameLayout frame, Control control, Action<Entity.Function> action)
        {
            Entity.Function function = null;
            //加载log
            Loading loading = new Loading();
            frame.AddChidren(loading);
            loading.Start();
            new System.Threading.Thread(() =>
            ThreadSend(control, (responsePackNew) =>
            {
                try
                {
                    // 获取设备详情通过(spk,sid)
                    var responsePackNew = PirSend.GetinfoBySid(control);
                    if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                    {
                        //var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data.ToString());
                        function = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(responsePackNew.Data.ToString());
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        action(function);
                    });
                }
            })
            { IsBackground = true }.Start();
                var function = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(responsePackNew.Data.ToString());
                action(function);
            }, "获取设备详情", "frame", frame, null);
        }
        /// <summary>
        /// 发送命令线程
        /// </summary>
@@ -432,9 +372,10 @@
        /// <param name="view">判断log父控件</param>
        /// <param name="frame">log父控件</param>
        /// <param name="dialog">log父控件</param>
        public static void ThreadSend(Control control, Action<ResponsePackNew> action, string str,string view, FrameLayout frame, Dialog dialog)
        /// <param name="attributesStatus">学习按键</param>
        public static void ThreadSend(Control control, Action<ResponsePackNew> action, string str, string view, FrameLayout frame, Dialog dialog, Entity.AttributesStatus attributesStatus=null)
        {
            //加载log
            Loading loading = new Loading();
            if (view == "dialog")
@@ -460,8 +401,25 @@
                        responsePackNew = PirSend.DeviceRename(control.deviceId, control.name);
                    }
                    else if (str == "删除按键") {
                       // responsePackNew = PirSend.CodeRemove(control.deviceId, control.name);
                    else if (str == "删除按键")
                    {
                        if (attributesStatus != null)
                        {
                            responsePackNew = PirSend.CodeRemove(attributesStatus, control.deviceId);
                        }
                    }
                    else if (str == "获取设备详情")
                    {
                        // 获取设备详情通过(spk,sid)
                        responsePackNew = PirSend.GetinfoBySid(control);
                    }
                    else if (str == "获取遥控器列表")
                    {
                        responsePackNew = PirSend.ControlList(control.deviceId);
                    }
                    else if (str == "库码测试")
                    {
                        responsePackNew = PirSend.CodeTest(control);
                    }
                }
                catch { }
@@ -477,7 +435,28 @@
                        else
                        {
                            Method method = new Method();
                            method.ErrorShow(responsePackNew, "");
                            //自定义错误提示文本
                            string eorroText = "";
                            if (str == "删除")
                            {
                            }
                            else if (str == "修改名称")
                            {
                            }
                            else if (str == "删除按键")
                            {
                            }
                            else if (str == "获取设备详情")
                            {
                            }
                            else if (str == "获取遥控器列表")
                            {
                            }
                            else if (str == "库码测试")
                            {
                            }
                            method.ErrorShow(responsePackNew, eorroText);
                        }
                    });
@@ -519,7 +498,7 @@
                    str = buttondata;
                }
                if (!string.IsNullOrEmpty(controldata))
                if (!string.IsNullOrEmpty(str))
                {
                    try
                    {
@@ -559,7 +538,11 @@
            }
            else if (text == "读取红外宝列表失败")
            {
                str = "读取红外宝列表失败"; //Language.StringByID(StringId.delFail);
                str = Language.StringByID(StringId.huoqushujushibao);
            }
            else if (text == "添加失败")
            {
                str = Language.StringByID(StringId.tianjiashibai);
            }
            else
            {
@@ -577,19 +560,19 @@
                            break;
                        case "10807":
                            {
                                str = "红外宝下遥控器超过最大(10个)数量限制";// Language.StringByID(StringId.gatewayNotOnline);
                                str = Language.StringByID(StringId.bunengchaoguo10);
                            }
                            break;
                        case "2":
                            {
                                str = "系统维护中~请稍后再试~";
                                str = Language.StringByID(StringId.xitongweihuzhong);
                            }
                            break;
                        default:
                            {
                                str ="获取数据失败" ;// Language.StringByID(StringId.saveFail);
                                str = Language.StringByID(StringId.huoqushujushibao);
                            }
                            break;
@@ -607,6 +590,79 @@
                case 3: { } break;
            }
        }
        /// <summary>
        ///指定刷新界面
        /// </summary>
        /// <param name="strView">判断字符</param>
        public static void RefreshView(string strView)
        {
            //标记是不是已经刷新完成
            bool if_bool = false;
            for (int i = MainPage.BasePageView.ChildrenCount - 1; 0 <= i; i--)
            {
                var view = MainPage.BasePageView.GetChildren(i);
                if (strView == "PirMain")
                {
                    if (view.GetType() == typeof(PirMain))
                    {
                        //强制转换对象
                        var f = (PirMain)view;
                        //移除所有子控件
                        f.RemoveAll();
                        //重新加载UI
                        f.Show();
                        //退出for循环
                        //break;
                        if_bool = true;
                    }
                }
                if (if_bool)
                {
                    //退出for循环
                    break;
                }
            }
        }
        /// <summary>
        /// 指定删除界面
        /// </summary>
        /// <param name="strView">判断字符</param>
        public static void RemoveView(string strView)
        {
            for (int i = MainPage.BasePageView.ChildrenCount - 1; 0 <= i; i--)
            {
                var view = MainPage.BasePageView.GetChildren(i);
                if (strView == "PirMain")
                {
                    if (view.GetType() == typeof(PirMain))
                    {
                        //移除界面
                        view.RemoveFromParent();
                    }
                }
                else if (strView == "AddControl")
                {
                    if (view.GetType() == typeof(AddControl))
                    {
                        //找到移除
                        view.RemoveFromParent();
                    }
                }
                else if (strView == "AddControlComplete")
                {
                    if (view.GetType() == typeof(AddControlComplete))
                    {
                        //找到移除
                        view.RemoveFromParent();
                    }
                }
            }
        }
    }
    [Serializable]