wxr
2023-05-30 b07d4f6ffbbc942c2e00fbedee5203bbec8d52fb
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
using System;
using System.Collections.Generic;
using System.Linq;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
    public partial class FunctionPage : FrameLayout
    {
        #region 控件列表
        /// <summary>
        /// 当前窗体
        /// </summary>
        static FrameLayout bodyView;
        /// <summary>
        /// 楼层选择下拉图标
        /// </summary>
        Button btnFloorDownIcon;
        /// <summary>
        /// 楼层显示
        /// </summary>
        Button btnFloor;
        /// <summary>
        /// 功能列表集合显示区域
        /// </summary>
        static VerticalScrolViewLayout functionListView;
        #endregion
 
        List<Function> functionList;
        int titleId;
 
        public FunctionPage()
        {
            bodyView = this;
            functionList = new List<Function>();
 
        }
 
        public void LoadPage(int titleId_out)
        {
            this.titleId = titleId_out;
 
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            if (titleId == StringId.Lights && !DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl)
            {
                Action action = () =>
                {
 
                    Action<Scene > refreshAction = (outScene) => {
                        if (outScene != null)
                        {
                            functionListView.AddChidren(new Button() { Height = Application.GetRealHeight(12) });
 
                            var sceneRow = new SceneControlZone(outScene);
                            functionListView.AddChidren(sceneRow);
                            sceneRow.LoadView();
                        }
                    };
 
                    var skipView = new AddLightScene(new List<Function>(), new Scene() { sceneType = SceneType.LightScene }, refreshAction);
                    MainPage.BasePageView.AddChidren(skipView);
                    skipView.LoadPage();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                };
                new TopViewDiv(bodyView, Language.StringByID(titleId)).LoadTopView_LightFunction(action);
            }
            else
            {
                new TopViewDiv(bodyView, Language.StringByID(titleId)).LoadTopView();
            }
 
 
 
#if DEBUG
            //Button testBtn = new Button()
            //{
            //    X = Application.GetRealWidth(80),
            //    Height = Application.GetRealHeight(64),
            //    BackgroundColor = 0xFFFF0000
            //};
            //bodyView.AddChidren(testBtn);
            //int ddd = 0;
            //testBtn.MouseUpEventHandler = (sender, e) => {
            //    ddd++;
            
            //        Function function_online = FunctionList.List.GetLightList().Find((obj) => obj.sid == "0001017DB92D2602020100010101");
            //    if (ddd % 2 == 0)
            //    {
            //        function_online.online = true;
            //    }
            //    else
            //    {
            //        function_online.online = false;
            //    }
            //    HomePage.LoadEvent_RefreshDevcieOnline(function_online);
            //    FunctionPage.UpdataOnline(function_online);
            //    RoomPage.UpdataOnline(function_online);
 
 
            //};
#endif
 
            /// <summary>
            /// 房间内容显示区域
            /// </summary>
            var roomFloorChangeView = new FrameLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(52),
            };
            bodyView.AddChidren(roomFloorChangeView);
            #region 房间顶部切换显示区域
            btnFloorDownIcon = new Button()
            {
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(18),
                UnSelectedImagePath = "Public/DownIcon.png",
            };
            roomFloorChangeView.AddChidren(btnFloorDownIcon);
           
            btnFloor = new Button()
            {
                X = btnFloorDownIcon.Right,
                Y = Application.GetRealHeight(18),
                Width = Application.GetRealWidth(200),
                Height = Application.GetMinRealAverage(16),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextAlignment = TextAlignment.CenterLeft,
                Text = DB_ResidenceData.Instance.CurFloor.roomName,
            };
            roomFloorChangeView.AddChidren(btnFloor);
            #endregion
 
            functionListView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64 + 52),
                Height = Application.GetRealHeight(603 - 12 - 52),
            };
            bodyView.AddChidren(functionListView);
 
            if (titleId == StringId.Lights)
            {
                functionList.AddRange(FunctionList.List.groupControls);
                functionList.AddRange(FunctionList.List.GetLightList());
 
 
 
 
            }
            else if (titleId == StringId.AC)
            {
                functionList.AddRange(FunctionList.List.GetAcList());
            }
            else if (titleId == StringId.Curtain)
            {
                functionList.AddRange(FunctionList.List.GetCurtainList());
            }
            else if (titleId == StringId.FloorHeating)
            {
                functionList.AddRange(FunctionList.List.GetFloorHeatingList());
            }
            else if (titleId == StringId.Electric)
            {
                functionList.AddRange(FunctionList.List.GetElectricals());
            }
            else if (titleId == StringId.EnvironmentalScience)
            {
                functionList.AddRange(FunctionList.List.GetEnvirSensorsList());
            }
            else if (titleId == StringId.Sensor)
            {
                functionList.AddRange(FunctionList.List.GetArmSensorList());
            }
            else if (titleId == StringId.FreshAir)
            {
                functionList.AddRange(FunctionList.List.GetAirFreshList());
            }
            else if(titleId == StringId.MechanicalArm)
            {
                functionList.AddRange(FunctionList.List.GetMechanicalArmList());
            }
            else if(titleId == StringId.SecurityMonitoring)
            {
                functionList.AddRange(FunctionList.List.GetIpCamImouList());
            }
            functionList = functionList.OrderByDescending(o => o.controlCounter).ToList();
 
            ShowFunctionRow(functionList);
 
            LoadDialog_ChangeFloor();
 
 
        
 
        }
        /// <summary>
        /// 显示的设备的总数
        /// </summary>
        int showCount = -1;
        /// <summary>
        /// 加载功能row
        /// </summary>
        void ShowFunctionRow(List<Function> showList, bool isAppend = false)
        {
            var waitPage = new Loading();
            bodyView.AddChidren(waitPage);
            waitPage.Start("");
 
            new System.Threading.Thread(() =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                        if (!isAppend)
                        {
                            showCount = -1;
                            functionListView.RemoveAll();
                            #region 加载组合调光场景
                            if (titleId == StringId.Lights)
                            {
                                foreach (var lightScene in FunctionList.List.scenes)
                                {
                                    if (lightScene.sceneType == SceneType.LightScene)
                                        if (lightScene != null)
                                        {
                                            var sceneRow = new SceneControlZone(lightScene);
                                            functionListView.AddChidren(sceneRow);
                                            sceneRow.LoadView();
                                            functionListView.AddChidren(new Button() { Height = Application.GetRealHeight(12) });
                                        }
                                }
                            }
                            #endregion
                        }
                        for (var i = 0;i<50;i++)
                        //foreach (var function in showList)
                        {
                            showCount++;
                            if (showCount >= showList.Count)
                            {
                                break;
                            }
                            var function = showList[showCount];
 
                            if (function.spk == SPK.SensorDryContact || function.spk == SPK.SensorDryContact2)
                            {
                                continue;
                            }
                            if (function.spk == SPK.LightRGBW || function.spk == SPK.LightRGB || function.spk == SPK.LightDimming)
                            {
                                var functionDiv = new FunctionControlZone(function,null)
                                {
                                    Gravity = Gravity.CenterHorizontal,
                                    Width = Application.GetRealWidth(343),
                                    Height = Application.GetRealHeight(116),
                                    Radius = (uint)Application.GetMinRealAverage(12),
                                    BorderColor = 0x00FFFFFF,
                                    BorderWidth = 1,
                                    BackgroundColor = CSS_Color.MainBackgroundColor,
                                    Tag = function.spk + function.sid
                                };
                                functionDiv.LoadFunctionDiv();
                                functionDiv.OrderEvent = OrderEvent;
                                functionListView.AddChidren(functionDiv);
                            }
                            else if (function.spk == SPK.IpCam_Imou)
                            {
                                var functionDiv = new FunctionControlZone(function,null)
                                {
                                    Gravity = Gravity.CenterHorizontal,
                                    Width = Application.GetRealWidth(343),
                                    Height = Application.GetRealHeight(96),
                                    Radius = (uint)Application.GetMinRealAverage(12),
                                    BorderColor = 0x00FFFFFF,
                                    BorderWidth = 1,
                                    BackgroundColor = CSS_Color.MainBackgroundColor,
                                    Tag = function.spk + function.sid
                                };
                                functionDiv.LoadFunctionDiv();
                                functionListView.AddChidren(functionDiv);
 
                            }
                            else
                            {
                                var functionDiv = new FunctionControlZone(function,null)
                                {
                                    Gravity = Gravity.CenterHorizontal,
                                    Width = Application.GetRealWidth(343),
                                    Height = Application.GetRealHeight(96),
                                    Radius = (uint)Application.GetMinRealAverage(12),
                                    BorderColor = 0x00FFFFFF,
                                    BorderWidth = 1,
                                    BackgroundColor = CSS_Color.MainBackgroundColor,
                                    Tag = function.spk + function.sid
                                };
                                functionDiv.LoadFunctionDiv();
                                functionDiv.OrderEvent = OrderEvent;
                                functionListView.AddChidren(functionDiv);
                            }
                            functionListView.AddChidren(new Button() { Height = Application.GetRealHeight(10) });
                        }
                        if (showList.Count > showCount)
                        {
                            var btnAppend = new Button()
                            {
                                Height = Application.GetRealHeight(60),
                                TextAlignment = TextAlignment.Center,
                                TextSize = CSS_FontSize.SubheadingFontSize,
                                TextColor = CSS_Color.FirstLevelTitleColor,
                                TextID = StringId.LoadMore,
                            };
                            functionListView.AddChidren(btnAppend);
                            btnAppend.MouseUpEventHandler = (sender, e) =>
                            {
                                btnAppend.RemoveFromParent();
                                ShowFunctionRow(showList, true);
                            };
                        }
 
                    });
                }
                catch (Exception ex)
                {
                    MainPage.Log("ShowFunctionRowError : " + ex.Message);
                }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        if (waitPage != null)
                        {
                            waitPage.RemoveFromParent();
                            waitPage = null;
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 排序事件
        /// </summary>
        void OrderEvent()
        {
            Action action = () =>
            {
                functionList = functionList.OrderBy(o => o.FunctionOrderNumber).ToList();
                ShowFunctionRow(functionList);
            };
            var skipView = new OrderFunctionPage();
            MainPage.BasePageView.AddChidren(skipView);
            skipView.LoadPage(functionList, action);
            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
        }
 
        ///// <summary>
        ///// 加载功能类型控制卡片
        ///// </summary>
        //public void LoadSceneRow(Scene scene)
        //{
        //    var bodyDiv = new FrameLayout()
        //    {
        //        Gravity = Gravity.CenterHorizontal,
        //        Width = Application.GetRealWidth(343),
        //        Height = Application.GetRealHeight(116),
        //        Radius = (uint)Application.GetMinRealAverage(12),
        //        BorderColor = 0x00FFFFFF,
        //        BorderWidth = 1,
        //        BackgroundColor = CSS_Color.MainBackgroundColor,
        //        Tag = "Scene-" + scene.sid
        //    };
        //    functionListView.AddChidren(bodyDiv);
 
        //    var btnIcon = new Button()
        //    {
        //        X = Application.GetRealWidth(10),
        //        Y = Application.GetRealHeight(15),
        //        Width = Application.GetRealWidth(32),
        //        Height = Application.GetRealWidth(32),
        //    };
        //    bodyDiv.AddChidren(btnIcon);
 
        //    var btnName = new Button()
        //    {
        //        X = Application.GetRealWidth(8 + 10 + 32),
        //        Y = Application.GetRealHeight(10),
        //        Width = Application.GetRealWidth(200),
        //        Height = Application.GetRealHeight(24),
        //        Text = scene.name,
        //        TextAlignment = TextAlignment.CenterLeft,
        //        TextColor = CSS_Color.FirstLevelTitleColor,
        //        TextSize = CSS_FontSize.TextFontSize,
        //    };
        //    bodyDiv.AddChidren(btnName);
 
        //    var btnFromFloor = new Button()
        //    {
        //        X = Application.GetRealWidth(8 + 10 + 32),
        //        Y = Application.GetRealHeight(10 + 24),
        //        Width = Application.GetRealWidth(200),
        //        Height = Application.GetRealHeight(18),
        //        Text = scene.GetRoomListName(),
        //        TextAlignment = TextAlignment.CenterLeft,
        //        TextColor = CSS_Color.PromptingColor1,
        //        TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
        //    };
        //    bodyDiv.AddChidren(btnFromFloor);
 
        //    var btnCollectionIcon = new Button()
        //    {
        //        X = Application.GetRealWidth(299),
        //        Y = Application.GetRealHeight(10),
        //        Width = Application.GetMinRealAverage(40),
        //        Height = Application.GetMinRealAverage(40),
        //        SelectedImagePath = "Collection/CollectionIcon.png",
        //        UnSelectedImagePath = "Collection/CollectionGrayIcon.png",
        //        IsSelected = scene.collect
        //    };
        //    bodyDiv.AddChidren(btnCollectionIcon);
 
        //    btnIcon.UnSelectedImagePath = "FunctionIcon/Scene/SceneIcon.png";
        //    if (scene.sceneType == SceneType.MovieScene)
        //    {
        //        var movieIcon = new Button()
        //        {
        //            X = Application.GetRealWidth(52),
        //            Y = Application.GetRealHeight(14),
        //            Width = Application.GetRealWidth(16),
        //            Height = Application.GetRealWidth(16),
        //            UnSelectedImagePath = "FunctionIcon/Scene/MovieMark.png",
        //        };
        //        bodyDiv.AddChidren(movieIcon);
        //        btnName.X = Application.GetRealWidth(52 + 16);
        //    }
        //    //加载场景控制事件
        //    LoadEvent_ControlScene(btnName, btnFromFloor, bodyDiv, scene);
 
        //    LoadEvent_FunctionCollection(btnCollectionIcon, scene);
        //}
 
 
        ///// <summary>
        ///// 加载功能收藏按钮事件
        ///// </summary>
        //void LoadEvent_FunctionCollection(Button btnCollectionIcon, Scene scene)
        //{
        //    btnCollectionIcon.MouseUpEventHandler += (sender, e) =>
        //    {
        //        btnCollectionIcon.IsSelected = scene.collect = !btnCollectionIcon.IsSelected;
        //        scene.CollectScene();
        //    };
        //}
        ///// <summary>
        ///// 加载场景控制事件
        ///// </summary>
        //void LoadEvent_ControlScene(Button btnName, Button btnFromFloor, FrameLayout bodyDiv, Scene scene)
        //{
        //    EventHandler<MouseEventArgs> upEvent = (sender, e) => {
        //        DriverLayer.Control.Ins.ControlScene(scene);
        //        string msg = scene.name + Language.StringByID(StringId.AlreadyOpened);
        //        new PublicAssmebly().TipMsgAutoClose(msg, false);
        //    };
        //    btnName.MouseUpEventHandler = upEvent;
        //    btnFromFloor.MouseUpEventHandler = upEvent;
        //    bodyDiv.MouseUpEventHandler = upEvent;
        //}
 
 
 
        /// <summary>
        /// 住宅列表点击事件
        /// </summary>
        void LoadDialog_ChangeFloor()
        {
            string nowSelectId = null;
            btnFloor.MouseUpEventHandler += (sender, e) =>
            {
                //显示下拉列表
                var form = new FloorRoomSelectPopupView();
                form.ShowDeviceFunctionView(btnFloor, this.functionList, (selectId, listFunc) =>
                {
                    nowSelectId = selectId;
                    //重新加载界面
                    ShowFunctionRow(listFunc);
                }, nowSelectId);
            };
        }
    }
}