陈嘉乐
2020-05-11 26cee91cc3332e09db5cadb9faf76612b1b0c081
ZigbeeApp/Shared/Phone/Device/Logic/SoneLogicList.cs
@@ -3,12 +3,12 @@
using Shared.Common;
using Shared.R;
using Shared;
using Shared.Phone.UserCenter.DoorLock;
namespace Shared.Phone.Device.Logic
{
    public class SoneLogicList : FrameLayout
    {
        public static SoneLogicList soneLogicList;
        public SoneLogicList()
        {
@@ -16,7 +16,7 @@
            soneLogicList = this;
        }
        /// 给徐梅刷新界面用的
        public Action<bool> action;
        public  Action<bool> action;
        ///第二块第一级父控件
        FrameLayout fLayout = new FrameLayout();
        ///常开模式图标
@@ -29,10 +29,8 @@
        FrameLayout listLogicFl = new FrameLayout();
        ///常开自动化列表上下滑动的控件
        VerticalRefreshLayout verticalRefresh = new VerticalRefreshLayout();
        public async void Show()
        {
            #region  界面的布局代码
            UserView.HomePage.Instance.ScrollEnabled = false;//锁住左滑
            TopView view = new TopView();
@@ -41,10 +39,6 @@
            view.clickBtn.MouseDownEventHandler += (sender, e) =>
            {
                UserView.HomePage.Instance.ScrollEnabled = true;
                if (updateThread != null && updateThread.IsAlive)
                {
                    updateThread.Abort();
                }
                //把静态变量的这个东西置空
                soneLogicList = null;
                this.RemoveFromParent();
@@ -146,7 +140,7 @@
            var addIconclickBtn = new Button
            {
                Width = Application.GetRealWidth(90+69+63),
                Width = Application.GetRealWidth(90 + 69 + 63),
                Height = Application.GetRealHeight(69),
                X = Application.GetRealWidth(800),
                Y = Application.GetRealHeight(60),
@@ -207,13 +201,28 @@
            };
            Read(true);
            #endregion
            DoorLockCommonInfo.LogicAction = (_bool) =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                        Send.CurrentDoorLock.IsDoorLockNormallyMode = _bool;
                        ModeView();
                    });
                }
                catch { }
            };
        }
        /// <summary>
        /// 常开模式开关切换图标界面
        /// </summary>
        public async void ModeView()
        {
            if (Send.CurrentDoorLock.IsDoorLockNormallyMode)
            {
                /// 查找是否存在时效性自动化;有的话就返回自动化对象;
@@ -242,23 +251,35 @@
                button1.MouseUpEventHandler = async (sender, e) =>
                {
                    var result = await UserCenter.DoorLock.DoorLockCommonInfo.DelNormallyOpenMode(Send.CurrentDoorLock);
                    if (result)
                    CommonPage.Loading.Start();
                    try
                    {
                        if (logic != null)
                        var result = await UserCenter.DoorLock.DoorLockCommonInfo.DelNormallyOpenMode(Send.CurrentDoorLock);
                        if (result)
                        {
                            ///有可能只有常开模式,没有时效性自动化
                            ///没有判断的话,逻辑会为空,抛出异常;
                            Send.DelLogic(logic.LogicId);
                            if (logic != null)
                            {
                                ///有可能只有常开模式,没有时效性自动化
                                ///没有判断的话,逻辑会为空,抛出异常;
                                Send.DelLogic(logic.LogicId);
                            }
                            Send.CurrentDoorLock.IsDoorLockNormallyMode = false;
                            ModeView();
                        }
                        Send.CurrentDoorLock.IsDoorLockNormallyMode = false;
                        ModeView();
                        else
                        {
                            LogicView.TipView.ShowFlashTip(Language.StringByID(MyInternationalizationString.closeFailed));
                        }
                    }
                    else
                    catch { }
                    finally
                    {
                        LogicView.TipView.ShowFlashTip(Language.StringByID(MyInternationalizationString.closeFailed));
                    }
                        Application.RunOnMainThread(() =>
                        {
                            CommonPage.Loading.Hide();
                        });
                    }
                };
                if (logic != null)
                {
@@ -271,21 +292,11 @@
                    button2.TextSize = 15;
                    button2.TextColor = ZigbeeColor.Current.LogicTextBlackColor;
                    ///有时效性常开才显示时间条件文本
                }
                else
                {
                    button2.Width = Application.GetRealWidth(0);
                    button2.Height = Application.GetRealHeight(0);
                }
                ///时效性常开只有一个条件;
                try
                {
                    var y = DateTime.Now.Year.ToString();//那一年
                    var m = DateTime.Now.Month.ToString();//那一月
                    var d = DateTime.Now.ToString("dd");//那一天
                    var h = int.Parse(DateTime.Now.ToString("HH"));//当前系统时间
                    var timeInt = int.Parse(logic.Conditions[0]["DoorLockOpenDelayTime"]);
                    var timeInt = int.Parse(logic.Conditions[0]["DoorLockOpenDelayTime"]);
                    int dayInt = (h + timeInt) / 24;//算出几天后执行
                    int hour = (h + timeInt) % 24;//算出几天后那个时间执行
                    int days = int.Parse(d) + dayInt;
@@ -296,7 +307,13 @@
                    string text5 = Language.StringByID(MyInternationalizationString.executeSone);
                    button2.Text = text1 + y + text2 + m + text3 + days.ToString() + text4 + hour.ToString() + text5;
                }
                catch { }
                else {
                    button2.Y = Application.GetRealHeight(0);
                    button2.X = Application.GetRealWidth(0);
                    button2.Width = Application.GetRealWidth(0);
                    button2.Height = Application.GetRealHeight(0);
                }
            }
            else
@@ -332,6 +349,7 @@
                button2.UnSelectedImagePath = "ZigeeLogic/nextIconSone.png";
                button2.TextSize = 15;
                button2.TextColor = ZigbeeColor.Current.LogicTextBlackColor;
                button2.Text ="";
                button2.MouseUpEventHandler = (sender, e) =>
                {
@@ -340,9 +358,11 @@
                    {///再次确认
                        LogicView.TipView.ShowInputTip(true, async (str) =>
                        {///确认发送命令
                            CommonPage.Loading.Start();
                            try
                            {
                                ///xm
                                var result = await UserCenter.DoorLock.DoorLockCommonInfo.SetNormallyOpenModeFuncAsync(Send.CurrentDoorLock);
                                if (!result)
                                {
@@ -365,11 +385,20 @@
                                    Send.CurrentDoorLock.IsDoorLockNormallyMode = true;
                                    ModeView();
                                }
                            }
                            catch
                            {
                            }
                            finally
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    CommonPage.Loading.Hide();
                                });
                            }
                        });
@@ -596,32 +625,6 @@
                };
            }
        }
        /// <summary>
        /// 定时更新常开模式(防止通过门锁关闭没及时刷新状态)
        /// </summary>
        System.Threading.Thread updateThread;
        public void UpdateModeIcon()
        {
            updateThread = new System.Threading.Thread(() =>
            {
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1000);
                    Application.RunOnMainThread(() =>
                    {
                        try
                        {
                            ModeView();
                        }
                        catch { }
                    });
                }
            });
            updateThread.Start();
        }
    }
}