CrabtreeOn,印度客户定制APP,迁移2.0平台版本
JLChen
2021-02-25 c0379d078e7919c9934085da038e8e3c20dee85a
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
using System;
using System.Collections.Generic;
using Shared;
 
namespace Shared.SimpleControl.Phone
{
    /// <summary>
    /// 加载云端的设备列表
    /// </summary>
    public class AlexaSettingDevicePage : Dialog
    {
        //List<string> showList = new List<string> ();
        VerticalScrolViewLayout deviceScrolView;
        VerticalScrolViewLayout typeLayout;
        string selectedDeviceType = "All";
 
        /// <summary>
        /// 设备、场景列表
        /// </summary>
        List<TargetInfo> targetInfoList = new List<TargetInfo> ();
       
        int show = 99;
        FrameLayout bodyView;
        public AlexaSettingDevicePage (List<TargetInfo> list)
        {
            targetInfoList = new List<TargetInfo>(list);
        
            bodyView = new FrameLayout () {
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            AddChidren (bodyView);
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="action"></param>
        /// <param name="saveAction"></param>
        public void ShowPage (Action<List<TargetInfo>> saveAction)
        {
            #region ---TopView---
            var topView = new RowLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (640),
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            bodyView.AddChidren (topView);
 
            var back = new Button () {
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
            };
            topView.AddChidren (back);
            back.MouseUpEventHandler += (sender, e) => {
                this.Close ();
            };
 
            Button NameButton = new Button () {
                Width = Application.GetRealWidth (400),
                Height = Application.GetMinReal (90),
                TextID = R.MyInternationalizationString.AddNewDevice,
                //Text = MainPage.SoftTitle,
                SelectedTextColor = SkinStyle.Current.TextColor1,
                TextColor = SkinStyle.Current.TextColor1,
                Gravity = Gravity.CenterHorizontal,
                TextAlignment = TextAlignment.Center,
                TextSize = 19,
            };
            topView.AddChidren (NameButton);
 
            #endregion
            #region type view 
            var chooseTypeView = new RowLayout () {
                Y = topView.Bottom,
                Height = Application.GetRealHeight (110),
                BackgroundColor = SkinStyle.Current.ViewColor,
            };
            bodyView.AddChidren (chooseTypeView);
            Button btnEquipmentIcon = new Button () {
                Width = Application.GetRealHeight (65),
                Height = Application.GetRealHeight (65),
                UnSelectedImagePath = "Item/LogicModule.png",
                X = Application.GetRealWidth (30),
                Gravity = Gravity.CenterVertical,
            };
            chooseTypeView.AddChidren (btnEquipmentIcon);
            Button btnDrodIcon = new Button () {
                X = Application.GetRealWidth (540),
                Height = Application.GetRealHeight (46),
                Width = Application.GetRealWidth (47),
                UnSelectedImagePath = "Item/Down.png",
                SelectedImagePath = "Item/DownSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            chooseTypeView.AddChidren (btnDrodIcon);
            Button btnEquipmentType = new Button () {
                Width = Application.GetRealHeight (460),
                X = btnEquipmentIcon.Right + Application.GetRealWidth (20),
                TextAlignment = TextAlignment.CenterLeft,
                Text = Language.StringByID (R.MyInternationalizationString.All),
                TextColor = SkinStyle.Current.TextColor1,
                SelectedTextColor = SkinStyle.Current.DialogTextColor
            };
            chooseTypeView.AddChidren (btnEquipmentType);
            typeLayout = new VerticalScrolViewLayout () {
                Y = chooseTypeView.Bottom,
                Height = Application.GetRealHeight (0),
                BackgroundColor = SkinStyle.Current.ViewColor
            };
            //EventHandler<MouseEventArgs> chooseTypeMethod = (sender, e) => {
            //    if (show == 99) {//第一次需要先初始化选择设备类型界面
            //        InitEquipmentTypeView (btnEquipmentType, btnEquipmentIcon, chooseTypeView);
            //        show = 0;
            //    } else if (show == 0) {
            //        typeLayout.Height = Application.GetRealHeight (1136 - 126 - 90);
            //        chooseTypeView.BackgroundColor = SkinStyle.Current.MainColor;
            //        show = 1;
            //    } else if (show == 1) {
            //        typeLayout.Height = 0;
            //        chooseTypeView.BackgroundColor = SkinStyle.Current.ViewColor;
            //        show = 0;
            //    }
            //};
            //btnEquipmentType.MouseUpEventHandler += chooseTypeMethod;
            //btnDrodIcon.MouseUpEventHandler += chooseTypeMethod;
            //chooseTypeView.MouseUpEventHandler += chooseTypeMethod;
            #endregion
 
            deviceScrolView = new VerticalScrolViewLayout () {
                Y = chooseTypeView.Bottom,
                Height = Application.GetRealHeight (1136 - 126 - 110 - 89),
                BackgroundColor = SkinStyle.Current.ViewColor,
            };
            bodyView.AddChidren (deviceScrolView);
 
    
 
            var btnClose = new Button () {
                Height = Application.GetRealHeight (90),
                Y = deviceScrolView.Bottom,
                BackgroundColor = SkinStyle.Current.MainColor,
                //Text = "OK",
                TextID = R.MyInternationalizationString.Confrim,
                TextColor = SkinStyle.Current.TextColor1,
                TextAlignment = TextAlignment.Center,
                TextSize = 16,
            };
            bodyView.AddChidren (btnClose);
            btnClose.MouseUpEventHandler += (sender, e) => {
                saveAction?.Invoke (targetInfoList); ;
                this.Close ();
            };
 
            GetDeviceList ();
        }
 
        /// <summary>
        /// 
        /// </summary>
        void GetDeviceList () {
            System.Threading.Tasks.Task.Run (() => {
                try {
                    Application.RunOnMainThread (() => {
                        MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load));
                    });
 
                    var revertObj = HttpServerRequest.Current.GetDeviceList ();
 
                    if (revertObj.Code == StateCode.SUCCESS) {
                        var devcieFunctionRes = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieFunctionRes> (revertObj.Data.ToString ());
                        Application.RunOnMainThread (() => {
                            if (devcieFunctionRes != null && devcieFunctionRes.list != null && devcieFunctionRes.list.Count > 0) {
                                CommonConfig.Current.FunctionList = devcieFunctionRes.list;
                            } else {
                                CommonConfig.Current.FunctionList = new List<Function> ();
                            }
                            CommonConfig.Current.Save ();
                            RefreshListView ();
                        });
                    } else {
                        //提示错误
                        IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
                    }
                } catch {
 
                } finally {
                    Application.RunOnMainThread (() => {
                        MainPage.Loading.Hide ();
                    });
                }
            });
        }
 
        /// <summary>
        /// 
        /// </summary>
        void RefreshListView ()
        {
            deviceScrolView.RemoveAll ();
            foreach (Function function in CommonConfig.Current.FunctionList) {
                AddRowView (function);
            }
 
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="function"></param>
        void AddRowView (Function function) {
 
            var deviceRow = new RowLayout () {
                Height = Application.GetRealHeight (120),
            };
            deviceScrolView.AddChidren (deviceRow);
 
            var btnPoint = new Button () {
                Width = Application.GetMinRealAverage (10),
                Height = Application.GetMinRealAverage (10),
                Radius = (uint)Application.GetMinRealAverage (5),
                X = Application.GetRealWidth (50),
                Gravity = Gravity.CenterVertical,
                BackgroundColor = SkinStyle.Current.TextColor1,
                SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
            };
            deviceRow.AddChidren (btnPoint);
 
            Button btnEquipment = new Button () {
                X = btnPoint.Right + Application.GetRealWidth (30),
                Width = Application.GetRealWidth (310),
                TextAlignment = TextAlignment.CenterLeft,
                SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
                SelectedTextColor = SkinStyle.Current.DialogTextColor,
                TextColor = SkinStyle.Current.TextColor1,
                Text = function.name,
                Tag = function.deviceId,
            };
            deviceRow.AddChidren (btnEquipment);
 
            //if (selectedDeviceType != "Scene") {
            //    //2020-01-10 隐藏修改按钮
            //    //return;
            //    var btnEdit = new Button () {
            //        X = btnEquipment.Right + Application.GetRealWidth (80),
            //        Width = Application.GetMinRealAverage (75),
            //        Height = Application.GetMinRealAverage (72),
            //        Gravity = Gravity.CenterVertical,
            //        UnSelectedImagePath = "CrabtreeAdd/Edit.png",
            //        SelectedImagePath = "CrabtreeAdd/EditOn.png",
            //    };
            //    deviceRow.AddChidren (btnEdit);
 
            //    btnEdit.MouseUpEventHandler += (sd, ds) => {
            //        //Action successAction = () => {
            //        //    GenericDialog.Current.RefreshRemark (commonDevice);
            //        //    if (!roomDeviceFilePathList.Contains (filePath)) {
            //        //        roomDeviceFilePathList.Add (filePath);
            //        //    }
            //        //};
            //        //GenericDialog.Current.ShowModifyRemarksDialog (commonDevice, commonBytes, btnEquipment, successAction);
            //    };
            //}
 
            var btnChoose = new Button () {
                X = Application.GetRealWidth (472 + 80),
                Width = Application.GetMinRealAverage (75),
                Height = Application.GetMinRealAverage (72),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "CrabtreeAdd/Choose.png",
                SelectedImagePath = "CrabtreeAdd/ChooseOn.png",
                
            };
            
            deviceRow.AddChidren (btnChoose);
 
            var sceneData = targetInfoList.Find ((obj) => obj.targetId == function.deviceId);
            btnChoose.IsSelected = sceneData != null;
 
 
            btnChoose.MouseUpEventHandler += (sendere, ee) => {
                btnChoose.IsSelected = !btnChoose.IsSelected;
                if (btnChoose.IsSelected) {
                    var sceneData = targetInfoList.Find ((obj) => obj.targetId == function.deviceId);
                    if (sceneData == null) {
                        targetInfoList.Add (new TargetInfo () {
                            targetId = function.deviceId,
                            targetName = function.name,
                            isDevice = true
                        });
                    }
 
                } else {
                    var sceneData = targetInfoList.Find ((obj) => obj.targetId == function.deviceId);
                    if (sceneData != null) {
                        targetInfoList.Remove (sceneData);
                    }
                }
            };
        }
 
       
 
        void InitEquipmentTypeView (Button btnEquipmentType, Button btnEquipmentIcon, RowLayout chooseTypeView)
        {
            bodyView.AddChidren (typeLayout);
 
            //下拉列表的数据源(选项为设备类型有关)
            List<string> typeTemp = new List<string>{
                Language.StringByID(R.MyInternationalizationString.All),
            };
 
            foreach (string typeName in typeTemp) {
                var dialogRow = new RowLayout () {
                    Height = Application.GetRealHeight (110),
                };
                typeLayout.AddChidren (dialogRow);
                var btnPoint = new Button () {
                    Width = Application.GetMinRealAverage (10),
                    Height = Application.GetMinRealAverage (10),
                    Radius = (uint)Application.GetMinRealAverage (5),
                    X = Application.GetRealWidth (70),
                    Gravity = Gravity.CenterVertical,
                    BackgroundColor = SkinStyle.Current.TextColor1,
                    SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
                };
                dialogRow.AddChidren (btnPoint);
 
                Button btnTypeName = new Button () {
                    Width = Application.GetRealHeight (400),
                    X = btnPoint.Right + Application.GetRealWidth (30),
                    Text = typeName,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = SkinStyle.Current.TextColor1
                };
                dialogRow.AddChidren (btnTypeName);
                EventHandler<MouseEventArgs> typeEvent = (sender1, e1) => {
                    typeLayout.Height = 0;
                    btnEquipmentType.Text = typeName;
                    //if (typeName == Language.StringByID (R.MyInternationalizationString.Lights)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "Item/Light.png";
                    //    selectedDeviceType = "Light";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Curtains)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "Curtain/Curtain.png";
                    //    selectedDeviceType = "Curtain";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.AC)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "AC/AC.png";
                    //    selectedDeviceType = "AC";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.FoolHeat)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "Item/FloorHeating.png";
                    //    selectedDeviceType = "FoolHeat";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.DryContactPanel)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "Item/DryContact.png";
                    //    selectedDeviceType = "DryContact";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.MusicModel)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "Item/Music.png";
                    //    selectedDeviceType = "Music";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.InfraredMode)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png";
                    //    selectedDeviceType = "InfraredMode";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.TV)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png";
                    //    selectedDeviceType = "InfraredMode";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.ElectricalControl)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "Light/Socket.png";
                    //    selectedDeviceType = "EC";//电器控制
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Fan)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "Fan/Fan.png";
                    //    selectedDeviceType = "Fan";
                    //    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.LogicModule)) {
                    //    //    btnEquipmentIcon.UnSelectedImagePath = "Item/PointBig.png";
                    //    //    selectedDeviceType = "LogicModule";
                    //} else
                    if (typeName == Language.StringByID (R.MyInternationalizationString.Scenes)) {
                        btnEquipmentIcon.UnSelectedImagePath = "Scene/Scene.png";
                        selectedDeviceType = "Scene";
                    }
                    //else if (typeName == Language.StringByID (R.MyInternationalizationString.UniversalDevice)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "UniversalDevice/UniversalDevice.png";
                    //    selectedDeviceType = "UniversalDevice";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Sensor)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "UniversalDevice/UniversalDevice.png";
                    //    selectedDeviceType = "Sensor";
                    //} else if (typeName == Language.StringByID (R.MyInternationalizationString.FreshAir)) {
                    //    btnEquipmentIcon.UnSelectedImagePath = "FreshAir/FreshAir.png";
                    //    selectedDeviceType = "FreshAir";
                    //}
                    else {
                        btnEquipmentIcon.UnSelectedImagePath = "Item/LogicModule.png";
                        selectedDeviceType = "All";
                    }
                    chooseTypeView.BackgroundColor = SkinStyle.Current.ViewColor;
                    GetDeviceList ();
                };
                dialogRow.MouseUpEventHandler += typeEvent;
                btnTypeName.MouseUpEventHandler += typeEvent;
            }
        }
    }
 
 
}