JLChen
2021-04-01 1ebda09d954de4409c5a7f3ba3c3ee75626ec7c0
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
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.Entity;
using HDL_ON.UI.UI2.Intelligence.Automation.LogicView;
using Shared;
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
{
    public class PirMain : FrameLayout
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public PirMain()
        {
            /// 标记界面
            Tag = "PirMain";
        }
        /// <summary>
        /// 回调
        /// </summary>
        public static Action BackAction;
        /// <summary>
        /// 添加图标Btn
        /// </summary>
        Button addDevice;
        /// <summary>
        /// 临时储存设备类型列表
        /// </summary>
        List<DeviceType> DeviceTypeList = new List<DeviceType>();
        public void Show()
        {
            #region 界面布局
            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
            PirDevice.View.TopView topView = new View.TopView();
            topView.topNameBtn.TextID = StringId.hongwaiyaokong;
            topView.topIconBtn.Visible = true;
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
               
                RemoveFromParent();
            };
 
            FrameLayout middFLayout = new FrameLayout();
            middFLayout.Y = Application.GetRealHeight(64);
            middFLayout.Height = Application.GetRealHeight(667 - 64);
            this.AddChidren(middFLayout);
 
            VerticalRefreshLayout vv = new VerticalRefreshLayout();
            middFLayout.AddChidren(vv);
            //加号图标
            addDevice = new Button
            {
                Y = Application.GetRealHeight(480),
                X = Application.GetRealWidth(293),
                Width = Application.GetRealWidth(82),
                Height = Application.GetRealWidth(84),
                UnSelectedImagePath = "PirIcon/add.png",
                Visible=false,
 
            };
            middFLayout.AddChidren(addDevice);
            if (Pir.currPir.FunctioList.Count < 10)
            {
                //10个遥控器就会隐藏添加图标
                // middFLayout.AddChidren(addDevice);
                addDevice.Visible = true;
            }
            #endregion
 
            #region 界面点击事件
            ///下拉刷新界面事件
            vv.BeginHeaderRefreshingAction += () =>
                {
                    ////关闭刷新View;
                    vv.EndHeaderRefreshing();
 
                    Method.GetControlList(this, () =>
                    {
                        Application.RunOnMainThread(() =>
                        {
                            //刷新界面
                            UIView(vv);
                        });
                    }, Pir.currPir);
 
                };
            ///设置图标点击事件
            topView.clickSetBtn.MouseUpEventHandler += (sender, e) =>
            {
 
                SetPir setPir = new SetPir();
                MainPage.BasePageView.AddChidren(setPir);
                setPir.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            ///添加遥控器图标点击事件
            addDevice.MouseUpEventHandler += (sender, e) =>
            {
                //进来不允许左滑
                MainPage.BasePageView.ScrollEnabled = false;
                View.Buttons buttons = new View.Buttons();
                buttons.AddFrameLayout(this, (if_value, view) => 
                {
                    //关闭允许左滑
                    MainPage.BasePageView.ScrollEnabled = true;
                    //1=空调;2=电视;3=风扇;4=机顶盒;5=DVD/EVD/VCD;6=投影仪;7=自定义;
                    if (if_value == 7)
                    {
                        Method method = new Method();
                        method.AddControl(this, (control) =>
                        {
                           //成功后移除;
                           view.RemoveFromParent();
                            AddButton addButton = new AddButton();
                            MainPage.BasePageView.AddChidren(addButton);
                            addButton.Show(control);
                            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                        });
                    }
                    else
                    {
                        if (if_value == 3 || if_value == 4 || if_value == 5 || if_value == 6)
                        {
                            new TipPopView().FlashingBox(Language.StringByID(StringId.zanshibuzhichigaigongneng));
                            return;
                        }
                        if (DeviceTypeList.Count == 0)
                        {
                            GetDeviceTypeList(true, () =>
                            {
                                DeviceTypeViewClick(if_value);
                               //获取成功之后移除
                               view.RemoveFromParent();
 
                            });
                        }
                        else
                        {
                            DeviceTypeViewClick(if_value);
                            view.RemoveFromParent();
                        }
 
                    }
                }, 7);
            };
            #endregion
            ///初始化界面
            UIView(vv);
        }
 
        /// <summary>
        /// 加载UI界面
        /// </summary>
        /// <param name="vv">上下滑控件</param>
        private void UIView(VerticalRefreshLayout vv)
        {
            vv.RemoveAll();
            #region 红外宝图标 版本号 名称 状态
            FrameLayout fLayout = new FrameLayout
            {
                Width = Application.GetRealWidth(375),
                Height = Application.GetRealHeight(12 + 92 + (50 * Pir.currPir.FunctioList.Count)),
            };
            vv.AddChidren(fLayout);
            View.PirView pirView = new View.PirView();
            //红外宝名称
            pirView.deviceNameBtn.Text = Pir.currPir.name;
            //红外宝当前有多少个遥控器
            pirView.geBtn.Text = Pir.currPir.FunctioList.Count.ToString();
            //红外宝是否在线-离线
            if (Pir.currPir.online)
            {
                pirView.stateIconBtn.IsSelected = true;
                pirView.stateTextBtn.IsSelected = true;
                pirView.stateTextBtn.TextID = StringId.zaixian;
            }
            else
            {
                pirView.stateIconBtn.IsSelected = false;
                pirView.stateTextBtn.IsSelected = false;
                pirView.stateTextBtn.TextID = StringId.lixian;
            }
            //标记红外宝
            pirView.clickBtn.Tag = Pir.currPir;
            //加载界面
            pirView.Show(Pir.currPir.FunctioList.Count, fLayout);
            //最后一个后面增加间隔背景
            vv.AddChidren(new FrameLayout { Height = Application.GetRealHeight(20) });
            #endregion
 
            for (int j = 0; j < Pir.currPir.FunctioList.Count; j++)
            {
                var control = Pir.currPir.FunctioList[j];
                View.ControlView controlView = new View.ControlView();
                controlView.Show(pirView.devfLayout, j);
                //遥控器名称
                controlView.nameBtn.Text = control.name;
                //遥控器存放区域
                controlView.areaBtn.Text = Intelligence.Automation.LogicMethod.GetGetRoomName(control);
                //标记遥控器
                controlView.delBtn.Tag = control;
                //删除点击事件
                controlView.delBtn.MouseUpEventHandler += (sender, e) =>
                {
                    var Function = controlView.delBtn.Tag as Entity.Function;
                    string text = Language.StringByID(StringId.shanchushebei) + Function.name + "?";
                    TipPopView tipPopView = new TipPopView();
                    tipPopView.TipBox(StringId.tip, text, (dialog) =>
                    {
                        Method.ThreadSend(new Control { deviceId=control.deviceId}, (responsePackNew) =>
                        {
                            dialog.Close();
                            var function = Pir.currPir.FunctioList.Find((c) => c.sid == Function.sid);
                            if (function != null)
                            {
                                Pir.currPir.FunctioList.Remove(Function);
                            }
                            UIView(vv);
                            if (Pir.currPir.FunctioList.Count < 10)
                            {
                                //10个遥控器就会隐藏添加图标
                                // middFLayout.AddChidren(addDevice);
                                addDevice.Visible = true;
                            }
                        }, "删除", "dialog", null, dialog);
 
                    }, () => { }, false);
                };
                //view点击事件
                controlView.clickBtn.MouseUpEventHandler += (sender, e) =>
                {
                    EditControl editControl = new EditControl();
                    MainPage.BasePageView.AddChidren(editControl);
                    editControl.Show(control,(device) =>
                    {
                        //回调更新名字/区域
                        controlView.nameBtn.Text = device.name;
                        controlView.areaBtn.Text = Intelligence.Automation.LogicMethod.GetGetRoomName(device);
 
                    });
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                };
                if (j == Pir.currPir.FunctioList.Count - 1)
                {
                    //最后改变一个线的颜色
                    controlView.line1Btn.BackgroundColor = CSS.CSS_Color.viewTranslucence;
                    controlView.funControlRow.LineColor = CSS.CSS_Color.viewTranslucence;
                }
 
 
            }
        }
        /// <summary>
        /// 设备进入下一级方法
        /// </summary>
        /// <param name="if_value">控件索引值</param>
        private void DeviceTypeViewClick(int if_value)
        {
          
            var strings = View.Buttons.GetTypeString(if_value).Split('-');
            var jobDeviceType = DeviceTypeList.Find((c) => c.deviceType == strings[0]);
            if (jobDeviceType == null)
            {
                return;
            }
            GetBrandList(jobDeviceType.id, (brandList) =>
            {
                Application.RunOnMainThread(() =>
                {
                    BrandList brandObj = new BrandList();
                    brandObj.Show(brandList, strings[1]);
                });
 
            });
 
        }
        /// <summary>
        /// 读取红外设备类型列表
        /// </summary>
        /// <param name="tag">表示要不要提示错误信息(true=提示)</param>
        /// <param name="action">回调函数</param>
        public void GetDeviceTypeList(bool tag, Action action)
        {
            PirSend.GetDeviceTypesList(this, (responsePackNew) =>
            {
 
                if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                {
                    //清空之前数据
                    DeviceTypeList.Clear();
                    try
                    {
                        var jArray = Newtonsoft.Json.Linq.JArray.Parse(responsePackNew.Data.ToString());
                        for (int a = 0; a < jArray.Count; a++)
                        {
                            var jay = jArray[a];
                            var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
                            var objDeviceType = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceType>(str);
                            if (objDeviceType != null)
                            {
                                if (null == DeviceTypeList.Find((c) => c.id == objDeviceType.id))
                                {
                                    DeviceTypeList.Add(objDeviceType);
                                }
                            }
                        }
                        action();
                    }
                    catch
                    {
 
                    }
                }
                else
                {
                    if (tag)
                    {
                        Method method = new Method();
                        method.ErrorShow(responsePackNew, "");
                    }
                }
            }, "", "设备类型列表");
        }
        /// <summary>
        /// 读取红外设备类型的品牌列表
        /// </summary>
        public void GetBrandList(string id, Action<List<Brand>> actionBrand)
        {
            List<Brand> brandList = new List<Brand>();
            PirSend.GetDeviceTypesList(this, (responsePackNew) =>
            {
 
                if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                {
                    //清空之前数据
                    brandList.Clear();
                    try
                    {
                        var jArray = Newtonsoft.Json.Linq.JArray.Parse(responsePackNew.Data.ToString());
                        for (int a = 0; a < jArray.Count; a++)
                        {
                            var jay = jArray[a];
                            var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
                            var brand = Newtonsoft.Json.JsonConvert.DeserializeObject<Brand>(str);
                            if (brand != null)
                            {
                                if (null == brandList.Find((c) => c.id == brand.id))
                                {
                                    brandList.Add(brand);
                                }
                            }
                        }
                    }
                    catch { }
                    finally
                    {
                        Application.RunOnMainThread(() =>
                        {
                            actionBrand(brandList);
                        });
                    }
                }
                else
                {
                    Method method = new Method();
                    method.ErrorShow(responsePackNew, "");
                }
            }, id, "品牌列表");
        }
        /// <summary>
        /// 移除界面
        /// </summary>
        public override void RemoveFromParent()
        {
            BackAction();
            base.RemoveFromParent();
        }
 
    }
 
}