JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System;
using Shared;
using Shared.SimpleControl.R;
using Shared.SimpleControl;
using System.Collections.Generic;
 
namespace SmartHome.UI.SimpleControl.Phone
{
    public class LocalDeviceListPage : FrameLayout
    {
        public void Show (Action action, List<YiPanelCommon> devicelist, string name)
        {
            AddChidren (new Button {
                Height = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            });
 
            var topFrameLayout = new FrameLayout {
                Height = Application.GetRealHeight (100),
                Y = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            };
            AddChidren (topFrameLayout);
 
            var LocallistName = new Button {
                Text = name,
                TextSize = 17,
                TextColor = SkinStyle.Current.MusicTextColor,
            };
            topFrameLayout.AddChidren (LocallistName);
 
            var hdl = new Button {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = MainPage.LogoString,
            };
            //topFrameLayout.AddChidren (hdl);
 
            var back = new Button {
                Width = Application.GetRealWidth (82),
                Height = Application.GetRealHeight (89),
                X = Application.GetRealWidth (10),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "MusicIcon/HomepageBack.png",
            };
            topFrameLayout.AddChidren (back);
            back.MouseDownEventHandler += (sender, e) => {
                RemoveFromParent ();
                devicechannelnumber (name);
                AddDevice.Isbool = true;
                action ();
            };
 
            var middle = new VerticalScrolViewLayout ();
            middle.Y = topFrameLayout.Bottom;
            middle.Height = Application.GetRealHeight (1136 - 136);
            middle.BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout;
            AddChidren (middle);
 
            foreach (var device in devicelist) {
                if (Language.StringByID (MyInternationalizationString.AC) == name) {
                    device.Type = DeviceType.HVAC;
                } else if (Language.StringByID (MyInternationalizationString.FoolHeat) == name) {
                    device.Type = DeviceType.FoolHeat;
                } else if (Language.StringByID (MyInternationalizationString.MusicModel) == name) {
                    device.Type = DeviceType.MusicModel;
                } else if (Language.StringByID (MyInternationalizationString.ReshAirRead) == name) {
                    device.Type = DeviceType.FreshAir;
                }
                var deviceRowLayout = new RowLayout {
                    Height = Application.GetRealHeight (100),
                    BackgroundColor = 0xff323232,
                };
                middle.AddChidren (deviceRowLayout);
 
                var devicetypename = new Button {
                    Width = Application.GetRealWidth (200),
                    Text = device.Name,
                    TextAlignment = TextAlignment.CenterLeft,
                    X = Application.GetRealWidth (40),
                };
                deviceRowLayout.AddChidren (devicetypename);
 
                var btnCheck = new Button {
                    Width = Application.GetRealWidth (60),
                    Height = Application.GetRealHeight (59),
                    Gravity = Gravity.CenterVertical,
                    X = Application.GetRealWidth (550),
                    SelectedImagePath = "Light/CheckOn.png",
                    UnSelectedImagePath = "Light/Check.png",
                };
                deviceRowLayout.AddChidren (btnCheck);
 
                if (AddDevice.displaydevicelist.Find ((dev) => dev.Type == device.Type && dev.CommonLoopID == device.CommonLoopID) != null) {
                    btnCheck.IsSelected = true;
                }
 
                EventHandler<MouseEventArgs> deviicetypeclick = (sender, e) => {
                    btnCheck.IsSelected = !btnCheck.IsSelected;
                    if (btnCheck.IsSelected) {
                        if (null == AddDevice.displaydevicelist.Find ((dev) => dev.Type == device.Type && dev.CommonLoopID == device.CommonLoopID)) {
                            AddDevice.displaydevicelist.Add (device);
                        }
                    } else {
                        AddDevice.displaydevicelist.RemoveAll ((dev) => dev.Type == device.Type && dev.CommonLoopID == device.CommonLoopID);
                    }
                };
                deviceRowLayout.MouseUpEventHandler += deviicetypeclick;
                devicetypename.MouseUpEventHandler += deviicetypeclick;
                btnCheck.MouseUpEventHandler += deviicetypeclick;
 
            }
 
        }
 
        void devicechannelnumber (string name)
        {
            int intvalue = 0;
            if (Language.StringByID (MyInternationalizationString.Lights) == name) {
                intvalue = 64;
            } else if (Language.StringByID (MyInternationalizationString.Curtains) == name) {
                intvalue = 8;
            } else if (Language.StringByID (MyInternationalizationString.AC) == name) {
                intvalue = 8;
            } else if (Language.StringByID (MyInternationalizationString.MusicModel) == name) {
                intvalue = 8;
            } else if (Language.StringByID (MyInternationalizationString.FoolHeat) == name) {
                intvalue = 8;
            } else if (Language.StringByID (MyInternationalizationString.ReshAirRead) == name) {
                intvalue = 8;
            }
 
            foreach (var device in AddDevice.displaydevicelist) {
                if (device.channelnumber == 0) {
                    for (int i = 1; i < intvalue; i++) {
                        var number = AddDevice.displaydevicelist.Find ((dev) => { return (dev.channelnumber != 0 && dev.channelnumber == (byte)i); });
                        if (number == null) {
                            device.channelnumber = (byte)i;
                            break;
                        }
                    }
                }
            }
        }
    }
}