lss
2020-06-03 1c2b6fa69a7002315d4b3ecb883c255c65eceafa
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
using System;
using System.Collections.Generic;
 
namespace Shared.Phone.UserCenter.SmartSound.Forms
{
    public class SmartSoundContentForDeviceChange : EditorCommonForm
    {
      
        /// <summary>
        /// 当前选中的房间
        /// </summary>
        private SmartSound.Room CurrentRoom = null;
 
        private FrameLayout ContentLayout = null;
 
        private FrameLayout DeviceListViewFrameLayout = null;
        /// <summary>
        /// 场景 listView
        /// </summary>
        private VerticalListControl SceneListView = null;
        /// <summary>
        /// 设备 listView
        /// </summary>
        private VerticalListControl DeviceListView = null;
        /// <summary>
        /// 没有数据的时候,提示用
        /// </summary>
        private FrameLayout TipLayout = null;
 
        private List<string> TabList = new List<string>() { "灯光", "窗帘" };
 
        private int CurrentSelectIndex = 0;
 
        private int imageWith = 683;
        private int imageHeight = 392;
 
        /// <summary>
        /// 选择房间中的设备
        /// </summary>
        /// <param name="_room"> 当前房间</param>       
        public SmartSoundContentForDeviceChange(SmartSound.Room _room)
        {
            this.CurrentRoom = _room;
        }
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置标题信息
            base.SetTitleText(CurrentRoom.RoomName);
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        private void InitMiddleFrame()
        {
            //1.场景、功能导航条
            var switchContr = new SceneFunctionSwitchControl();
            this.bodyFrameLayout.AddChidren(switchContr);
            switchContr.Gravity = Gravity.CenterVertical;
            switchContr.Width = Application.GetRealWidth(650);
            switchContr.Y = Application.GetRealHeight(40);
 
 
            ContentLayout = new FrameLayout();
            this.bodyFrameLayout.AddChidren(ContentLayout);
            ContentLayout.Height = this.bodyFrameLayout.Height - switchContr.Height - Application.GetRealHeight(40);
            ContentLayout.Y = switchContr.Height + Application.GetRealHeight(40);
 
            var listTitle = new List<string>();
            listTitle.Add(Language.StringByID(R.MyInternationalizationString.uScence));
            listTitle.Add(Language.StringByID(R.MyInternationalizationString.uFunction));
 
            //设置初始值
            switchContr.SetDefultIndex(0);
 
            //选择事件
            switchContr.SelectTabEvent += (selectIndex) =>
            {
                //刷新bodyView
                if (selectIndex == 0)
                {
                    LoadSceneView();
                }
                else
                {
                    LoadFunction();
                }
            };
 
            //开始初始化
            switchContr.InitControl(listTitle);
        }
 
        /// <summary>
        /// 加载场景界面
        /// </summary>
        private void LoadSceneView()
        {
            try
            {
                //3.设备列表 ListView
                ContentLayout.RemoveAll();
 
                var tipLayout = new FrameLayout();
                ContentLayout.AddChidren(tipLayout);
                tipLayout.Visible = false;
                ShowNoFunctionTip(tipLayout);
 
                SceneListView = new VerticalListControl();
                ContentLayout.AddChidren(SceneListView);
                SceneListView.Y = Application.GetRealHeight(40);
                SceneListView.RemoveAll();
 
                for (int i = 0; i < CurrentRoom.SceneList.Count; i++)
                {
                    SmartSound.Scene scene = CurrentRoom.SceneList[i];
                    var roomRowLayout = new SceneRowLayout(this, scene, i);
                    SceneListView.AddChidren(roomRowLayout);
                    roomRowLayout.InitControl();
                }
 
                if (SceneListView.ChildrenCount == 0)
                {
                    tipLayout.Visible = true;
                }
                else
                {
                    tipLayout.Visible = false;
                }
            }
            catch (Exception ex)
            {
                string eoor = ex.Message;
            }
        }
 
        private void LoadFunction()
        {
            try
            {
                //2.功能类型选择(灯光、遮阳、空调)
                //3.设备列表 ListView
                ContentLayout.RemoveAll();
 
                FrameLayout tab_layout = new FrameLayout();
                ContentLayout.AddChidren(tab_layout);
                tab_layout.Height = Application.GetRealHeight(170);
                tab_layout.Y = 0;
 
                //添加 ListView 提示
                TipLayout = new FrameLayout();
                ContentLayout.AddChidren(TipLayout);
                TipLayout.Visible = false;
                TipLayout.Y = tab_layout.Height;
                ShowNoFunctionTip(TipLayout);
 
                Buttons.Clear();
 
                //添加功能项
                for (int i = 0; i < TabList.Count; i++)
                {
                    Button button = new Button();
                    tab_layout.AddChidren(button);
                    button.Width = Application.GetRealWidth(250);
                    button.Text = TabList[i];
                    button.X = ControlCommonResourse.XXLeft / 2 + i * button.Width;
                    button.AddTag("Index", i);
                    Buttons.Add(button);
 
                    button.MouseUpEventHandler += (sender, e) =>
                    {
                        Button btn = sender as Button;
                        CurrentSelectIndex = (int)btn.GetTagByKey("Index");
                        RefreshButtonState();
                        RefreshFunctionListView();
                    };
                }
 
                //添加 ListView
                DeviceListViewFrameLayout = new FrameLayout();
                ContentLayout.AddChidren(DeviceListViewFrameLayout);
                DeviceListViewFrameLayout.Y = tab_layout.Height;
                DeviceListViewFrameLayout.Height = ContentLayout.Height - tab_layout.Height;
 
                RefreshButtonState();
                RefreshFunctionListView();
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }
 
        private void RefreshFunctionListView()
        {
            try
            {
 
                DeviceListViewFrameLayout.RemoveAll();
 
                DeviceListView = new VerticalListControl();
                DeviceListViewFrameLayout.AddChidren(DeviceListView);
                DeviceListView.Height = DeviceListViewFrameLayout.Height;
                DeviceListView.RemoveAll();
 
                switch (CurrentSelectIndex)
                {
                    case 0:// 灯光
                        {
                            int n = 0;
                            for (int i = 0; i < CurrentRoom.DeviceList.Count; i++)
                            {
                                SmartSound.Device device = CurrentRoom.DeviceList[i];
                                //灯光
                                if (device.DeviceType == 1 || device.DeviceType == 2 || device.DeviceType == 3)
                                {
                                    var deviceRowLayout = new DeviceRowLayout(this, device, n);
                                    DeviceListView.AddChidren(deviceRowLayout);
                                    deviceRowLayout.InitControl();
                                    n++;
                                }
                            }
                        }
                        break;
                    case 1: // 窗帘
                        {
                            int n = 0;
                            for (int i = 0; i < CurrentRoom.DeviceList.Count; i++)
                            {
                                SmartSound.Device device = CurrentRoom.DeviceList[i];
                                //
                                if (device.DeviceType == 4 || device.DeviceType == 5 || device.DeviceType == 6)
                                {
                                    var deviceRowLayout = new DeviceRowLayout(this, device, n);
                                    DeviceListView.AddChidren(deviceRowLayout);
                                    deviceRowLayout.InitControl();
                                    n++;
                                }
                            }
                        }
                        break;
                }
 
                if (DeviceListView.ChildrenCount == 0)
                {
                    TipLayout.Visible = true;
                }
                else
                {
                    TipLayout.Visible = false;
                }
            }
            catch (Exception e)
            {
                string error = e.Message;
            }
        }
 
        private void ShowSetNicknameDialog(SmartSound.Scene scene, SceneRowLayout sceneRowLayout)
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputControl();
            //编辑住宅
            dialogForm.SetTitleText("自定义唤醒词");
            //请输入住宅名称
            dialogForm.SetTipText("请输入唤醒词");
            dialogForm.Text = scene.NicksName;
 
            //按下确认按钮
            dialogForm.ComfirmClickEvent += ((textValue) =>
            {
                scene.NicksName = textValue;
                string remark = scene.SceneName;
                if (scene.NicksName.Trim() != string.Empty)
                {
                    remark += "(" + scene.NicksName + ")";
                }
                sceneRowLayout.btnCaption.Text = remark;
                //画面关闭
                dialogForm.CloseDialog();               
            });
        }
 
        private void ShowSetNicknameDialog(SmartSound.Device device, DeviceRowLayout deviceRowLayout)
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputControl();
            //编辑住宅
            dialogForm.SetTitleText("自定义唤醒词");
            //请输入住宅名称
            dialogForm.SetTipText("请输入唤醒词");
            dialogForm.Text = device.NicksName;
 
            //按下确认按钮
            dialogForm.ComfirmClickEvent += ((textValue) =>
            {
                device.NicksName = textValue;
                string remark = device.DeviceName;
                if (device.NicksName.Trim() != string.Empty)
                {
                    remark += "(" + device.NicksName + ")";
                }
                deviceRowLayout.btnCaption.Text = remark;
                //画面关闭
                dialogForm.CloseDialog();
            });
        }
 
        /// <summary>
        /// 解除绑定弹窗
        /// </summary>
        private void ShowSceneDelectDialog(SmartSound.Scene scene)
        {
            this.ShowMassage(ShowMsgType.Confirm, "确认删除该控制内容?", () =>
            {
                try
                {
                    CurrentRoom.SceneList.Remove(scene);
                    LoadSceneView();
                    //SceneListView.RemoveAt(index);
 
                }
                catch (Exception e)
                {
                    string sss = e.Message;
                }
                
            }, "确认");
        }
 
        /// <summary>
        /// 解除绑定弹窗
        /// </summary>
        private void ShowDeviceDelectDialog(SmartSound.Device device)
        {
            this.ShowMassage(ShowMsgType.Confirm, "确认删除该控制内容?", () =>
            {
                try
                {
                    //DeviceListView.RemoveAt(index);
                    CurrentRoom.DeviceList.Remove(device);
                    RefreshFunctionListView();
                }
                catch (Exception e)
                {
                    string sss = e.Message;
                }
 
            }, "确认");
        }
 
        /// <summary>
        /// 提示没有功能
        /// </summary>
        private void ShowNoFunctionTip(FrameLayout layout, string tip = "没有数据哦")
        {
            var noFunction = new Button()
            {
                Y = Application.GetRealHeight(320),
                Width = Application.GetMinRealAverage(757),
                Height = Application.GetMinRealAverage(435),
                UnSelectedImagePath = "Item/NoFunction.png",
                Gravity = Gravity.CenterHorizontal
            };
            layout.AddChidren(noFunction);
 
            var noFunctionTip = new Button()
            {
                Y = noFunction.Bottom + Application.GetRealHeight(32),
                Height = Application.GetRealHeight(200),
                Width = Application.GetRealWidth(700),
                Gravity = Gravity.CenterHorizontal,
                Text = tip,
                TextColor = UserCenterColor.Current.TextGrayColor1,
                TextAlignment = TextAlignment.Center,
                IsMoreLines = true
            };
            layout.AddChidren(noFunctionTip);
        }
 
        //为了方便更新状态,存起来
        private List<Button> Buttons = new List<Button>();
        private void RefreshButtonState()
        {
            try
            {
                for (int i = 0; i < Buttons.Count; i++)
                {
                    Button btn = Buttons[i];
                    if (i == CurrentSelectIndex)
                    {
                        btn.SelectedImagePath = "Item/RoomIconBackgroundSelected.png";
                        btn.UnSelectedImagePath = "Item/RoomIconBackgroundSelected.png";
                        btn.TextColor = UserCenterColor.Current.White;
                    }
                    else
                    {
                        btn.SelectedImagePath = "Item/RoomIconBackground.png";
                        btn.UnSelectedImagePath = "Item/RoomIconBackground.png";
                        btn.TextColor = UserCenterColor.Current.TextGrayColor1;
                    }
                }
            }
            catch (Exception e)
            {
                string error = e.Message;
            }
        }
 
        #region ■ 自定义场景选择控件_____________________
 
        /// <summary>
        /// 场景列表行
        /// </summary>
        private class SceneRowLayout : RowLayoutControl
        {
            private SmartSoundContentForDeviceChange smartSoundContentForDeviceChange = null;
 
            private SmartSound.Scene scene = null;
            /// <summary>
            /// 删除按钮
            /// </summary>
            public NormalViewControl btnDelect = null;
            public NormalViewControl btnCaption = null;
            private int Index = 0;
 
            public SceneRowLayout(SmartSoundContentForDeviceChange _smartSoundContentForDeviceChange, SmartSound.Scene _scene,int _index)
            {
                smartSoundContentForDeviceChange = _smartSoundContentForDeviceChange;
                scene = _scene;
                Index = _index;
            }
 
            /// <summary>
            /// 初始化内部控件
            /// </summary>
            public void InitControl()
            {
                this.BackgroundColor = UserCenterColor.Current.White;
                this.Height = Application.GetRealHeight(175);
                string remark = scene.SceneName;
                if (scene.NicksName.Trim() != string.Empty)
                {
                    remark += " (" + scene.NicksName + ")";
                }
                btnCaption = frameTable.AddLeftCaption(remark, 2000);
 
                var nicknameIcon = frameTable.AddRightArrow();//58
                nicknameIcon.TextSize = 17;
                
                nicknameIcon.SelectedImagePath = "SmartSound/Nickname.png";
                nicknameIcon.UnSelectedImagePath = "SmartSound/Nickname.png";
                nicknameIcon.AddTag("obj", scene);
                nicknameIcon.ButtonClickEvent += (sender, e) =>
                {
                    var btn = sender as IconViewControl;
                    SmartSound.Scene tmpScene = (SmartSound.Scene)btn.GetTagByKey("obj");
                    smartSoundContentForDeviceChange.ShowSetNicknameDialog(tmpScene, this);
                };
 
                //底线
                frameTable.AddBottomLine();
 
                btnDelect = base.AddDeleteControl();
                btnDelect.Text = "删除";
                btnDelect.ButtonClickEvent += (sender, e) =>
                {
                    smartSoundContentForDeviceChange.ShowSceneDelectDialog(scene);
                };
            }
        }
        #endregion
 
        #region ■ 自定灯光选择控件_____________________
 
        /// <summary>
        /// 房间列表行
        /// </summary>
        private class DeviceRowLayout : RowLayoutControl
        {
            private SmartSoundContentForDeviceChange smartSoundContentForDeviceChange = null;
 
            private SmartSound.Device device = null;
            /// <summary>
            /// 删除按钮
            /// </summary>
            public NormalViewControl btnDelect = null;
            public NormalViewControl btnCaption = null;
            private int Index = 0;
 
            public DeviceRowLayout(SmartSoundContentForDeviceChange _smartSoundContentForDeviceChange, SmartSound.Device _device, int _index)
            {
                smartSoundContentForDeviceChange = _smartSoundContentForDeviceChange;
                device = _device;
                Index = _index;
            }
 
            /// <summary>
            /// 初始化内部控件
            /// </summary>
            public void InitControl()
            {
                this.BackgroundColor = UserCenterColor.Current.White;
                this.Height = Application.GetRealHeight(175);
                string remark = device.DeviceName;
                if (device.NicksName.Trim() != string.Empty)
                {
                    remark += " (" + device.NicksName + ")";
                }
                btnCaption = frameTable.AddLeftCaption(remark, 2000);
 
                var nicknameIcon = frameTable.AddRightArrow();//58
                nicknameIcon.TextSize = 17;
 
                nicknameIcon.SelectedImagePath = "SmartSound/Nickname.png";
                nicknameIcon.UnSelectedImagePath = "SmartSound/Nickname.png";
                nicknameIcon.AddTag("obj", device);
                nicknameIcon.ButtonClickEvent += (sender, e) =>
                {
                    var btn = sender as IconViewControl;
                    SmartSound.Device tmpDevice = (SmartSound.Device)btn.GetTagByKey("obj");
                    smartSoundContentForDeviceChange.ShowSetNicknameDialog(tmpDevice, this);
                };
 
                //底线
                frameTable.AddBottomLine();
 
                btnDelect = base.AddDeleteControl();
                btnDelect.Text = "删除";
                btnDelect.ButtonClickEvent += (sender, e) =>
                {
                    smartSoundContentForDeviceChange.ShowDeviceDelectDialog(device);
                };
            }
        }
        #endregion
    }
}