wxr
2024-06-07 56da43f1e25a191cd83fb91c5756f19ef7431bb0
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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
using System;
using System.Collections.Generic;
using Shared.SimpleControl.Phone.Music;
 
namespace Shared.SimpleControl.Phone
{
    public static class UserMiddle
    {
        //public static Button AppBtnTip = new Button () {
        //    Height = Application.GetRealHeight (140),
        //    BackgroundColor = 0xFFD7D7D7,
        //};
 
 
        public static int userMenuItemHeight {
            get {
                //if (Application.PixelScale > 1) {
                //    return Convert.ToInt32 (90 * Application.PixelScale + 20);
                //} else {
                return Convert.ToInt32 (90 * MainPage.PixelScale);
                //}
            }
        }
 
        public static FrameLayout UserPageView = new FrameLayout ();
 
        public static Button LinkStatusTip = new Button () {
            Height = Application.GetRealHeight (Convert.ToInt32 (36 * MainPage.PixelScale)),
            BackgroundColor = SkinStyle.Current.MainColor
        };
 
        public static PageLayout FavoritePageView = new PageLayout () {
            IsShowPoint = false,
        };
        public static FrameLayout FavoriteBodyView = new FrameLayout () {
            //Width = Application.GetRealWidth (Application.DesignWidth),
            //Height = Application.GetRealHeight (Application.DesignHeight)
        };
        public static UserRoom FavoriteRoom = new UserRoom () {
            //Width = Application.GetRealWidth (Application.DesignWidth),
            Height = Application.GetRealHeight (Application.DesignHeight - userMenuItemHeight)
        };
 
        public static PageLayout DevicePageView = new PageLayout () {
            IsShowPoint = false,
        };
        public static FrameLayout DeviceBodyView = new FrameLayout () {
            //Width = Application.GetRealWidth (Application.DesignWidth),
            Height = Application.GetRealHeight (Application.DesignHeight)
        };
        public static VerticalScrolViewLayout DeviceView = new VerticalScrolViewLayout () {
            Y = Application.GetRealHeight (126),
            //Width = Application.GetRealWidth (Application.DesignWidth),
            Height = Application.GetRealHeight (Application.DesignHeight - 126 - userMenuItemHeight),
        };
 
        public static PageLayout RoomPageView = new PageLayout () {
            IsShowPoint = false,
        };
        public static FrameLayout RoomBodyView = new FrameLayout () {
            Width = Application.GetRealWidth (Application.DesignWidth),
            Height = Application.GetRealHeight (Application.DesignHeight)
        };
 
        public static PageLayout SettingPageView = new PageLayout () {
            IsShowPoint = false,
        };
        public static FrameLayout SettingBodyView = new FrameLayout () {
            BackgroundColor = SkinStyle.Current.MainColor,
            Height = Application.GetRealHeight (Application.DesignHeight)
        };
        public static VerticalScrolViewLayout SettingView = new VerticalScrolViewLayout () {
            Y = Application.GetRealHeight (126),
            Width = Application.GetRealWidth (Application.DesignWidth),
            Height = Application.GetRealHeight (Application.DesignHeight - 126 - userMenuItemHeight - 90),
            BackgroundColor = SkinStyle.Current.ViewColor,
            //ScrollEnabled = true
        };
        public static Button btnVersion = new Button () {
            Y = Application.GetRealHeight (Application.DesignHeight - userMenuItemHeight - 90),
            Width = Application.GetRealWidth (Application.DesignWidth),
            Height = Application.GetRealHeight (90),
            Text = Language.StringByID (R.MyInternationalizationString.Version) + " : " + MainPage.RequestVersion,
            TextColor = SkinStyle.Current.TextColor1,
            BackgroundColor = SkinStyle.Current.ViewColor,
            Enable = false
        };
 
        public static FrameLayout UserMenuItem = new FrameLayout () {
            Y = Application.GetRealHeight (Application.DesignHeight - userMenuItemHeight),
            Height = Application.GetMinRealAverage (userMenuItemHeight+5),
            BackgroundColor = SkinStyle.Current.MainColor
        };
 
        public static PageLayout guidePageView = new PageLayout () {
            IsShowPoint = false
        };
 
        static int curPageView = 0;
        public static List<System.Threading.Thread> updateSensorhreadList = new List<System.Threading.Thread> ();
 
        public static Button btnLinkStatus = new Button () {
            Y = Application.GetRealHeight (10),
            Width = Application.GetMinRealAverage (131),
            Height = Application.GetMinRealAverage (80),
            UnSelectedImagePath = MainPage.WiFiStatus,
        };
 
        #region ---Bottom Button----
        public static Button btnFavorite = new Button () {
            Width = Application.GetRealWidth (160),
            Height = MainPage.GetDesignHeight (90),
            TextID = R.MyInternationalizationString.Favorite,
            TextColor = SkinStyle.Current.TextColor1,
            SelectedTextColor = SkinStyle.Current.SelectedColor,
            BackgroundColor = SkinStyle.Current.MainColor,
            SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton,
            UnSelectedImagePath = "Navigation/MenuFavorite.png",
            SelectedImagePath = "Navigation/MenuFavoriteOn.png",
            TextSize = 10,
            Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0),
            IsSelected = true
        };
 
        public static Button btnDevice = new Button () {
            X = Application.GetRealWidth (160),
            Width = Application.GetRealWidth (160),
            Height = MainPage.GetDesignHeight (90),
            TextID = R.MyInternationalizationString.Category,
            SelectedTextColor = SkinStyle.Current.SelectedColor,
            TextColor = SkinStyle.Current.TextColor1,
            BackgroundColor = SkinStyle.Current.MainColor,
            SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton,
            UnSelectedImagePath = "Navigation/MenuCategory.png",
            SelectedImagePath = "Navigation/MenuCategoryOn.png",
            TextSize = 10,
            Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0),
        };
        public static Button btnRoom = new Button () {
            X = Application.GetRealWidth (160 * 2),
            Width = Application.GetRealWidth (160),
            Height = MainPage.GetDesignHeight (90),
            TextID = R.MyInternationalizationString.Rooms,
            SelectedTextColor = SkinStyle.Current.SelectedColor,
            TextColor = SkinStyle.Current.TextColor1,
            BackgroundColor = SkinStyle.Current.MainColor,
            SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton,
            UnSelectedImagePath = "Navigation/MenuRoom.png",
            SelectedImagePath = "Navigation/MenuRoomOn.png",
            TextSize = 10,
            Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0),
        };
        public static Button btnSetting = new Button () {
            X = Application.GetRealWidth (160 * 3),
            Width = Application.GetRealWidth (160),
            Height = MainPage.GetDesignHeight (90),
            TextID = R.MyInternationalizationString.Setting,
            SelectedTextColor = SkinStyle.Current.SelectedColor,
            TextColor = SkinStyle.Current.TextColor1,
            BackgroundColor = SkinStyle.Current.MainColor,
            SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton,
            UnSelectedImagePath = "Navigation/MenuSettings.png",
            SelectedImagePath = "Navigation/MenuSettingsOn.png",
            TextSize = 10,
            Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0),
        };
 
        public static void SelectedBottomButton (Button btn)
        {
            if (btnFavorite.Parent == null)
                UserMenuItem.AddChidren (btnFavorite);
            if (btnDevice.Parent == null)
                UserMenuItem.AddChidren (btnDevice);
            if (btnRoom.Parent == null)
                UserMenuItem.AddChidren (btnRoom);
            if (btnSetting.Parent == null)
                UserMenuItem.AddChidren (btnSetting);
            btnFavorite.IsSelected = false;
            btnDevice.IsSelected = false;
            btnRoom.IsSelected = false;
            btnSetting.IsSelected = false;
            btn.IsSelected = true;
        }
        #endregion
 
        //public static void CleanPageView ()
        //{
        //    FavoriteRoom.RemoveAll ();
        //    FavoriteBodyView.RemoveAll ();
        //    FavoritePageView.RemoveAll ();
        //    DeviceView.RemoveAll ();
        //    DeviceBodyView.RemoveAll ();
        //    DevicePageView.RemoveAll ();
        //    RoomBodyView.RemoveAll ();
        //    RoomPageView.RemoveAll ();
        //    SettingView.RemoveAll ();
        //    SettingBodyView.RemoveAll ();
        //    SettingPageView.RemoveAll ();
        //    UserPageView.RemoveAll ();
        //}
        static void CleanPageView (FrameLayout BodyView)
        {
            FavoriteRoom.RemoveAll ();
            FavoriteBodyView.RemoveAll ();
            FavoritePageView.RemoveAll ();
            DeviceView.RemoveAll ();
            DeviceBodyView.RemoveAll ();
            DevicePageView.RemoveAll ();
            RoomBodyView.RemoveAll ();
            RoomPageView.RemoveAll ();
            SettingView.RemoveAll ();
            SettingBodyView.RemoveAll ();
            SettingPageView.RemoveAll ();
            UserPageView.RemoveAll ();
            BodyView.AddChidren (UserMenuItem);
            foreach (var thread in UserMiddle.updateSensorhreadList) {
                thread.Abort ();
                Utlis.WriteLine ("abortThread");
            }
            UserMiddle.updateSensorhreadList.Clear ();
        }
 
        /// <summary>
        /// 移除GuidePageView
        /// </summary>
        static void removeGuidePageView ()
        {
            if (guidePageView != null) {
                if (guidePageView.Parent != null) {
                    Utlis.WriteLine ("移除GuidePageView Parent 不为");
                }
                
                guidePageView.RemoveFromParent ();
               
            }
        }
        /// <summary>
        /// 是否刷新过住宅信息 2022-06-22 14:16:27
        /// </summary>
        static bool refreshHomeData = false;
 
        /// <summary>
        /// 2020-01-11 
        /// </summary>
        /// <param name="isGuide">是否Guide</param>
        /// <param name="bFromLogin">是否来自登录界面</param>
        public static void Init (bool isGuide = false, bool bFromLogin = false,bool logout = true)
        {
            if (MainPage.LoginUser == null)
                MainPage.LoginUser = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo> (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (UserInfo.GlobalRegisterFile)));
            //判断需不需要登陆,有没有登陆,或者登陆是否过期,
            if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) {
                new AccountLogin ().Show ();
                UserConfig.Instance.TipVersionBackup = UserConfig.Instance.VersionNumber;
            } else {
                //2021-03-23 移除GuidePageView
                removeGuidePageView ();
 
                //if (UserConfig.Instance.GatewayList.Count == 0) {
                //2020-01-11 Mac没绑定 是否来只登录界面
                if (bFromLogin) {
                    if (!UserConfig.Instance.CheckHomeGatewaysNotEmpty ()) {
                        #region 多次迁移住宅导致网关被移除的情况
                        if (!refreshHomeData) {
                            refreshHomeData = true;
                            //获取住宅列表
                            var revertObjCode = HttpServerRequest.Current.GetHomePager ();
                            if (revertObjCode == StateCode.SUCCESS) {
                                var mHomeLists = UserConfig.Instance.HomeLists;
 
                                if (mHomeLists != null && mHomeLists.Count > 0) {
                                    var bFind = false;
                                    foreach (var mHome in mHomeLists) {
                                        if (mHome.isBindGateway) {
                                            bFind = true;
                                            UserConfig.Instance.CurrentRegion = mHome;
                                            break;
                                        }
                                    }
 
                                    if (!bFind) {
                                        var findRoom2 = mHomeLists.Find ((obj) => obj.IsOthreShare == false);
                                        if (findRoom2 != null) {
                                            UserConfig.Instance.CurrentRegion = findRoom2;
                                        } else {
                                            UserConfig.Instance.CurrentRegion = mHomeLists [0];
                                        }
                                    }
 
                                    IO.FileUtils.DeleteAllFile ();
                                }
                                SaveUserConfig (mHomeLists);
                            }
                            return;
                        }
                        #endregion
 
 
                        UserHomePage.FrameLayoutMain.AddChidren (guidePageView);
                        var guide = new GuideAddResidence ();
                        guide.IsHideBack = logout;
                        guidePageView.AddChidren (guide);
 
                        guide.ShowHomeView (true);
                        guidePageView.PageIndex = 0;
                        MainPage.LoginUser.LastTime = DateTime.MinValue;
                        MainPage.LoginUser.SaveUserInfo ();
                        guidePageView.PageChange += (sender, e) => {
                            if (e < guidePageView.ChildrenCount - 1) {
                                guidePageView.GetChildren (guidePageView.ChildrenCount - 1).RemoveFromParent ();
                            }
                        };
                        return;
                    }
                }
                InitHomePageView ();
                //后台验证账号
                System.Threading.Tasks.Task.Run (() => {
                    try {
                        var revertObj = HttpServerRequest.Current.LoginByPassword (MainPage.LoginUser.AccountString, MainPage.LoginUser.Password);
                        if (revertObj != null) {
                            //Application.RunOnMainThread (() => {
                            if (revertObj.Code == StateCode.SUCCESS) {
                                var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes> (revertObj.Data.ToString ());
                                //MainPage.LoginUser.AllVisionRegisterDevUserNameGuid = revertData.AllVisionRegisterDevUserNameGuid;
                                MainPage.LoginUser.LoginTokenString = revertData.headerPrefix + revertData.accessToken;
                                MainPage.LoginUser.RefreshToken = revertData.refreshToken;
                                MainPage.LoginUser.LastTime = DateTime.Now;
                                MainPage.LoginUser.SaveUserInfo ();
                                //2020-01-14 验证账号通过后
                                if (!bFromLogin) {
                                    HttpServerRequest.Current.GetHomeGatewayList ();
                                }
                            } else if (!string.IsNullOrEmpty (revertObj.Code)) {
                                if (revertObj.Code != StateCode.NETWORK_ERROR && revertObj.Code != StateCode.DATA_EXCEPTION) {
                                    MainPage.LoginUser.LastTime = DateTime.Now.AddDays (-30);
                                    MainPage.LoginUser.SaveUserInfo ();
                                    //提示错误原因
                                    IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
                                    Application.RunOnMainThread (() => {
                                        new AccountLogin ().Show ();
                                    });
 
                                }
                            }
                            //});
                        }
                    } catch { } finally {
                        UserConfig.Instance.SaveUserConfig ();
                    }
                });
                if (isGuide) {
                    ShowRoomsView ();
                }
            }
            UserConfig.Instance.SaveUserConfig ();
 
           
            EventHandler<MouseEventArgs> btnLinkEvent = (sender, e) => {
                try {
                    if (SmartHome.MqttCommon.remoteMqttIsConnecting && CommonPage.IsRemote) {
                        Alert alert = new Alert ("", "Being connected remotely, do you still want to cancel and re-detect?", Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
                        alert.ResultEventHandler += (sender2, e2) => {
                            if (e2) {
                                EquipmentPublicClass.CheckLinkRemote (UserConfig.Instance.internetStatus);
                            }
                        };
                        alert.Show ();
                        //MainPage.ShowAlertOnMainThread ("Please wait, connecting remotely...");
                    } else {
                        EquipmentPublicClass.CheckLinkRemote (UserConfig.Instance.internetStatus);
                    }
                } catch { }
            };
 
            try {
                //2020-04-23 解决安卓重复弹窗问题
                if (btnLinkStatus.MouseUpEventHandler == null) {
                    btnLinkStatus.MouseUpEventHandler += btnLinkEvent;
                } else {
                    btnLinkStatus.MouseUpEventHandler -= btnLinkEvent;
                    btnLinkStatus.MouseUpEventHandler += btnLinkEvent;
                }
              
            } catch {
                //Utlis.WriteLine ("ccc");
            }
 
        }
 
 
 
 
        /// <summary>
        /// 加载用户界面
        /// </summary>
        static void InitHomePageView ()
        {
            //SystemRemote.LinkRemote ("", "", "",true);
           
            if (null != UserPageView.Parent) {
 
                CleanPageView (FavoriteBodyView);
                UserPageView.AddChidren (FavoritePageView);
                FavoritePageView.AddChidren (FavoriteBodyView);
                FavoriteBodyView.AddChidren (FavoriteRoom);
                FavoriteRoom.InitRoomView (Room.FavoriteRoom);
                SelectedBottomButton (btnFavorite);
                curPageView = 0;
 
                return;
            }
 
            Language.CurrentLanguage = "English";
#if DEBUG
            //UserConfig.Instance.SkinCode = 1;
            Language.CurrentLanguage = "English";
            //var lii = new LightLogic () { Type = DeviceType.LightRGB, LoopID = 1, DeviceID = 4, SubnetID = 42, Name = "RGB" };
            //IO.FileUtils.SaveEquipmentMessage (lii, lii.LoopID.ToString ());
            //var lii1 = new LightSwitch () { LoopID = 1, DeviceID = 2, SubnetID = 232, Name = "继电器" };
            //IO.FileUtils.SaveEquipmentMessage (lii1, lii1.LoopID.ToString ());
            ////var lii11 = new LightDimming () { LoopID = 1, DeviceID = 1, SubnetID = 232, Name = "调光器" };
            ////IO.FileUtils.SaveEquipmentMessage (lii11, lii11.LoopID.ToString ());
            ////var lii111 = new LightDimming () { LoopID = 1, DeviceID = 8, SubnetID = 232, Name = "调光器2" };
            ////IO.FileUtils.SaveEquipmentMessage (lii111, lii111.LoopID.ToString ());
 
 
            //var mCurtainModel1 = new CurtainModel () { LoopID = 1, DeviceID = 9, SubnetID = 42, Name = "窗帘" };
            //IO.FileUtils.SaveEquipmentMessage (mCurtainModel1, mCurtainModel1.LoopID.ToString ());
            ////var mCurtainModel2 = new CurtainModel () { LoopID = 2, DeviceID = 9, SubnetID = 42, Name = "窗帘2" };
            ////IO.FileUtils.SaveEquipmentMessage (mCurtainModel2, mCurtainModel2.LoopID.ToString ());
            //var mCurtainModel3 = new CurtainModel () { LoopID = 1, DeviceID = 2, SubnetID = 42, Name = "窗帘3" };
            //IO.FileUtils.SaveEquipmentMessage (mCurtainModel3, mCurtainModel3.LoopID.ToString ());
 
            //var mCurtainRoller = new CurtainRoller () { LoopID = 1, DeviceID = 88, SubnetID = 42, Name = "窗帘CurtainRoller" };
            //IO.FileUtils.SaveEquipmentMessage (mCurtainRoller, mCurtainRoller.LoopID.ToString ());
 
            //var mCurtainTrietex = new CurtainTrietex () { LoopID = 1, DeviceID = 87, SubnetID = 42, Name = "窗帘CurtainTrietex" };
            //IO.FileUtils.SaveEquipmentMessage (mCurtainTrietex, mCurtainTrietex.LoopID.ToString ());
 
 
 
 
            //var s1 = new LightEnergySocket () { LoopID = 1, DeviceID = 1, SubnetID = 44, Name = "EnergySocket" };
            //IO.FileUtils.SaveEquipmentMessage (s1, s1.LoopID.ToString ());
 
            //var s2 = new LightEnergySwitch () { LoopID = 11, DeviceID = 1, SubnetID = 44, Name = "EnergySwitch" };
            //IO.FileUtils.SaveEquipmentMessage (s2, s2.LoopID.ToString ());
 
            //InfraredMode infraredMode = new InfraredMode () { LoopID = 1, SubnetID = 100, DeviceID = 12, InfraredType = InfraredType.TV, Name = "测试电视" };
            //IO.FileUtils.SaveEquipmentMessage (infraredMode, "1");
            //ACInfrared aCInfrared = new ACInfrared () { LoopID = 1, SubnetID = 100, DeviceID = 112, Name = "空调ACInfrared" };
            //IO.FileUtils.SaveEquipmentMessage (aCInfrared, "1");
 
 
            //ACPanel mACPanel = new ACPanel () { LoopID = 1, SubnetID = 100, DeviceID = 42, Name = "空调面板ACPanel" };
            //IO.FileUtils.SaveEquipmentMessage (mACPanel, "1");
 
            //CustomAC mCustomAC = new CustomAC () { LoopID = 1, SubnetID = 99, DeviceID = 42, Name = "空调CustomAC" };
            //IO.FileUtils.SaveEquipmentMessage (mCustomAC, "1");
 
            //HVAC mHVAC = new HVAC () { LoopID = 1, SubnetID = 98, DeviceID = 42, Name = "空调HVAC" };
            //IO.FileUtils.SaveEquipmentMessage (mHVAC, "1");
 
 
            //var fanM = new FanModule () { Name = "Fan Module",SubnetID = 2,DeviceID  = 1,LoopID = 1};
            //IO.FileUtils.SaveEquipmentMessage (fanM);
            //var fanLoop1 = new FanModule () { Name = "Fan 1", SubnetID = 2, DeviceID = 1, LoopID = 1 };
            //IO.FileUtils.SaveEquipmentMessage (fanLoop1, "1");
            //var fanLoop2 = new FanModule () { Name = "Fan 2", SubnetID = 2, DeviceID = 1, LoopID = 2 };
            //IO.FileUtils.SaveEquipmentMessage (fanLoop2, "2");
            //LightEnergySocket sddd = new LightEnergySocket () { LoopID = 1, SubnetID = 100, DeviceID = 122,   Name = "测试插座" };
            //IO.FileUtils.SaveEquipmentMessage (sddd, "1");
 
            //var ud = new UniversalDevice () { LoopID = 1, SubnetID = 1, DeviceID = 100, ActionType = 2, Name = "通用开关", obj1 = 1, TargetType = 0 };
            //ud.SendBytes = new List<byte> () { 1, 0 };
            //IO.FileUtils.SaveEquipmentMessage (ud, ud.LoopID.ToString());
 
            //var ud2 = new UniversalDevice () { LoopID = 2, SubnetID = 1, DeviceID = 100, ActionType = 2, Name = "通用开关2", obj1 = 1, TargetType = 0 };
            //ud.SendBytes = new List<byte> () { 1, 255 };
            //IO.FileUtils.SaveEquipmentMessage (ud, ud.LoopID.ToString ());
 
 
            //var ud2 = new UniversalDevice () { LoopID = 2, SubnetID = 42, DeviceID = 6, ActionType = 0, Name = "Universal-2", obj1 = 1,TargetType = 1};
            //ud2.SendBytes = new List<byte> () { 2 ,0};
            //IO.FileUtils.SaveEquipmentMessage (ud2, "2");
            //var ud3 = new UniversalDevice () { LoopID = 3, SubnetID = 42, DeviceID = 6, ActionType = 1, Name = "Universal-3", obj1 = 1 ,TargetType = 2};
            //ud3.SendBytes = new List<byte> () { 3 ,0};
            //IO.FileUtils.SaveEquipmentMessage (ud3, "3");
#endif
            UserHomePage.FrameLayoutMain.AddChidren (UserPageView);
            UserHomePage.FrameLayoutMain.AddChidren (LinkStatusTip);
 
            UserPageView.AddChidren (FavoritePageView);
            FavoritePageView.AddChidren (FavoriteBodyView);
            FavoriteBodyView.AddChidren (UserMenuItem);
            FavoriteBodyView.AddChidren (FavoriteRoom);
            FavoriteRoom.InitRoomView (Room.FavoriteRoom);
 
            #region 底部导航栏
            UserMenuItem.AddChidren (btnFavorite);
            UserMenuItem.AddChidren (btnDevice);
            UserMenuItem.AddChidren (btnRoom);
            UserMenuItem.AddChidren (btnSetting);
            SelectedBottomButton (btnFavorite);
 
            btnFavorite.MouseUpEventHandler += (sender, e) => {
                CleanPageView (FavoriteBodyView);
                UserPageView.AddChidren (FavoritePageView);
                FavoritePageView.AddChidren (FavoriteBodyView);
                FavoriteBodyView.AddChidren (FavoriteRoom);
                FavoriteRoom.InitRoomView (Room.FavoriteRoom);
                SelectedBottomButton (btnFavorite);
                curPageView = 0;
                SharedMethod.SharedMethod.CurPageLayout = FavoritePageView;
            };
 
            btnDevice.MouseUpEventHandler += (sender, e) => {
                try {
                    CleanPageView (DeviceBodyView);
                    UserPageView.AddChidren (DevicePageView);
                    DevicePageView.AddChidren (DeviceBodyView);
                    DeviceBodyView.AddChidren (DeviceView);
                    SelectedBottomButton (sender as Button);
                    UserDeviceView.DeviceMode ();
                    SharedMethod.SharedMethod.CurPageLayout = DevicePageView;
                    curPageView = 1;
                } catch { } finally {
                }
            };
            btnRoom.MouseUpEventHandler += (sender, e) => {
                CleanPageView (RoomBodyView);
                UserPageView.AddChidren (RoomPageView);
                RoomPageView.AddChidren (RoomBodyView);
                UserRooms.ShowRoomList ();
                SelectedBottomButton (btnRoom);
                curPageView = 2;
                SharedMethod.SharedMethod.CurPageLayout = RoomPageView;
            };
 
            btnSetting.MouseUpEventHandler += (sender, e) => {
                CleanPageView (SettingBodyView);
                UserPageView.AddChidren (SettingPageView);
                SettingPageView.AddChidren (SettingBodyView);
                SettingBodyView.AddChidren (SettingView);
                SettingBodyView.AddChidren (btnVersion);
                SelectedBottomButton (btnSetting);
                UserSettingView.InitUserSettingView ();
                SettingPageView.PageIndex = 0;
                curPageView = 3;
                SharedMethod.SharedMethod.CurPageLayout = SettingPageView;
            };
            FavoritePageView.PageChange += (sender, e) => {
                if (e < FavoritePageView.ChildrenCount - 1) {
                    FavoritePageView.GetChildren (FavoritePageView.ChildrenCount - 1).RemoveFromParent ();
                }
            };
            SettingPageView.PageChange += (sender, e) => {
                if (e < SettingPageView.ChildrenCount - 1) {
                    SettingPageView.GetChildren (SettingPageView.ChildrenCount - 1).RemoveFromParent ();
                }
                if (e == 0) {
                    //2020-01-15 回到主界面,重置为加密
                    UserConfig.Instance.IsLocalEncrypt = true;
                }
            };
            RoomPageView.PageChange += (sender, e) => {
                if (e < RoomPageView.ChildrenCount - 1) {
                    RoomPageView.GetChildren (RoomPageView.ChildrenCount - 1).RemoveFromParent ();
                }
            };
            DevicePageView.PageChange += (sender, e) => {
                while (e < DevicePageView.ChildrenCount - 1) {
                    DevicePageView.GetChildren (DevicePageView.ChildrenCount - 1).RemoveFromParent ();
                }
                if (e == 0) {
                    DevicePageView.ScrollEnabled = true;
                }
            };
 
            #endregion
 
 
        }
 
        public static void ShowSettingView ()
        {
            CleanPageView (SettingBodyView);
            UserPageView.AddChidren (SettingPageView);
            SettingPageView.AddChidren (SettingBodyView);
            SettingBodyView.AddChidren (SettingView);
            SettingBodyView.AddChidren (btnVersion);
            SelectedBottomButton (btnSetting);
            UserSettingView.InitUserSettingView ();
        }
 
        public static void ShowRoomsView ()
        {
            CleanPageView (RoomBodyView);
            UserPageView.AddChidren (RoomPageView);
            RoomPageView.AddChidren (RoomBodyView);
            //UserMiddle.RoomBodyView.RemoveAll ();
            UserRooms.ShowRoomList ();
            SelectedBottomButton (btnRoom);
            curPageView = 2;
        }
 
        public static void ReadAllDeviceStatus (bool isRefresh = true, bool isCheckIsReadingAll = false)
        {
            if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) {
                return;
            }
            UserDeviceToLight.readAllStatus (isRefresh, isCheckIsReadingAll);
            UserDeviceToSocket.readAllStatus (isRefresh, isCheckIsReadingAll);
            UserDeviceToAC.readAllStatus (isRefresh, isCheckIsReadingAll);
            UserDeviceToFH.readAllStatus (isRefresh);
        }
 
 
 
        ///// <summary>
        ///// 登录成功后,查询刷新一次当前住宅 网关列表
        ///// 2020-01-11
        ///// </summary>
        //static void GetNowHomeGatewayAfterLoginSuccess ()
        //{
        //    var requestObj3 = new GetSingleHomeGatewayPaggerObj ();
        //    requestObj3.ReqDto.LoginAccessToken = MainPage.LoginUser.LoginTokenString;
        //    requestObj3.ReqDto.HomeId = UserConfig.Instance.CurrentRegion.Id;
        //    requestObj3.ReqDto.PageSetting.Page = 1;
        //    requestObj3.ReqDto.PageSetting.PageSize = 10;
        //    string urlHead = MainPage.RequestHttpsHost;
        //    if (requestObj3.IsOtherAccountCtrl) {
        //        urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl;
        //        requestObj3.ReqDto.LoginAccessToken = UserConfig.Instance.MasterAccountToken;
        //    }
 
        //    var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj3);
        //    var revertObj3 = MainPage.RequestHttps (API.GetSingleHomeGatewayPagger, requestJson3, urlHead);
        //    if (revertObj3.StateCode.ToUpper () == StateCode.SUCCESS) {
        //        var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGatewayResult> (revertObj3.ResponseData.ToString ());
        //        //2020-01-11
        //        UserConfig.Instance.SetNowHomeGateways (infoResult.PageData);
 
        //    }
        //}
 
        /// <summary>
        /// 保存数据 并加载页面
        /// </summary>
        /// <param name="revertRoomData"></param>
        static void SaveUserConfig (List<RegionInfoRes> revertRoomData)
        {
            UserConfig.Instance.SaveUserConfig ();
            MainPage.LoginUser.LastTime = DateTime.Now;
            if (UserConfig.Instance.CheckHomeGatewaysNotEmpty ()) {
                MainPage.LoginUser.SaveUserInfo ();
                Scene.Refresh ();
                A31MusicModel.Refresh ();
                Application.RunOnMainThread (() => {
                    Init (false, true);
                    EquipmentPublicClass.CheckLinkRemote (UserConfig.Instance.internetStatus);
                });
            } else {
                Application.RunOnMainThread (() => {
                    Init (false, true);
                });
            }
 
        }
 
    }
}