HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-12-31 fe3b2466c68b5db70d38e78039703add3b8b1dfe
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
using System;
using Shared.Common;
 
namespace Shared.Phone.UserCenter.DeviceBind
{
    /// <summary>
    /// 空气质量传感器的绑定多个时间设置
    /// </summary>
    public class AirQualitySensorLedBindTime : BindCommonLayout
    {
        /// 构造函数
        /// </summary>
        /// <param name="doorLock"></param>
        public AirQualitySensorLedBindTime(ZigBee.Device.TemperatureSensor sensor)
        {
            this.sensor = sensor;
        }
 
        #region 变量申明
        /// <summary>
        /// 当前空气质量传感器对象
        /// </summary>
        ZigBee.Device.TemperatureSensor sensor;
        /// <summary>
        /// 显示被绑定设备或场景的view
        /// </summary>
        VerticalFrameRefreshControl midVerticalRefreshLayout;
        /// <summary>
        /// 空数据显示布局
        /// </summary>
        FrameLayout blankFrameLayout;
        /// <summary>
        /// 列表数据是否为空
        /// </summary>
        bool isEmpty = true;
 
        #endregion
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        void InitListInfo()
        {
            System.Threading.Tasks.Task.Run(async () =>
            {
                try
                {
                    bool isLost = false;
                    for (int i = 0; i < 5; i++)
                    {
                        if (isLost)
                        {
                            continue;//只要有一条获取失败,剩下的就停止获取,防止循环后等待透传时间太长
                        }
                        var result = await sensor.ReadAirQualitySensorLedTime(i);
                        if (result != null)
                        {
                            if (result.enable == 1)
                            {
                                if (sensor.AirQualitySensorLedTimeList.ContainsKey(result.serialNum))
                                {
                                    sensor.AirQualitySensorLedTimeList[result.serialNum] = result;
                                }
                                else
                                {
                                    sensor.AirQualitySensorLedTimeList.Add(result.serialNum, result);
                                }
                            }
                            else
                            {
                                if (sensor.AirQualitySensorLedTimeList.ContainsKey(result.serialNum))
                                {
                                    sensor.AirQualitySensorLedTimeList.Remove(result.serialNum);
                                }
                            }
                        }
                        else
                        {
                            isLost = true;
                        }
                    }
                    if (isLost)
                    {
                        Application.RunOnMainThread(() =>
                  {
                      new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GetLedTimeLost), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(CommonPage.Instance);
 
                  });
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
              {
                  RefreshList();
                  midVerticalRefreshLayout.EndHeaderRefreshing();
                  CommonPage.Loading.Hide();
              });
                }
            });
        }
 
        /// <summary>
        /// 显示
        /// </summary>
        public void Show()
        {
            TopFrameLayout();
            MiddleFrameLayout();
            CommonPage.Loading.Start("");
            InitListInfo();
        }
 
        /// <summary>
        /// Top布局
        /// </summary>
        void TopFrameLayout()
        {
            this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.SetAirQualitySensorLight));
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
                RemoveFromParent();
            };
            this.btnBack.MouseUpEventHandler += eHandlerBack;
            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
 
            var btnAddFrameLayout = new FrameLayout()
            {
                X = Application.GetRealWidth(772 - 58),
                Width = Application.GetRealWidth(192),
            };
            this.titleFrameLayout.AddChidren(btnAddFrameLayout);
 
            var btnBindAdd = new Button
            {
                X = Application.GetRealWidth(62),
                Height = Application.GetMinReal(72),
                Width = Application.GetMinReal(72),
                UnSelectedImagePath = "BindPic/BindAdd.png",
            };
            btnAddFrameLayout.AddChidren(btnBindAdd);
 
            #region eHandlerAdd
            EventHandler<MouseEventArgs> eHandlerAdd = (sender, e) =>
            {
                if (sensor.AirQualitySensorLedTimeList.Count == 5)
                {
                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.LedBindFull), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(CommonPage.Instance);
                    return;
                }
                var airQualitySensorLogic = new Shared.Phone.UserCenter.DeviceBind.AirQualitySensorLogic(sensor);
                Shared.Phone.UserView.HomePage.Instance.AddChidren(airQualitySensorLogic);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                airQualitySensorLogic.Show();
                airQualitySensorLogic.refreshAction = () =>
          {
              RefreshList();
          };
            };
            btnBindAdd.MouseDownEventHandler += eHandlerAdd;
            btnAddFrameLayout.MouseDownEventHandler += eHandlerAdd;
            #endregion
        }
 
        /// <summary>
        /// Middle布局
        /// </summary>
        void MiddleFrameLayout()
        {
            this.MidFrameLayout(this);
            VerticalFrameLayout();
            BlankFrameLayout();
        }
 
        /// <summary>
        /// VerticalFrameLayout布局
        /// </summary>
        void VerticalFrameLayout()
        {
            midVerticalRefreshLayout = new VerticalFrameRefreshControl(29)
            {
                Height = this.midFrameLayout.Height + 1,
            };
            this.midFrameLayout.AddChidren(midVerticalRefreshLayout);
 
            midVerticalRefreshLayout.BeginHeaderRefreshingAction += () =>
            {
                midVerticalRefreshLayout.BeginHeaderRefreshing();
                InitListInfo();
            };
        }
 
        /// <summary>
        /// BlankFrameLayout布局
        /// </summary>
        void BlankFrameLayout()
        {
            blankFrameLayout = new FrameLayout
            {
                Height = this.midFrameLayout.Height,
            };
            this.midFrameLayout.AddChidren(blankFrameLayout);
 
            var entryStatusPic = new Button
            {
                X = Application.GetRealWidth(213),
                Y = Application.GetRealHeight(418),
                Height = Application.GetRealHeight(556),
                Width = Application.GetRealWidth(654),
                UnSelectedImagePath = "BindPic/BindEmptyPic.png",
            };
            blankFrameLayout.AddChidren(entryStatusPic);
 
            var btnPicTip = new Button
            {
                Y = Application.GetRealHeight(1020),
                Text = Language.StringByID(R.MyInternationalizationString.NoControlTargets),
                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                Gravity = Gravity.CenterHorizontal,
                TextSize = 12,
                Height = Application.GetRealHeight(49),
            };
            blankFrameLayout.AddChidren(btnPicTip);
        }
 
        /// <summary>
        /// 按键绑定表显示
        /// </summary> 
        async void RefreshList()
        {
            if (sensor.AirQualitySensorLedTimeList.Count == 0)
            {
                isEmpty = true;
            }
            else
            {
                isEmpty = false;
            }
 
            if (isEmpty)
            {
                midVerticalRefreshLayout.Height = 0;
                blankFrameLayout.Height = this.midFrameLayout.Height;
                return;
            }
            else
            {
                blankFrameLayout.Height = 0;
                midVerticalRefreshLayout.Height = this.midFrameLayout.Height;
                midVerticalRefreshLayout.RemoveAll();
 
            }
            #region 数据处理
            int currentIndex = 0;
            foreach (var key in sensor.AirQualitySensorLedTimeList.Keys)
            {
                var ledTimeData = sensor.AirQualitySensorLedTimeList[key];
                var rowLayout = new RowLayoutControl(midVerticalRefreshLayout.rowSpace / 2);
                rowLayout.BackgroundColor = ZigbeeColor.Current.XMWhite;
                midVerticalRefreshLayout.AddChidren2(rowLayout);
                rowLayout.frameTable.UseClickStatu = false;
 
                var devicePic = rowLayout.frameTable.AddLeftIcon();
                devicePic.Y = Application.GetRealHeight(49);
                devicePic.UnSelectedImagePath = "AirQualitySensor/LED84.png";
 
                #region 绑定数据处理
                var btnBindNameText = ledTimeData.remark;
                string sm = ledTimeData.startMin.ToString();
                string em = ledTimeData.endMin.ToString();
                if (ledTimeData.startMin < 10)
                {
                    sm = "0" + ledTimeData.startMin;
                }
                if (ledTimeData.endMin < 10)
                {
                    em = "0" + ledTimeData.endMin;
                }
                var btnTimeText = ledTimeData.startHour + ":" + sm + "-" + ledTimeData.endHour + ":" + em;
                var btnTipText = Language.StringByID(R.MyInternationalizationString.LedClose);
                if (currentIndex == sensor.AirQualitySensorLedTimeList.Count - 1)
                {
                    rowLayout.LineColor = Shared.Common.ZigbeeColor.Current.XMWhite;
                }
 
                rowLayout.frameTable.AddTopView(btnBindNameText, 410);
                rowLayout.frameTable.AddBottomView(btnTimeText, 410);
                rowLayout.frameTable.AddMostRightView(btnTipText, 410);
                rowLayout.frameTable.AddBottomLine();
 
                var btnEditor = rowLayout.AddEditorControl();
                btnEditor.ButtonClickEvent += (sender, e) =>
                {
                    var airQualitySensorLogic = new Shared.Phone.UserCenter.DeviceBind.AirQualitySensorLogic(sensor, ledTimeData);
                    Shared.Phone.UserView.HomePage.Instance.AddChidren(airQualitySensorLogic);
                    Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                    airQualitySensorLogic.Show();
                    airQualitySensorLogic.refreshAction = () =>
            {
                RefreshList();
            };
                };
 
                var btnDel = rowLayout.AddDeleteControl();
                btnDel.ButtonClickEvent += async (sender, e) =>
                 {
                     try
                     {
                         Application.RunOnMainThread(() =>
                 {
                     CommonPage.Loading.Start("");
                 });
 
                         ledTimeData.enable = 0;
                         var result = await sensor.SetAirQualitySensorLedTime(ledTimeData);
                         if (result != null && result.responseData != null)
                         {
                             if (result.responseData.status == 0)
                             {
                                 Application.RunOnMainThread(() =>
                         {
                             sensor.AirQualitySensorLedTimeList.Remove(ledTimeData.serialNum);
                             RefreshList();
                         });
                             }
                             else
                             {
                                 Application.RunOnMainThread(() =>
                         {
                             new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.RemoveFailed), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel);
                         });
                             }
                         }
                         else
                         {
                             Application.RunOnMainThread(() =>
                     {
                         new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel);
                     });
                         }
                     }
                     catch { }
                     finally
                     {
                         Application.RunOnMainThread(() =>
                 {
                     CommonPage.Loading.Hide();
                 });
                     }
                 };
                #endregion
                currentIndex++;
            }
            midVerticalRefreshLayout.AdjustTableHeight(Application.GetRealHeight(23));
 
            #endregion
        }
 
        /// <summary>
        /// 重写移除方法
        /// </summary>
        public override void RemoveFromParent()
        {
            base.RemoveFromParent();
        }
    }
}