黄学彪
2019-10-10 2ed75b8b337048e5d75e6d9ec8307633134f02fd
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
using System;
using System.Collections.Generic;
using Shared.Common;
using ZigBee.Common;
namespace Shared.Phone.Device.Room
{
    public class AddDeviceList : FrameLayout
    {
        public AddDeviceList()
        {
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
            Tag = "categoryAddScene";
        }
        public override void RemoveFromParent()
        {
            base.RemoveFromParent();
        }
        /// <summary>
        /// Show the specified room.
        /// </summary>
        /// <param name="room">Room.</param>
        public async void Show(Shared.Common.Room room)
        {
            #region topview
            var topBGView = new FrameLayout()
            {
                Height = Application.GetRealHeight(CommonPage.Navigation_Height),
                BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
            };
            AddChidren(topBGView);
            var topView = new FrameLayout()
            {
                Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y),
                Height = Application.GetRealHeight(CommonPage.Navigation_Height - CommonPage.NavigationTitle_Y),
                BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor,
            };
            AddChidren(topView);
 
            var title = new Button()
            {
                TextAlignment = TextAlignment.Center,
                Text = room.Name,
                TextSize = 20,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                Width = Application.GetRealWidth(CommonPage.AppRealWidth - 500),
                Gravity = Gravity.CenterHorizontal
            };
            topView.AddChidren(title);
 
            var back = new Device.CommonForm.BackButton() { };
            topView.AddChidren(back);
            back.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
            #endregion
            CommonPage.Loading.Start();
            //设备类型去重分类
            var dList = new List<ZigBee.Device.DeviceType>();
 
            var devices = new List<ZigBee.Device.CommonDevice> { };
            devices = LocalDevice.Current.listAllDevice;
            foreach (var device in devices)
            {
                if (dList.Contains(device.Type))
                {
                    continue;
                }
                dList.Add(device.Type);
            }
 
            CommonPage.Loading.Hide();
            if (devices == null || devices.Count == 0)
            {
                var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ConnectGWFail), Language.StringByID(R.MyInternationalizationString.Confrim));
                alert.Show();
                alert.ResultEventHandler += (sender, e) =>
                {
                    RemoveFromParent();
                };
                return;
            }
 
            #region midFL
            var midFL = new VerticalScrolViewLayout()
            {
                Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
                Y = topView.Bottom,
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
            };
            this.AddChidren(midFL);
 
            var r = new R.MyInternationalizationString();
 
            foreach (var deviceType in dList)
            {
                var deviceItemFL = new FrameLayout()
                {
                    Height = Application.GetRealHeight(170)
                };
                midFL.AddChidren(deviceItemFL);
                var deviceIMG = new Button()
                {
                    X = Application.GetRealWidth(50),
                    Width = Application.GetMinRealAverage(110),
                    Height = Application.GetMinRealAverage(110),
                    UnSelectedImagePath = DeviceUI.GetDeviceTypeUnSelectedImagePath(deviceType),
                    SelectedImagePath = DeviceUI.GetDeviceTypeSelectedImagePath(deviceType),
                    Gravity = Gravity.CenterVertical
                };
                deviceItemFL.AddChidren(deviceIMG);
 
                var deviceName = new Button()
                {
                    X = deviceIMG.Right + Application.GetRealWidth(50),
                    Width = Application.GetRealWidth(700),
                    Height = Application.GetRealHeight(110),
                    TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                    SelectedTextColor = ZigbeeColor.Current.GXCButtonBlueColor,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = 16,
                    Text = DeviceUI.GetDeviceTypeName(deviceType),
                    Gravity = Gravity.CenterVertical
                };
                deviceItemFL.AddChidren(deviceName);
                var deviceRight = new Device.CommonForm.SelectedStatuButton()
                {
                    X = Application.GetRealWidth(CommonPage.AppRealWidth - 150),
                    Width = Application.GetMinRealAverage(110),
                    Height = Application.GetMinRealAverage(110),
                    UnSelectedImagePath = "Item/Next.png",
                    SelectedImagePath = "Item/NextSelected.png",
                    Gravity = Gravity.CenterVertical
                };
                deviceItemFL.AddChidren(deviceRight);
                var line = new Button()
                {
                    Y = Application.GetRealHeight(170) - 1,
                    Height = 1,
                    BackgroundColor = ZigbeeColor.Current.GXCLineColor,
                    Tag = deviceType
                };
                deviceItemFL.AddChidren(line);
 
                //设备详细类列表
                EventHandler<MouseEventArgs> deviceHandler = (sender, e) =>
                {
                    var sameTypeList = new Room.AddDevicesSameTypeList();
                    UserView.HomePage.Instance.AddChidren(sameTypeList);
                    UserView.HomePage.Instance.PageIndex += 1;
                    sameTypeList.Show(deviceType, room);
                };
                deviceRight.MouseUpEventHandler += deviceHandler;
                deviceIMG.MouseUpEventHandler += deviceHandler;
                deviceName.MouseUpEventHandler += deviceHandler;
            }
            #endregion
        }
    }
}