黄学彪
2020-01-17 4b378188ce972df432b23d9cb73babb6cc0679c6
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
using System;
using Shared.Common;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DoorLock
{
    public class UserDoorLockPage : DoorLockCommonLayout, ZigBee.Common.IStatus
    {
        /// <summary>
        ///  构造函数
        /// </summary>
        /// <param name="room"></param>
        /// <param name="doorLock"></param>
        public UserDoorLockPage(Shared.Common.Room room, DeviceUI doorLock)
        {
            this.doorLock = doorLock.CommonDevice as ZigBee.Device.DoorLock;
            currentRoom = room;
            deviceUI = doorLock;
            BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor;
            ZigBee.Device.ZbGateway.StatusList.Add(this);
        }
 
        #region  变量申明
        /// <summary>
        /// 当前门锁
        /// </summary>
        ZigBee.Device.DoorLock doorLock;
        /// <summary>
        /// 底部布局
        /// </summary>
        FrameLayout bottomFrameLayout;
        /// <summary>
        /// 当前房间
        /// </summary>
        Shared.Common.Room currentRoom;
        /// <summary>
        /// 设备UI对象
        /// </summary>
        DeviceUI deviceUI;
        /// <summary>
        /// 设置二次验证Action
        /// </summary>
        Action action;
        /// <summary>
        /// 中部布局中门锁名称显示
        /// </summary>
        Button btnDoorLockTitle;
        #endregion
 
        /// <summary>
        /// UI显示 
        /// </summary>
        public void Show()
        {
            this.TopFrameLayout(this, ""); 
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
                RemoveFromParent();
            };
            this.btnBack.MouseUpEventHandler += eHandlerBack;
            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
 
            this.MidFrameLayout(this);
            var btnShare = new Button
            {
                X = Application.GetRealWidth(850 - 116),
                Height = Application.GetRealHeight(69),
                Width = Application.GetRealWidth(0),
            };
            this.titleFrameLayout.AddChidren(btnShare);
 
            var btnFuncSetFrameLayout = new FrameLayout
            {
                X = Application.GetRealWidth(850 - 116),
                Height = Application.GetRealHeight(69),
                Width = Application.GetRealWidth(69 * 2 + 58),
            };
            this.titleFrameLayout.AddChidren(btnFuncSetFrameLayout);
 
            var btnFuncSet = new Button
            {
                X = Application.GetRealWidth(103),
                Height = Application.GetRealHeight(69),
                Width = Application.GetRealWidth(69),
                UnSelectedImagePath = "DoorLock/SettingIcon.png",
            };
            btnFuncSetFrameLayout.AddChidren(btnFuncSet);
            EventHandler<MouseEventArgs> btnFuncSetHander = (sender, e) =>
            {
                var functionSetting = new Shared.Phone.UserCenter.DoorLock.FunctionSetting(doorLock);
                Shared.Phone.UserView.HomePage.Instance.AddChidren(functionSetting);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                functionSetting.Show();
                functionSetting.devicNameAction += (deviceRename) =>
                {
                    if (!string.IsNullOrEmpty(deviceRename))
                    {
                        btnDoorLockTitle.Text = deviceRename;
                        //改房间
                        Shared.Common.Room.CurrentRoom.ChangedRoom(deviceUI.CommonDevice, currentRoom.Id);
                        deviceUI.CommonDevice.ReSave();
                    }
                };
            };
            btnFuncSetFrameLayout.MouseDownEventHandler += btnFuncSetHander;
            btnFuncSet.MouseDownEventHandler += btnFuncSetHander;
 
            MidFrameLayoutContent();
        }
        /// <summary>
        /// 中部布局
        /// </summary>
        public void MidFrameLayoutContent()
        {
            #region UI
            var midTopFrameLayout = new FrameLayout()
            {
                X = Application.GetRealWidth(58),
                Y = Application.GetRealHeight(115),
                Height = Application.GetRealHeight(1238),
                Width = Application.GetRealWidth(965),
                BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                Radius = 6,
            };
            this.midFrameLayout.AddChidren(midTopFrameLayout);
 
            btnDoorLockTitle = new Button()
            {
                Width = Application.GetRealWidth(250),
                Height = Application.GetRealHeight(60),
                X = Application.GetRealWidth(372),
                Y = Application.GetRealHeight(46),
                TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                TextSize = 15,
                TextAlignment = TextAlignment.Center,
                IsBold = true,
            };
            midTopFrameLayout.AddChidren(btnDoorLockTitle);
            //获取Mac名字 
            btnDoorLockTitle.Text = Common.LocalDevice.Current.GetDeviceMacName(doorLock);
 
            var btnRecordFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(69+15+46),
                Height = Application.GetRealHeight(69+46 * 2),
                X = Application.GetRealWidth(752-46), 
             };
            midTopFrameLayout.AddChidren(btnRecordFrameLayout);
 
            var btnRecord = new Button()
            {
                Width = Application.GetRealWidth(69),
                Height = Application.GetRealHeight(69),
                X = Application.GetRealWidth(46),
                Y = Application.GetRealHeight(46),
                UnSelectedImagePath = "DoorLock/RecordIcon.png",
            };
            btnRecordFrameLayout.AddChidren(btnRecord);
            EventHandler<MouseEventArgs> handerRecord = (sender, e) =>
            {
                //历史记录 ----   stan
                var form = new DeviceDoorLock.DoorLockHistoryLogForm();
                form.AddForm(this.doorLock.DeviceAddr);
            };
            btnRecordFrameLayout.MouseDownEventHandler += handerRecord;
            btnRecord.MouseDownEventHandler += handerRecord;
            var btnCollectFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(69+15+46),
                Height = Application.GetRealHeight(69+46*2),
                X = Application.GetRealWidth(850-15), 
             };
            midTopFrameLayout.AddChidren(btnCollectFrameLayout);
 
            var btnCollect = new Button()
            {
                Width = Application.GetRealWidth(69),
                Height = Application.GetRealHeight(69),
                X = Application.GetRealWidth(15),
                Y = Application.GetRealHeight(46),
                UnSelectedImagePath = "Item/Collection.png",
                SelectedImagePath = "Item/CollectionSelected.png"
            };
            btnCollectFrameLayout.AddChidren(btnCollect);
            var de = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == deviceUI.FileName);
            if (de == null)
            {
                btnCollect.IsSelected = false;
            }
            else
            {
                btnCollect.IsSelected = true;
            }
            EventHandler < MouseEventArgs > handerCollect = (sender, e) =>
            {
                btnCollect.IsSelected = !btnCollect.IsSelected;
                if (btnCollect.IsSelected)
                {
                    Shared.Common.Room.CurrentRoom.GetLoveRoom().AddDevice(deviceUI.FileName);//收藏
                }
                else
                {
                    Shared.Common.Room.CurrentRoom.GetLoveRoom().DeleteDevice(deviceUI.FileName); //取消收藏
                }
            };
            btnCollectFrameLayout.MouseDownEventHandler += handerCollect;
            btnCollect.MouseDownEventHandler += handerCollect;
            var btnCurrentText = new Button()
            {
                Width = Application.GetRealWidth(100),
                Height = Application.GetRealHeight(40),
                X = Application.GetRealWidth(415),
                Y = Application.GetRealHeight(118),
                Text = Language.StringByID(R.MyInternationalizationString.Current),
                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                TextSize = 10,
                TextAlignment = TextAlignment.CenterLeft,
            };
            midTopFrameLayout.AddChidren(btnCurrentText);
 
            var btnStatus = new Button()
            {
                Width = Application.GetRealWidth(200),
                Height = Application.GetRealHeight(40),
                X = btnCurrentText.Right,
                Y = Application.GetRealHeight(118),
                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                Text = Language.StringByID(R.MyInternationalizationString.CLose),
                TextSize = 10,
                TextAlignment = TextAlignment.CenterLeft,
            };
            midTopFrameLayout.AddChidren(btnStatus);
 
            var btnDoorLockPic = new Button()
            {
                Width = Application.GetRealWidth(383),
                Height = Application.GetRealHeight(343),
                X = Application.GetRealWidth(161),
                Y = Application.GetRealHeight(415),
                UnSelectedImagePath = "DoorLock/DoorLockPicClose.png",
                SelectedImagePath = "DoorLock/DooorLockPicOpen.png",
            };
            midTopFrameLayout.AddChidren(btnDoorLockPic);
 
            var btnFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(420 - 46),
                Height = Application.GetRealHeight(446),
                X = btnDoorLockPic.Right,
                Y = Application.GetRealHeight(354),
                BackgroundColor = ZigbeeColor.Current.XMWhite,
            };
            midTopFrameLayout.AddChidren(btnFrameLayout);
 
            var openFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(420),//639-35
                Height = Application.GetRealHeight(446 / 2),
                BackgroundColor = ZigbeeColor.Current.XMWhite,
            };
            btnFrameLayout.AddChidren(openFrameLayout);
 
            var closeFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(420),//639-35
                Height = Application.GetRealHeight(446 / 2),
                Y = Application.GetRealHeight(446 / 2),
                BackgroundColor = ZigbeeColor.Current.XMWhite,
            };
            btnFrameLayout.AddChidren(closeFrameLayout);
 
            var progressFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(9),//639-35
                Height = Application.GetRealHeight(446),
                X = Application.GetRealWidth(95),
                Y = Application.GetRealHeight(0),
                BackgroundColor = ZigbeeColor.Current.XMVerticalSeekBar,
            };
            btnFrameLayout.AddChidren(progressFrameLayout);
 
            var progressButton = new Button()
            {
                Width = Application.GetRealWidth(81),//639-35
                Height = Application.GetRealHeight(89),
                X = Application.GetRealWidth(58),
                Y = Application.GetRealHeight(347),
                UnSelectedImagePath = "DoorLock/UnLockButton.png",
                SelectedImagePath = "DoorLock/UnLockButton.png",
            };
            btnFrameLayout.AddChidren(progressButton);
 
            var btnDoorOpenPic = new Button()
            {
                Width = Application.GetRealWidth(81),
                Height = Application.GetRealHeight(81),
                X = Application.GetRealWidth(164),
                Y = Application.GetRealHeight(6),
                UnSelectedImagePath = "DoorLock/DoorLockOpen.png",
            };
            openFrameLayout.AddChidren(btnDoorOpenPic);
 
            var btnDoorClosePic = new Button()
            {
                Width = Application.GetRealWidth(81),
                Height = Application.GetRealHeight(81),
                X = Application.GetRealWidth(164),
                Y = Application.GetRealHeight(117),
                UnSelectedImagePath = "DoorLock/DoorLockClose.png",
            };
            closeFrameLayout.AddChidren(btnDoorClosePic);
 
            var btnCurrentTopFrameLayout = new FrameLayout()
            {
                Height = Application.GetRealHeight(50),
                Width = Application.GetRealWidth(965),
                BackgroundColor = ZigbeeColor.Current.XMBlack,
                Y = Application.GetRealHeight(1100),
            };
            midTopFrameLayout.AddChidren(btnCurrentTopFrameLayout);
 
            var btnCurrentFrameLayout = new FrameLayout()
            {
                Width = Application.GetRealWidth(965),
                Height = Application.GetRealHeight(138),
                Y = Application.GetRealHeight(1100),
                BackgroundColor = ZigbeeColor.Current.XMBlack,
                Radius = 6,
            };
            midTopFrameLayout.AddChidren(btnCurrentFrameLayout);
 
            var btnCurrentRoomPic = new Button()
            {
                Width = Application.GetRealWidth(81),
                Height = Application.GetRealHeight(81),
                X = Application.GetRealWidth(58),
                Y = Application.GetRealHeight(29),
                UnSelectedImagePath = "DoorLock/RoomPic.png",
            };
            btnCurrentFrameLayout.AddChidren(btnCurrentRoomPic);
 
            var btnCurrentRoomName = new Button()
            {
                Width = Application.GetRealWidth(172),
                Height = Application.GetRealHeight(49),
                X = Application.GetRealWidth(150),
                Y = Application.GetRealHeight(46),
                Text = currentRoom.Name,
                TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                TextSize = 12,
                TextAlignment = TextAlignment.CenterLeft,
            };
            btnCurrentFrameLayout.AddChidren(btnCurrentRoomName);
            #endregion
 
            #region 数据处理
            EventHandler<MouseEventArgs> hander1 = async (sender, e) =>
            {
                openFrameLayout.Enable = false;
                btnDoorOpenPic.Enable = false;
                if (UserCenterResourse.UserInfo.AuthorityNo != 1)
                {
                    var result = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockOperateAccess(doorLock, Shared.Common.Config.Instance.Guid);
                    if (result == false)
                    {
                        var result1 = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockUnlockAccess(doorLock, Shared.Common.Config.Instance.Guid);
                        if (result1 == true)
                        {
                            RemoteUnlockRequest(doorLock, action, progressButton, btnDoorLockPic, btnStatus, btnDoorLockTitle);
                            devicNameSecAction += (deviceRename) =>
                             {
                                 if (!string.IsNullOrEmpty(deviceRename))
                                 {
                                     btnDoorLockTitle.Text = deviceRename;
                                     //改房间
                                     Shared.Common.Room.CurrentRoom.ChangedRoom(deviceUI.CommonDevice, currentRoom.Id);
                                     deviceUI.CommonDevice.ReSave();
                                 }
                             };
                            openFrameLayout.Enable = true;
                            btnDoorOpenPic.Enable = true;
                        }
                        else
                        {
                            this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.NoAccess));
                            openFrameLayout.Enable = true;
                            btnDoorOpenPic.Enable = true;
                        }
                    }
                    else
                    {
                        this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.AccountIsFreezed));
                        openFrameLayout.Enable = true;
                        btnDoorOpenPic.Enable = true;
                    }
                }
                else
                {
                    RemoteUnlockRequest(doorLock, action, progressButton, btnDoorLockPic, btnStatus, btnDoorLockTitle);
                    devicNameSecAction += (deviceRename) =>
                     {
                         if (!string.IsNullOrEmpty(deviceRename))
                         {
                             btnDoorLockTitle.Text = deviceRename;
                             //改房间
                             Shared.Common.Room.CurrentRoom.ChangedRoom(deviceUI.CommonDevice, currentRoom.Id);
                             deviceUI.CommonDevice.ReSave();
                         }
                     };
                    openFrameLayout.Enable = true;
                    btnDoorOpenPic.Enable = true;
                }
            };
            openFrameLayout.MouseUpEventHandler += hander1;
            btnDoorOpenPic.MouseUpEventHandler += hander1;
            EventHandler<MouseEventArgs> hander2 = (sender, e) =>
            {
                btnDoorLockPic.IsSelected = false;
                progressButton.Y = Application.GetRealHeight(347);
            };
            closeFrameLayout.MouseUpEventHandler += hander2;
            btnDoorClosePic.MouseUpEventHandler += hander2;
            #endregion
        }
 
        #region  接口实现
        /// <summary>
        /// 处理变化事件 --将弃用 改用DeviceInfoChange()
        /// </summary>
        /// <returns>The changed.</returns>
        /// <param name="common">Common.</param>
        public void Changed(CommonDevice common)
        {
 
        }
        /// <summary>
        /// 处理变化事件
        /// </summary>
        /// <param name="common"></param>
        /// <param name="typeTag"></param>
        public void DeviceInfoChange(CommonDevice common, string typeTag)
        {
        }
        /// <summary>
        /// Changeds the IL ogic status.
        /// </summary>
        /// <param name="logic">Logic.</param>
        public void ChangedILogicStatus(ZigBee.Device.Logic logic)
        {
        }
        /// <summary>
        /// Changeds the IS cene status.
        /// </summary>
        /// <param name="scene">Scene.</param>
        public void ChangedISceneStatus(Scene scene)
        {
        }
        #endregion
    }
}