wxr
2023-08-23 96e9ff2e5a54f54cdbb6b8b2f049fdf6a837de3c
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
using System;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
 
namespace HDL_ON.UI
{
    public class ClassificaitionPublicBLL
    {
        public ClassificaitionPublicBLL()
        {
        }
 
        /// <summary>
        /// 更新功能状态
        /// </summary>
        /// <param name="updataFunction"></param>
        public void UpdataStates(Function updataFunction, FrameLayout view, VerticalScrolViewLayout scrolView, Room room = null)
        {
            if (view == null || scrolView == null || updataFunction == null)
            {
                return;
            }
            Application.RunOnMainThread((() =>
            {
                try
                {
                    if (!scrolView.ScrollEnabled)
                    {
                        return;
                    }
                    if (room != null)
                    {
                        if (!updataFunction.roomIds.Contains(room.roomId))
                        {
                            return;
                        }
                    }
                    for (int i = 0; i < scrolView.ChildrenCount; i++)
                    {
                        if (scrolView.GetChildren(i).Tag == null || scrolView.GetChildren(i).Tag.ToString() == "")
                        {
                            continue;
                        }
                        var viewTag = scrolView.GetChildren(i).Tag.ToString();
                        if (scrolView.GetChildren(i).Tag != null && viewTag == updataFunction.spk + updataFunction.sid)
                        {
                            //if ( && scrolView.GetChildren(i).Tag.ToString() == updataFunction.sid)
                            {
                                var fcView = scrolView.GetChildren(i) as FrameLayout;
                                for (int j = 0; j < fcView.ChildrenCount; j++)
                                {
                                    if (fcView.GetChildren(j).Tag == null)
                                        continue;
                                    var cTag = fcView.GetChildren(j).Tag.ToString();
                                    if (SPK.LightSpkList().Contains(updataFunction.spk) ||
                                    SPK.AcSpkList().Contains(updataFunction.spk) ||
                                    SPK.FhSpkList().Contains(updataFunction.spk) ||
                                    SPK.AirFreshSpkList().Contains(updataFunction.spk))
                                    {
                                        #region 按钮状态更新
                                        if (cTag == updataFunction.sid + "_Switch")
                                        {
                                            try
                                            {
                                                (fcView.GetChildren(j) as Button).IsSelected = updataFunction.trait_on_off.curValue.ToString() == "on";
                                            }
                                            catch (Exception ex)
                                            {
                                                MainPage.Log($"{this.GetType()} error 0 : {ex.Message}");
                                            }
                                        }
                                        #endregion
                                        #region 调光状态进度更新
                                        else if (cTag == updataFunction.sid + "_DimmerBar")
                                        {
                                            try
                                            {
                                                (fcView.GetChildren(j) as DiyImageSeekBar).Progress = Convert.ToInt32(updataFunction.GetAttrState(FunctionAttributeKey.Brightness));
                                                if (updataFunction.trait_on_off.curValue.ToString() == "on")
                                                {
                                                    (fcView.GetChildren(j) as DiyImageSeekBar).ProgressBarColor = CSS.CSS_Color.AuxiliaryColor1;
                                                }
                                                else
                                                {
                                                    (fcView.GetChildren(j) as DiyImageSeekBar).ProgressBarColor = CSS.CSS_Color.PromptingColor2;
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                MainPage.Log($"{this.GetType()} error 1 : {ex.Message}");
                                            }
                                        }
                                        #endregion
                                        #region 功能状态信息更新
                                        else if (cTag == updataFunction.spk + "_laststates_" + updataFunction.sid)
                                        {
                                            try
                                            {
                                                (fcView.GetChildren(j) as Button).IsSelected = updataFunction.trait_on_off.curValue.ToString() == "on";
                                                (fcView.GetChildren(j) as Button).Text = updataFunction.lastState;
                                            }
                                            catch (Exception ex)
                                            {
                                                MainPage.Log($"{this.GetType()} error 2 : {ex.Message}");
                                            }
                                        }
                                        #endregion
                                    }
                                    else if (SPK.CurtainSpkList().Contains(updataFunction.spk))
                                    {
                                        #region 窗帘更新
                                        var onoffString = updataFunction.GetAttrState(FunctionAttributeKey.OnOff);
                                        var percentAttr = updataFunction.GetAttribute(FunctionAttributeKey.Percent);
                                        if(percentAttr != null)
                                        {
                                            onoffString = percentAttr.curValue.ToString() == "0" ? "off" : "on";
                                        }
 
                                        if (onoffString == "stop")
                                        {
                                            return;
                                        }
                                        var percent = onoffString == "off" ? 0 : 100;
                                        if (updataFunction.GetAttributes().Contains(FunctionAttributeKey.Percent))
                                        {
                                            string percentString = updataFunction.GetAttrState(FunctionAttributeKey.Percent);
                                            int.TryParse(percentString, out percent);
                                        }
                                        if (percent == 0)
                                        {
                                            if (cTag == updataFunction.sid + "_off")
                                            {
                                                try
                                                {
                                                    (fcView.GetChildren(j) as Button).IsSelected = true;
                                                }
                                                catch { }
                                            }
                                            else
                                            {
                                                (fcView.GetChildren(j) as Button).IsSelected = false;
                                            }
                                        }
                                        else
                                        {
                                            if (cTag == updataFunction.sid + "_on")
                                            {
                                                try
                                                {
                                                    (fcView.GetChildren(j) as Button).IsSelected = true;
                                                }
                                                catch { }
                                            }
                                            else
                                            {
                                                (fcView.GetChildren(j) as Button).IsSelected = false;
                                            }
                                        }
                                        #endregion
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log($"RoomControlZone Updata States error : {ex.Message}");
                }
            }));
        }
 
        public void UpdataOnlineStatus(Function updataFunction, FrameLayout view, VerticalScrolViewLayout scrolView, Room room = null)
        {
            Application.RunOnMainThread(() =>
            {
                try
                {
                    if (view == null || scrolView == null || updataFunction == null)
                    {
                        return;
                    }
                    if (!scrolView.ScrollEnabled)
                    {
                        return;
                    }
                    if (room != null)
                    {
                        if (!updataFunction.roomIds.Contains(room.roomId))
                        {
                            return;
                        }
                    }
                    for (int i = 0; i < scrolView.ChildrenCount; i++)
                    {
                        if (scrolView.GetChildren(i).Tag == null || scrolView.GetChildren(i).Tag.ToString() == "")
                        {
                            continue;
                        }
                        var viewTag = scrolView.GetChildren(i).Tag.ToString();
                        if (scrolView.GetChildren(i).Tag != null && viewTag == updataFunction.spk + updataFunction.sid)
                        {
                            if (scrolView.GetChildren(i).GetType() == typeof(FunctionControlZone)) {
                                var fcView = scrolView.GetChildren(i) as FunctionControlZone;
                                fcView.UpdataOnline(updataFunction.isOnline());
                            }
                        }
                    }
                }catch (Exception ex)
                {
                    MainPage.Log("Function Online status error : " + ex.Message);
                }
            });
        }
 
    }
}