wxr
2023-02-24 7e8d169707c1c829b45172bffee4ecd00299185d
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
 
namespace HDL_ON.UI
{
    public class OrderFunctionPage : FrameLayout
    {
        #region 控件列表
        /// <summary>
        /// 当前窗体
        /// </summary>
        static FrameLayout bodyView;
        /// <summary>
        /// 功能列表集合显示区域
        /// </summary>
        static VerticalScrolViewLayout functionListView;
        /// <summary>
        /// 完成按钮
        /// </summary>
        Button btnConfrim;
 
        #endregion
        /// <summary>
        /// 回调刷新
        /// </summary>
        Action<Scene> backActon;
 
        List<Function> orderList = new List<Function>();
        List<int> orderNumber = new List<int>();
 
        public OrderFunctionPage()
        {
            bodyView = this;
        }
 
        public void LoadPage(List<Function> functions,Action action)
        {
            List<int> orderNumberAlreay = new List<int>();
            for (int i=0;i< functions.Count; i++)
            {
                if (functions[i].FunctionOrderNumber != 9999)
                {
                    orderNumberAlreay.Add(functions[i].FunctionOrderNumber);
                }
            }
            for (int i = 1; i < functions.Count + 1; i++)
            {
                if (!orderNumberAlreay.Contains(i))
                {
                    orderNumber.Add(i);
                }
            }
 
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.Sort)).LoadTopView();
 
            functionListView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(84),
                Height = Application.GetRealHeight(640 - 100),
            };
            bodyView.AddChidren(functionListView);
 
            LoadRow(functions);
 
            #region 底部view
            var bottomView = new FrameLayout()
            {
                Y = Application.GetRealHeight(591),
                Height = Application.GetRealHeight(100),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
            };
            this.AddChidren(bottomView);
 
            btnConfrim = new Button()
            {
                Y = Application.GetRealHeight(12),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                Radius = (uint)Application.GetRealHeight(22),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainBackgroundColor,
                BackgroundColor = CSS_Color.BackgroundColor,
                TextID = StringId.Confirm,
                TextSize = CSS_FontSize.SubheadingFontSize,
                SelectedTextColor = CSS_Color.MainBackgroundColor,
                SelectedBackgroundColor = CSS_Color.MainColor,
                IsSelected = true
            };
            bottomView.AddChidren(btnConfrim);
            btnConfrim.MouseUpEventHandler = (sender, e) => {
                foreach(var function in functions)
                {
                    function.SaveFunctionFile();
                }
                    action?.Invoke();
                    this.RemoveFromParent();
            };
 
            #endregion
 
        }
 
        /// <summary>
        /// 显示的设备的总数
        /// </summary>
        int showCount = 0;
 
        /// <summary>
        /// 加载功能row
        /// </summary>
        /// <param name="lightList"></param>
        void LoadRow(List<Function> functions, bool isAppend = false)
        {
            var waitPage = new Loading();
            bodyView.AddChidren(waitPage);
            waitPage.Start("");
 
            new System.Threading.Thread(() =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                        if (!isAppend)
                        {
                            showCount = 0;
                            functionListView.RemoveAll();
                        }
                        int i = 0;
 
 
 
                        foreach (var function in functions)
                        {
                            i++;
                            if (i > 100)
                            {
                                break;
                            }
                            showCount++;
                            var functionDiv = new OrderFunctionRow()
                            {
                                Gravity = Gravity.CenterHorizontal,
                                Width = Application.GetRealWidth(343),
                                Height = Application.GetRealHeight(62),
                                Radius = (uint)Application.GetMinRealAverage(12),
                                BorderColor = 0x00FFFFFF,
                                BorderWidth = 1,
                                BackgroundColor = CSS_Color.MainBackgroundColor,
                            };
 
                            functionDiv.LoadDiv(function, orderNumber);
 
 
                            functionListView.AddChidren(functionDiv);
 
                            functionListView.AddChidren(new Button() { Height = Application.GetRealHeight(12) });
                        }
 
                        if (functions.Count > showCount)
                        {
                            var btnAppend = new Button()
                            {
                                Height = Application.GetRealHeight(60),
                                TextAlignment = TextAlignment.Center,
                                TextSize = CSS_FontSize.SubheadingFontSize,
                                TextColor = CSS_Color.FirstLevelTitleColor,
                                Text = "加载更多",
                            };
                            if (Language.CurrentLanguage != "Chinese")
                            {
                                btnAppend.Text = "Load more";
                            }
                            functionListView.AddChidren(btnAppend);
                            btnAppend.MouseUpEventHandler = (sender, e) =>
                            {
                                btnAppend.RemoveFromParent();
                                LoadRow(functions, true);
                            };
                        }
                    });
                }
                catch (Exception ex)
                {
                    MainPage.Log("ShowFunctionRowError : " + ex.Message);
                }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        if (waitPage != null)
                        {
                            waitPage.RemoveFromParent();
                            waitPage = null;
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
 
        }
 
 
 
    }
 
 
 
    public class OrderFunctionRow : FrameLayout
    {
        #region 区域控件
        static FrameLayout bodyDiv;
        /// <summary>
        /// 功能/场景icon
        /// </summary>
        Button btnIcon;
        /// <summary>
        /// 功能名称/场景名称
        /// </summary>
        Button btnName;
        /// <summary>
        /// 楼层信息显示按钮
        /// </summary>
        Button btnFromFloor;
        /// <summary>
        /// 选中按钮
        /// </summary>
        Button btnSelect;
        #endregion
 
        public OrderFunctionRow()
        {
            bodyDiv = this;
        }
 
 
        /// <summary>
        /// 加载控制卡片区域
        /// </summary>
        public void LoadDiv(Function function, List<int> orderNumber)
        {
            btnIcon = new Button()
            {
                X = Application.GetRealWidth(10),
                Y = Application.GetRealHeight(15),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = $"FunctionIcon/Icon/{function.IconName}.png"
            };
            bodyDiv.AddChidren(btnIcon);
 
            btnName = new Button()
            {
                X = Application.GetRealWidth(8 + 10 + 32),
                Y = Application.GetRealHeight(10),
                Width = Application.GetRealWidth(200),
                Height = Application.GetRealHeight(24),
                Text = function.name,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
            };
            bodyDiv.AddChidren(btnName);
 
            btnFromFloor = new Button()
            {
                X = Application.GetRealWidth(8 + 10 + 32),
                Y = Application.GetRealHeight(10 + 24),
                Width = Application.GetRealWidth(200),
                Height = Application.GetRealHeight(18),
                Text = function.GetRoomListName(),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
            };
            bodyDiv.AddChidren(btnFromFloor);
 
            btnSelect = new Button()
            {
                X = Application.GetRealWidth(303),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                Text = function.FunctionOrderNumber == 9999 ? "" : function.FunctionOrderNumber.ToString(),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.Center,
            };
            bodyDiv.AddChidren(btnSelect);
 
            EventHandler<MouseEventArgs> eventHandler = (sender, e) => {
                lock (orderNumber)
                {
                    if (function.FunctionOrderNumber == 9999)
                    {
                        function.FunctionOrderNumber = orderNumber[0];
                        orderNumber.RemoveAt(0);
                        btnSelect.Text = function.FunctionOrderNumber.ToString();
                    }
                    else
                    {
 
                        if (!orderNumber.Contains(function.FunctionOrderNumber))
                        {
                            for (var i = 0; i < orderNumber.Count; i++)
                            {
                                if (orderNumber[i] > function.FunctionOrderNumber)
                                {
                                    orderNumber.Insert(i, function.FunctionOrderNumber);
                                    function.FunctionOrderNumber = 9999;
                                    break;
                                }
                            }
                        }
                        if (function.FunctionOrderNumber != 9999)
                        {
                            orderNumber.Add(function.FunctionOrderNumber);
                            function.FunctionOrderNumber = 9999;
                        }
                        btnSelect.Text = "";
                    }
                }   
            };
            btnName.MouseUpEventHandler = eventHandler;
            btnSelect.MouseUpEventHandler = eventHandler;
            bodyDiv.MouseUpEventHandler = eventHandler;
 
        }
    }
}