黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Shared;
using Shared.Common;
using Shared.Phone;
using Shared.Phone.Device.Logic.LogicView;
using Shared.R;
using ZigBee.Device;
 
namespace Shared.Phone.Device.Logic
{
    public class LogicCommunalPage : FrameLayout
    {
 
        public LogicCommunalPage()
        {
            UserView.HomePage.Instance.RemoveViewByTag("Logic");
            Tag = "Logic";
        }
 
        public async void Show(Action action)
        {
 
            #region  View布局代码
            UserView.HomePage.Instance.ScrollEnabled = false;//锁住左滑
            TopView view = new TopView();
            this.AddChidren(view.TopRowView());
            if (Common.Logic.CurrentLogic.LogicId != 0)
            {
                view.toptitleNameBtn.Text = Language.StringByID(MyInternationalizationString.editautomation);
            }
            else
            {
                view.toptitleNameBtn.Text = Language.StringByID(MyInternationalizationString.newautomation);
            }
            view.clickBtn.MouseDownEventHandler += (sender, e) =>
            {
                // UserView.HomePage.Instance.ScrollEnabled = true;//恢复左滑
                action();
                RemoveFromParent();
            };
            var middle = new VerticalScrolViewLayout
            {
                Y = view.topRowLayout.Bottom,
                Height = Application.GetRealHeight(Method.H - 184 - 180),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
            var saveBtn = new SaveView();
            saveBtn.frameLayout.Y = middle.Bottom;
            saveBtn.frameLayout.Height = Application.GetRealHeight(180);
            this.AddChidren(saveBtn.Show());
            #endregion
 
            #region -----自动化名称 设置名称-----
            var logicnamefl = new FrameLayout
            {
                Height = Application.GetRealHeight(130),
                BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
            };
            middle.AddChidren(logicnamefl);
 
            var text = new Button
            {
                Width = Application.GetRealWidth(300),
                Height = Application.GetRealHeight(60),
                X = Application.GetRealWidth(58),
                TextAlignment = TextAlignment.CenterLeft,
                //Text = "自动化名称",
                TextID = MyInternationalizationString.automationname,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                Y = Application.GetRealHeight(35),
                TextSize = 15,
            };
            logicnamefl.AddChidren(text);
 
            EditText logicTextBox = new EditText
            {
                Y = Application.GetRealHeight(35),
                Width = Application.GetRealWidth(1080 - 58 - 300),
                Height = Application.GetRealHeight(60),
                X = text.Right,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
                TextSize = 14,
                Text = Common.Logic.CurrentLogic.LogicName,
                //TextID=MyInternationalizationString.automation1,
            };
            logicnamefl.AddChidren(logicTextBox);
 
            var fraline = new FrameLayout
            {
                Height = Application.GetRealHeight(30),
            };
            middle.AddChidren(fraline);
            #endregion
 
            #region -----显示逻辑条件-----
            Addview addconditionview = new Addview();
            addconditionview.iconBtn.Visible = true;
            addconditionview.titleBtn.TextID = MyInternationalizationString.ifcondition;
            middle.AddChidren(addconditionview.AddDeviceView());
 
            ///添加条件的点击事件
            addconditionview.clickBtn.MouseUpEventHandler += (sender, e) =>
             {
                 Common.Logic.CurrentLogic.LogicName = logicTextBox.Text.Trim();
                 if (Common.Logic.CurrentLogic.Conditions.Count == 1)
                 {
                     new LogicDveiceStatus { }.ConditionView(false, this);
                 }
                 else
                 {
                     var addLogicPage = new AddLogicPage();
                     UserView.HomePage.Instance.AddChidren(addLogicPage);
                     UserView.HomePage.Instance.PageIndex += 1;
                     addLogicPage.Show();
                 }
             };
            List<Dictionary<string, string>> ListConditions = new List<Dictionary<string, string>>();
            ListConditions.Clear();
            ListConditions.AddRange(Common.Logic.CurrentLogic.Conditions);
            ListConditions.Add(new Dictionary<string, string>());
            if (Common.Logic.CurrentLogic.Conditions.Count > 1)
            {
                var row = new FrameLayout
                {
                    Height = Application.GetRealHeight(60),
                    BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
                };
                middle.AddChidren(row);
                var relationship = new Button
                {
                    Width = Application.GetRealWidth(600),
                    Height = Application.GetRealHeight(60),
                    TextAlignment = TextAlignment.CenterLeft,
                    X = Application.GetRealWidth(58),
                    TextColor = ZigbeeColor.Current.LogicBtnCompleteColor,
                };
                row.AddChidren(relationship);
                if (Common.Logic.CurrentLogic.Relationship == 0)
                {
                    relationship.Text = Language.StringByID(MyInternationalizationString.followingconditions) + Language.StringByID(MyInternationalizationString.Allconditions);
                }
                else
                {
                    relationship.Text = Language.StringByID(MyInternationalizationString.followingconditions) + Language.StringByID(MyInternationalizationString.anycondition);
                }
                EventHandler<MouseEventArgs> editclick = (sender, e) =>
                {
                    Common.Logic.CurrentLogic.LogicName = logicTextBox.Text.Trim();
                    new LogicDveiceStatus { }.ConditionView(true, this);
                };
                row.MouseUpEventHandler += editclick;
                relationship.MouseUpEventHandler += editclick;
 
            }
            new LogicDveiceStatus { }.Conditions(this, middle, ListConditions, logicTextBox.Text.Trim());
 
            #endregion
 
            #region  ----显示执行目标----
 
            Addview addactionview = new Addview();
            addactionview.iconBtn.Visible = true;
            addactionview.titleBtn.TextID = MyInternationalizationString.execute;
            middle.AddChidren(addactionview.AddDeviceView());
            addactionview.clickBtn.MouseUpEventHandler += (sender, e) =>
             {
                 Common.Logic.CurrentLogic.LogicName = logicTextBox.Text.Trim();
                 Method.View(IfString.Action_Logic, IfString.Action_LogicScene);
             };
 
            List<Dictionary<string, object>> ListActions = new List<Dictionary<string, object>>();
            ListActions.Clear();
            ListActions.AddRange(Common.Logic.CurrentLogic.Actions);
            ListActions.Add(new Dictionary<string, object>());
            new LogicDveiceStatus { }.Actions(this, middle, ListActions, logicTextBox.Text.Trim());
 
            #endregion
 
            #region -----每天 设置周期-----
 
            var fraline1 = new FrameLayout
            {
                Height = Application.GetRealHeight(30),
            };
            middle.AddChidren(fraline1);
 
            Addview weekview = new Addview();
            weekview.iconBtn.Visible = true;
            weekview.iconBtn.UnSelectedImagePath = "ZigeeLogic/next.png";
            weekview.titleBtn.TextID = MyInternationalizationString.setupcycle;
            middle.AddChidren(weekview.AddDeviceView());
            var weekBtn = new Button
            {
                Width = Application.GetRealWidth(595),
                Height = Application.GetRealHeight(60),
                TextAlignment = TextAlignment.CenterRight,
                //Text = "每天",
                TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
                TextID = MyInternationalizationString.everyday,
                Y = Application.GetRealHeight(35 + 30),
                X = weekview.titleBtn.Right,
                TextSize = 14,
            };
            weekview.frameLayout.AddChidren(weekBtn);
            Method.UpdateWeek(weekBtn, Common.Logic.CurrentLogic);
            EventHandler<MouseEventArgs> cycleclick = (sender, e) =>
            {
                /*------保留每月,每年类型*/
                var cycle = new Cycle(() => { Method.UpdateWeek(weekBtn, Common.Logic.CurrentLogic); });
                UserView.HomePage.Instance.AddChidren(cycle);
                UserView.HomePage.Instance.PageIndex += 1;
                cycle.Show();
 
                //var cyclicCycle = new CyclicCycle(() => { UpdateWeek(btnweektext); });
                //UserView.HomePage.Instance.AddChidren(cyclicCycle);
                //UserView.HomePage.Instance.PageIndex += 1;
                //cyclicCycle.Show();
            };
            weekBtn.MouseUpEventHandler += cycleclick;
            weekview.clickBtn.MouseUpEventHandler += cycleclick;
            #endregion
 
            #region  ----推送设置----
            Method.Push(middle);
 
            #endregion
 
            saveBtn.clickviewBtn.MouseUpEventHandler += (sender, e) =>
             {
                 var name = logicTextBox.Text.Trim();
                 Method.SaveLogic(IfString._Logic, name, IfString.Tag, Common.Logic.CurrentLogic);
             };
        }
    }
}