using System; using System.Collections.Generic; using HDL_ON.DAL.Server; using HDL_ON.Entity; using HDL_ON.UI.CSS; using HDL_ON.UI.UI2.Intelligence.Automation; using Shared; namespace HDL_ON.UI { public class SceneAutomationListChoosePage : FrameLayout { FrameLayout bodyView; Scene scene; Action refreshAction; List addedList = new List(); public SceneAutomationListChoosePage(Scene function, Action action) { scene = function; bodyView = this; refreshAction = action; refreshAction += () => { this.RemoveFromParent(); }; } public void LoadPage() { this.bodyView.BackgroundColor = CSS_Color.MainBackgroundColor; var topView = new TopViewDiv(bodyView,Language.StringByID( StringId.SelectAutomation)); topView.maginY = 10; topView.LoadTopView(); var contentView = new VerticalScrolViewLayout() { Y = Application.GetRealHeight(74), Height = Application.GetRealHeight(667-80), ScrollEnabled = false, }; bodyView.AddChidren(contentView); foreach (var logic in Logic.LogicList) { var funtionView = new FrameLayout() { Height = Application.GetRealHeight(50), }; contentView.AddChidren(funtionView); Button btnRight = new Button() { X = Application.GetRealWidth(339), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/Right.png", }; funtionView.AddChidren(btnRight); if (scene.functions.Find((obj) => obj.sid == logic.sid) != null) { addedList.Add(logic); var btnTipAdded = new Button() { Width = Application.GetRealWidth(327), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Added }; funtionView.AddChidren(btnTipAdded); addedList.Add(logic); } var btnFunctionTitle = new Button() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(220), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.SubheadingFontSize, Text = logic.name }; funtionView.AddChidren(btnFunctionTitle); var btnClick = new Button() { X = Application.GetRealWidth(300), Width = Application.GetRealWidth(70), }; funtionView.AddChidren(btnClick); btnClick.MouseUpEventHandler = (sender, e) => { LoadEditDialog_OnOff(logic.sid); }; contentView.AddChidren(new Button() { Height = 1, BackgroundColor = CSS_Color.DividingLineColor }); } } /// /// 加载自动化配置弹窗 /// void LoadEditDialog_OnOff(string logicSid) { Dialog dialog = new Dialog(); var pView = new FrameLayout() { BackgroundColor = CSS_Color.DialogTransparentColor1, }; dialog.AddChidren(pView); var optionBaseView = new FrameLayout() { Y = Application.GetRealHeight(500), Height = Application.GetRealHeight(160), AnimateSpeed = 0.3f, Animate = Animate.DownToUp, }; pView.AddChidren(optionBaseView); var optionView = new VerticalScrolViewLayout() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(100), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), ScrollEnabled = false, }; optionBaseView.AddChidren(optionView); var btnOn = new Button() { Height = Application.GetRealHeight(50), TextAlignment = TextAlignment.Center, TextColor = CSS_Color.TextualColor, SelectedTextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.SubheadingFontSize, TextID = StringId.OpenArm, }; optionView.AddChidren(btnOn); optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), BackgroundColor = CSS_Color.DividingLineColor }); var btnOff = new Button() { Height = Application.GetRealHeight(50), TextAlignment = TextAlignment.Center, TextColor = CSS_Color.TextualColor, SelectedTextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.SubheadingFontSize, TextID = StringId.Close, }; optionView.AddChidren(btnOff); var btnCancel = new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(8) + optionView.Bottom, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(50), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), TextID = StringId.Cancel, TextColor = CSS_Color.WarningColor, TextSize = CSS_FontSize.SubheadingFontSize, }; optionBaseView.AddChidren(btnCancel); dialog.Show(); pView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnCancel.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnOn.MouseUpEventHandler = (sender, e) => { dialog.Close(); var temp = scene.functions.Find((obj) => obj.sid == logicSid); if (temp != null) { var kv = temp.status.Find((obj) => obj.key == "enable"); if (kv != null) { kv.value = "true"; } else { temp.status.Add(new SceneFunctionStatus() { key = "enable", value = "true", }); } } else { temp = new SceneFunction(); temp.type = "7"; temp.sid = logicSid; temp.status.Add(new SceneFunctionStatus() { key = "enable", value = "true" }); scene.functions.Add(temp); } if (scene.userSceneId != null) { var waitPage = new Loading(); bodyView.AddChidren(waitPage); waitPage.Start(""); new System.Threading.Thread(() => { try { var code = scene.EditScene(); Application.RunOnMainThread(() => { if (code == "0") { refreshAction(); } else { IMessageCommon.Current.ShowErrorInfoAlter(code); } }); } catch { } finally { Application.RunOnMainThread(() => { if (waitPage != null) { waitPage.RemoveFromParent(); waitPage = null; } }); } }) { IsBackground = true }.Start(); } else { refreshAction(); } }; btnOff.MouseUpEventHandler = (sender, e) => { dialog.Close(); var temp = scene.functions.Find((obj) => obj.sid == logicSid); if (temp != null) { var kv = temp.status.Find((obj) => obj.key == "enable"); if (kv != null) { kv.value = "false"; } else { temp.status.Add(new SceneFunctionStatus() { key = "enable", value = "false", }); } } else { temp = new SceneFunction(); temp.type = "7"; temp.sid = logicSid; temp.status.Add(new SceneFunctionStatus() { key = "enable", value = "false" }); scene.functions.Add(temp); } if (scene.userSceneId != null) { var waitPage = new Loading(); bodyView.AddChidren(waitPage); waitPage.Start(""); new System.Threading.Thread(() => { try { var code = scene.EditScene(); Application.RunOnMainThread(() => { if (code == "0") { refreshAction(); } else { IMessageCommon.Current.ShowErrorInfoAlter(code); } }); } catch { } finally { Application.RunOnMainThread(() => { if (waitPage != null) { waitPage.RemoveFromParent(); waitPage = null; } }); } }) { IsBackground = true }.Start(); } else { refreshAction(); } }; } } }