From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 16 四月 2020 17:10:57 +0800
Subject: [PATCH] 请合并代码

---
 ZigbeeApp/Shared/Phone/MainPage/Controls/SafetyShortcutControl.cs |  309 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 309 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/MainPage/Controls/SafetyShortcutControl.cs b/ZigbeeApp/Shared/Phone/MainPage/Controls/SafetyShortcutControl.cs
new file mode 100755
index 0000000..38484ea
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/MainPage/Controls/SafetyShortcutControl.cs
@@ -0,0 +1,309 @@
+锘縰sing Shared.Common;
+using Shared.Phone.Device.CommonForm;
+using Shared.Phone.UserCenter;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shared.Phone.MainPage.Controls
+{
+    /// <summary>
+    /// 瀹夐槻蹇嵎鏂瑰紡鎺т欢
+    /// </summary>
+    public class SafetyShortcutControl : Button
+    {
+        /// <summary>
+        /// dialog
+        /// </summary>
+        private Dialog dialog;
+        /// <summary>
+        /// SafetyShortcut
+        /// </summary>
+        public SafetyShortcutControl()
+        {
+            this.Height = Application.GetMinRealAverage(69);
+            this.Width = Application.GetMinRealAverage(69);
+            this.UnSelectedImagePath = "Item/SafetyShortcut.png";
+            this.MouseUpEventHandler += (sender, e) =>
+            {
+                Show();
+            };
+        }
+
+        /// <summary>
+        /// Show
+        /// </summary>
+        private void Show()
+        {
+            Common.CommonPage.Instance.IsDrawerLockMode = true;
+
+            dialog = new Dialog();
+            dialog.BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor;
+            dialog.Show();
+            var closeBGview = new FrameLayout();
+            dialog.AddChidren(closeBGview);
+            closeBGview.MouseUpEventHandler += (send1, e1) =>
+            {
+                dialog.Close();
+            };
+
+            var bg = new Button
+            {
+                X = Application.GetRealWidth(495),
+                Y = Application.GetRealHeight(161),
+                Width = Application.GetRealWidth(449),
+                Height = Application.GetRealHeight(495),
+                UnSelectedImagePath = "Item/SafetyShortcut_background.png"
+            };
+            closeBGview.AddChidren(bg);
+
+            var bg1 = new FrameLayout
+            {
+                X = Application.GetRealWidth(495),
+                Y = Application.GetRealHeight(161),
+                Width = Application.GetRealWidth(449),
+                Height = Application.GetRealHeight(495),
+            };
+            closeBGview.AddChidren(bg1);
+
+            new System.Threading.Thread(async () =>
+            {
+                //鍒锋柊
+                var result = await HdlSafeguardLogic.Current.ReFreshByGateway();
+                if (result == false)
+                {
+                    return;
+                }
+                //鏄惁璁剧疆鏈夊唴閮ㄩ槻鍖�
+                Application.RunOnMainThread(() =>
+                {
+                    RefreshSafeZone(bg1, HdlSafeguardLogic.Current.IsHadInternalDefenseArea());
+                });
+            })
+            { IsBackground = true }.Start();
+        }
+
+        /// <summary>
+        /// 鏄剧ず闃插尯
+        /// </summary>
+        /// <param name="statu">true 3涓槻鍖� false 2涓槻鍖�</param>
+        private void RefreshSafeZone(FrameLayout layout, bool statu)
+        {
+            if (statu)
+            {
+                ShowThreeSafeType(layout);
+            }
+            else
+            {
+                ShowTwoSafeType(layout);
+            }
+        }
+
+        /// <summary>
+        /// 甯冮槻鎾ら槻
+        /// </summary>
+        /// <param name="layout"></param>
+        private void ShowTwoSafeType(FrameLayout layout)
+        {
+            Device.CommonForm.LeftIconButtonRow tempRow;
+            var atHome = new Device.CommonForm.LeftIconButtonRow(449, 150);
+            atHome.Y = Application.GetRealHeight(32);
+            atHome.Init("Item/SafetyShortcut_item.png", "Item/SafetyShortcut_itemSelected.png", Language.StringByID(R.MyInternationalizationString.uGarrison));
+            layout.AddChidren(atHome);
+            atHome.Tag = GarrisonMode.AtHome;
+            if (HdlSafeguardLogic.Current.NowGarrisonMode == GarrisonMode.AtHome)
+            {
+                atHome.IsSelected = true;
+                tempRow = atHome;
+            }
+            atHome.ButtonClickEvent += (sender, e) =>
+            {
+                dialog.Close();
+                if (sender.IsSelected)
+                {
+                    return;
+                }
+                CommonPage.Loading.Start();
+                new System.Threading.Thread(async () =>
+                {
+                    var result = await HdlSafeguardLogic.Current.SetSafetyGarrisonByModel(GarrisonMode.AtHome);
+                    Application.RunOnMainThread(() =>
+                    {
+                        CommonPage.Loading.Hide();
+                        if (result == GarrisonMode.AtHome)
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uSetGarrisonSuccess));
+                        }
+                        else
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uSetGarrisonFail));
+                        }
+                    });
+
+                })
+                { IsBackground = true }.Start();
+            };
+
+
+            var withdrawGarriso = new Device.CommonForm.LeftIconButtonRow(449, 150);
+            withdrawGarriso.Y = atHome.Bottom + Application.GetRealHeight(3);
+            withdrawGarriso.Init("Item/SafetyShortcut_item.png", "Item/SafetyShortcut_itemSelected.png", Language.StringByID(R.MyInternationalizationString.uWithdrawGarrison));
+            layout.AddChidren(withdrawGarriso);
+            withdrawGarriso.Tag = GarrisonMode.RemoveGarrison;
+            if (HdlSafeguardLogic.Current.NowGarrisonMode == GarrisonMode.None)
+            {
+                withdrawGarriso.IsSelected = true;
+                tempRow = withdrawGarriso;
+            }
+            withdrawGarriso.ButtonClickEvent += (sender, e) =>
+            {
+                dialog.Close();
+                if (sender.IsSelected)
+                {
+                    return;
+                }
+                CommonPage.Loading.Start();
+                new System.Threading.Thread(async () =>
+                {
+                    var result = await HdlSafeguardLogic.Current.RemoveSafetyGarrison(GarrisonMode.RemoveGarrison, true);
+                    Application.RunOnMainThread(() =>
+                    {
+                        CommonPage.Loading.Hide();
+                        if (result == 1)
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uRemoveGarrisonSuccess));
+                        }
+                        else
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uRemoveGarrisonFail));
+                        }
+                    });
+                })
+                { IsBackground = true }.Start();
+            };
+        }
+
+        /// <summary>
+        /// 鍦ㄥ 绂诲 鎾ら槻
+        /// </summary>
+        /// <param name="layout"></param>
+        private void ShowThreeSafeType(FrameLayout layout)
+        {
+            var atHome = new Device.CommonForm.LeftIconButtonRow(449, 150);
+            atHome.Y = Application.GetRealHeight(32);
+            atHome.Init("Item/SafetyShortcut_item.png", "Item/SafetyShortcut_itemSelected.png", Language.StringByID(R.MyInternationalizationString.uAtHomeGarrison));
+            layout.AddChidren(atHome);
+            if (HdlSafeguardLogic.Current.NowGarrisonMode == GarrisonMode.AtHome)
+            {
+                atHome.IsSelected = true;
+            }
+            atHome.ButtonClickEvent += (sender, e) =>
+            {
+                dialog.Close();
+                if (sender.IsSelected)
+                {
+                    return;
+                }
+                CommonPage.Loading.Start();
+                new System.Threading.Thread(async () =>
+                {
+                    var result = await HdlSafeguardLogic.Current.SetSafetyGarrisonByModel(GarrisonMode.AtHome);
+                    Application.RunOnMainThread(() =>
+                    {
+                        CommonPage.Loading.Hide();
+                        if (result == GarrisonMode.AtHome)
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uSetAtHomeGarrisonSuccess));
+                        }
+                        else
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uSetGarrisonFail));
+                        }
+                    });
+                })
+                { IsBackground = true }.Start();
+            };
+
+
+            var removeHome = new Device.CommonForm.LeftIconButtonRow(449, 150);
+            removeHome.Y = atHome.Bottom + Application.GetRealHeight(3);
+            removeHome.Init("Item/SafetyShortcut_item.png", "Item/SafetyShortcut_itemSelected.png", Language.StringByID(R.MyInternationalizationString.uRemoveHomeGarrison));
+            layout.AddChidren(removeHome);
+            if (HdlSafeguardLogic.Current.NowGarrisonMode == GarrisonMode.RemoveHome)
+            {
+                removeHome.IsSelected = true;
+            }
+            removeHome.ButtonClickEvent += (sender, e) =>
+            {
+                dialog.Close();
+                if (sender.IsSelected)
+                {
+                    return;
+                }
+                CommonPage.Loading.Start();
+                new System.Threading.Thread(async () =>
+                {
+                    var result = await HdlSafeguardLogic.Current.SetSafetyGarrisonByModel(GarrisonMode.RemoveHome);
+                    Application.RunOnMainThread(() =>
+                    {
+                        CommonPage.Loading.Hide();
+                        if (result == GarrisonMode.RemoveHome)
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uSetRemoveHomeGarrisonSuccess));
+                        }
+                        else
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uSetGarrisonFail));
+                        }
+                    });
+                })
+                { IsBackground = true }.Start();
+            };
+
+            var withdrawGarriso = new Device.CommonForm.LeftIconButtonRow(449, 150);
+            withdrawGarriso.Y = removeHome.Bottom + Application.GetRealHeight(3);
+            withdrawGarriso.Init("Item/SafetyShortcut_item.png", "Item/SafetyShortcut_itemSelected.png", Language.StringByID(R.MyInternationalizationString.uWithdrawGarrison));
+            layout.AddChidren(withdrawGarriso);
+            withdrawGarriso.HidenLine(true);
+            if (HdlSafeguardLogic.Current.NowGarrisonMode == GarrisonMode.None)
+            {
+                withdrawGarriso.IsSelected = true;
+            }
+            withdrawGarriso.ButtonClickEvent += (sender, e) =>
+            {
+                dialog.Close();
+                if (sender.IsSelected)
+                {
+                    return;
+                }
+                CommonPage.Loading.Start();
+                new System.Threading.Thread(async () =>
+                {
+                    var result = await HdlSafeguardLogic.Current.RemoveSafetyGarrison(GarrisonMode.RemoveGarrison, true);
+                    Application.RunOnMainThread(() =>
+                    {
+                        CommonPage.Loading.Hide();
+                        if (result == 1)
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uRemoveGarrisonSuccess));
+                        }
+                        else
+                        {
+                            CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.uRemoveGarrisonFail));
+                        }
+                    });
+                })
+                { IsBackground = true }.Start();
+            };
+        }
+
+        /// <summary>
+        /// RemoveFromParent
+        /// </summary>
+        public override void RemoveFromParent()
+        {
+            Common.CommonPage.Instance.IsDrawerLockMode = false;
+            base.RemoveFromParent();
+        }
+    }
+}

--
Gitblit v1.8.0