HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-09-30 404cdc88627f942df7944af04ee05b9d527752d6
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DeviceShard
{
    /// <summary>
    /// 网关指定分享设备的信息画面
    /// </summary>
    public class ShardDeviceEpointInfoForm : UserCenterCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 设备名称变更的回调函数(设备名称,房间名)
        /// </summary>
        public Action<string, List<string>> ActionNameChangedEvent = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout listview = null;
        /// <summary>
        /// 新上报的设备
        /// </summary>
        private CommonDevice newDevice = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="device">设备</param>
        public void ShowForm(CommonDevice device)
        {
            this.newDevice = device;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceSettingUp));
 
            //检测设备是否拥有测试的功能
            if (Common.LocalDevice.Current.DeviceIsCanTest(device) == true)
            {
                //初始化头部右边的测试图标
                this.InitTopLayoutRightIcon();
            }
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化头部右边的测试图标
        /// </summary>
        private void InitTopLayoutRightIcon()
        {
            var btnIcon = new TopLayoutMostRightView();
            btnIcon.UnSelectedImagePath = "Item/Test.png";
            btnIcon.SelectedImagePath = "Item/TestSelected.png";
            topFrameLayout.AddChidren(btnIcon);
 
            btnIcon.MouseUpEventHandler += (sender, e) =>
            {
                //测试
                Common.LocalDevice.Current.SetTestCommand(newDevice);
            };
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        public void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //房间
            List<string> listRoomName = Common.Room.CurrentRoom.GetRoomListNameByDevice(this.newDevice);
 
            //图标
            var btnImage = new IconViewControl(332);
            btnImage.Y = Application.GetRealHeight(40);
            btnImage.Gravity = Gravity.CenterHorizontal;
            //设置大图
            Common.LocalDevice.Current.SetDeviceBigIconToControl(btnImage, this.newDevice);
            bodyFrameLayout.AddChidren(btnImage);
            btnImage.MouseUpEventHandler += (sender, e) =>
            {
                //显示变更设备图标的界面
                this.ShowChangedIconForm(btnImage);
            };
 
            listview = new VerticalScrolViewLayout();
            listview.Y = btnImage.Bottom + Application.GetRealHeight(50);
            listview.Height = bodyFrameLayout.Height - btnImage.Bottom - Application.GetRealHeight(50);
            bodyFrameLayout.AddChidren(listview);
 
            //设备名称
            string caption = Language.StringByID(R.MyInternationalizationString.uDeviceName);
            string nameValue = Common.LocalDevice.Current.GetDeviceEpointName(newDevice);
            var btnDeviceView = new EditorNameValueRow(caption, nameValue);
            listview.AddChidren(btnDeviceView);
            btnDeviceView.InitControl();
            //请输入设备名称
            btnDeviceView.SetEmptyNameTip(Language.StringByID(R.MyInternationalizationString.uDeviceNameMastInput));
            //编辑设备名称
            btnDeviceView.SetDialogTitle(Language.StringByID(R.MyInternationalizationString.uEditorDeviceName));
            btnDeviceView.ActionNameChangedEvent += (deviceName) =>
            {
                //设备重命名
                this.DeviceReName(deviceName, listRoomName);
            };
 
            var statuRow = new StatuRowLayout(listview);
            //所属区域
            var btnBelongAreaView = new RowTopGrayView(false);
            btnBelongAreaView.TextID = R.MyInternationalizationString.uBelongArea;
            statuRow.AddChidren(btnBelongAreaView);
 
            var btnBelongArea = new RowBottomBlackView(false);
            btnBelongArea.Text = Common.Room.CurrentRoom.GetRoomName(listRoomName);
            statuRow.AddChidren(btnBelongArea);
            //向右图标
            statuRow.AddRightIconControl();
            statuRow.MouseUpEvent += (sender, e) =>
            {
                var form = new SelectRoomForm();
                this.AddForm(form, listRoomName);
                form.ActionSelectRoom = (list) =>
                {
                    if (list != null)
                    {
                        //变更房间
                        Common.Room.CurrentRoom.ChangedRoom(newDevice, list);
 
                        btnBelongArea.Text = Common.Room.CurrentRoom.GetRoomName(list);
                        listRoomName = list;
 
                        if (this.ActionNameChangedEvent != null)
                        {
                            string name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
                            this.ActionNameChangedEvent(name, listRoomName);
                        }
                    }
                };
            };
 
            //所属模块
            var row = new RowLayout();
            row.Height = ControlCommonResourse.ListViewRowHeight;
            listview.AddChidren(row);
 
            var btnBelongObjectView = new RowTopGrayView(false);
            btnBelongObjectView.TextID = R.MyInternationalizationString.uBelongObject;
            row.AddChidren(btnBelongObjectView);
 
            var btnBelongObject = new RowBottomBlackView(false);
            btnBelongObject.Text = Common.LocalDevice.Current.GetDeviceMacName(newDevice);
            row.AddChidren(btnBelongObject);
        }
 
        #endregion
 
        #region ■ 修改名字___________________________
 
        /// <summary>
        /// 设备重命名
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="listRoomName">Name.</param>
        private async void DeviceReName(string name, List<string> listRoomName)
        {
            //设备名称修改
            var result = await Common.LocalDevice.Current.ReName(this.newDevice, name);
            if (result == false)
            {
                return;
            }
            Application.RunOnMainThread(() =>
            {
                if (this.ActionNameChangedEvent != null)
                {
                    name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
                    this.ActionNameChangedEvent(name, listRoomName);
                }
            });
        }
 
        #endregion
 
        #region ■ 变更图片___________________________
 
        /// <summary>
        /// 显示变更设备图标的界面
        /// </summary>
        /// <param name="btnIcon"></param>
        private void ShowChangedIconForm(IconViewControl btnIcon)
        {
            var form = new Phone.Device.CommonForm.DeviceIconSelectedIMGByLocal();
            UserView.HomePage.Instance.AddChidren(form);
            UserView.HomePage.Instance.PageIndex += 1;
            form.Show();
            form.action = (unSelectedImagePath, selectedImagePath) =>
            {
                btnIcon.UnSelectedImagePath = selectedImagePath;
 
                //变更图标
                Common.LocalDevice.Current.ChangedDeviceIcon(newDevice, unSelectedImagePath);
 
                if (this.ActionNameChangedEvent != null)
                {
                    List<string> listRoomName = Common.Room.CurrentRoom.GetRoomListNameByDevice(this.newDevice);
                    string name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
                    this.ActionNameChangedEvent(name, listRoomName);
                }
            };
        }
 
        #endregion
 
        #region ■ 关闭界面___________________________
 
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        {
            this.ActionNameChangedEvent = null;
            base.CloseForm();
        }
 
        #endregion
    }
}