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
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DeviceShard
{
    /// <summary>
    /// 编辑分享设备的信息
    /// </summary>
    public class ShardDeviceMacInfoEditorForm : UserCenterCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 画面正常关闭的回调函数
        /// </summary>
        public Action<string> ActionFormClose = null;
        /// <summary>
        /// 设备对象
        /// </summary>
        private List<CommonDevice> listNewDevice = null;
        /// <summary>
        /// 获取得到了镜像信息
        /// </summary>
        private bool receiveImageInfo = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="listdevices">设备列表</param>
        public void ShowForm(List<CommonDevice> listdevices)
        {
            this.listNewDevice = listdevices;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceInfo));
 
            //初始化删除设备的界面(右上)
            //this.InitDeleteDeviceForm();
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //设备图片
            var btnpictrue = new PicViewControl(510, 320);
            btnpictrue.Gravity = Gravity.CenterHorizontal;
            btnpictrue.Y = Application.GetRealHeight(100);
            Common.LocalDevice.Current.SetRealDeviceIconToControl(btnpictrue, listNewDevice);
            bodyFrameLayout.AddChidren(btnpictrue);
 
            var listview = new VerticalScrolViewLayout();
            listview.Y = btnpictrue.Bottom + Application.GetRealHeight(100);
            listview.Height = bodyFrameLayout.Height - btnpictrue.Bottom - Application.GetRealHeight(100);
            bodyFrameLayout.AddChidren(listview);
 
            //生产商名称
            var row = new RowLayout();
            row.Height = ControlCommonResourse.ListViewRowHeight;
            listview.AddChidren(row);
            var btnManuView = new RowTopGrayView(false);
            btnManuView.TextID = R.MyInternationalizationString.uManufacturerName;
            row.AddChidren(btnManuView);
            var btnManu = new RowBottomBlackView(false);
            btnManu.Text = listNewDevice[0].ManufacturerName;
            if (string.IsNullOrEmpty(btnManu.Text) == true)
            {
                if (listNewDevice[0].DriveCode > 0)
                {
                    //虚拟设备固定使用HDL
                    btnManu.Text = "HDL";
                }
            }
            row.AddChidren(btnManu);
 
            //设备型号
            row = new RowLayout();
            row.Height = ControlCommonResourse.ListViewRowHeight;
            listview.AddChidren(row);
            var btnModelIdView = new RowTopGrayView(false);
            btnModelIdView.TextID = R.MyInternationalizationString.uModelIdentifier;
            row.AddChidren(btnModelIdView);
            var btnModelId = new RowBottomBlackView(false);
            btnModelId.Text = listNewDevice[0].ModelIdentifier;
            row.AddChidren(btnModelId);
 
            //序列号
            row = new RowLayout();
            row.Height = ControlCommonResourse.ListViewRowHeight;
            listview.AddChidren(row);
            var btnSerialView = new RowTopGrayView(false);
            btnSerialView.TextID = R.MyInternationalizationString.uSerialNumber;
            row.AddChidren(btnSerialView);
            var btnSerial = new RowBottomBlackView(false);
            btnSerial.Text = listNewDevice[0].SerialNumber;
            if (string.IsNullOrEmpty(btnSerial.Text) == true)
            {
                btnSerial.Text = listNewDevice[0].DeviceAddr;
            }
            row.AddChidren(btnSerial);
 
            //产品名称
            string caption = Language.StringByID(R.MyInternationalizationString.uProductName);
            string nameValue = Common.LocalDevice.Current.GetDeviceMacName(listNewDevice[0]);
            var btnDeviceView = new EditorNameValueRow(caption, nameValue);
            listview.AddChidren(btnDeviceView);
            btnDeviceView.InitControl();
            //请输入产品名称
            btnDeviceView.SetEmptyNameTip(Language.StringByID(R.MyInternationalizationString.uProductNameMastInput));
            //编辑产品名称
            btnDeviceView.SetDialogTitle(Language.StringByID(R.MyInternationalizationString.uEditorProductName));
            btnDeviceView.ActionNameChangedEvent += (deviceName) =>
            {
                //设备重命名然后打开新的画面
                this.DeviceReName(deviceName);
            };
 
            //只有是河东的设备的时候
            if (Common.LocalDevice.Current.IsHdlDevice(listNewDevice[0]) == true)
            {
                //添加【固件信息】行
                this.AddFirmwareVersionRow(listview);
            }
        }
 
        #endregion
 
        #region ■ 固件信息___________________________
 
        /// <summary>
        /// 添加【固件信息】行
        /// </summary>
        /// <param name="listview"></param>
        private void AddFirmwareVersionRow(VerticalScrolViewLayout listview)
        {
            //拥有200端口这个东西的时候,才会显示这一行
            var oTADevice = Common.LocalDevice.Current.GetOTADevice(listNewDevice[0].DeviceAddr);
            if (oTADevice == null || oTADevice.ImgVersion == -1)
            {
                return;
            }
 
            var statuRow = new StatuRowLayout(listview);
            //固件信息
            var btnUpview = new RowCenterView(false);
            btnUpview.TextID = R.MyInternationalizationString.uFirmwareInformation;
            statuRow.AddChidren(btnUpview);
 
            statuRow.AddRightIconControl();
 
            statuRow.MouseUpEvent += (sender, e) =>
            {
                var form = new Device.DeviceFirmwareInfoForm();
                this.AddForm(form, listNewDevice);
            };
 
            //设置设备的版本信息
            this.SetDeviceVersionInfo(oTADevice);
        }
 
        /// <summary>
        /// 设置设备的版本信息
        /// </summary>
        /// <param name="oTADevice">ota设备</param>
        private void SetDeviceVersionInfo(OTADevice oTADevice)
        {
            //打开进度条
            this.ShowProgressBar();
 
            new System.Threading.Thread(async () =>
            {
                //设置设备全部的镜像信息
                HdlDeviceImageInfoLogic.Current.SetAllImageInfoToOtaDevice(oTADevice, this.OtaImageInfoActionBack);
                int count = 5;
                while (this.receiveImageInfo == false && count > 0)
                {
                    //等待设备镜像的反馈
                    await System.Threading.Tasks.Task.Delay(300);
                    count--;
                }
                //变量还原 
                this.receiveImageInfo = false;
                //移除事件
                HdlDeviceImageInfoLogic.Current.RemoveDeviceFirmwareVersionThread(oTADevice);
 
                //关闭进度条
                this.CloseProgressBar();
            })
            { IsBackground = true }.Start();
        }
 
        /// <summary>
        /// 获取到了OTA镜像信息回调(100%特定回调)
        /// </summary>
        /// <param name="device"></param>
        /// <param name="reportData"></param>
        private void OtaImageInfoActionBack(CommonDevice device, CommonDevice.DeviceStatusReportData reportData)
        {
            this.receiveImageInfo = true;
        }
 
        #endregion
 
        #region ■ 修改名字___________________________
 
        /// <summary>
        /// 设备重命名
        /// </summary>
        /// <param name="i_deviceName">deviceName.</param>
        private async void DeviceReName(string i_deviceName)
        {
            //修改MAC名
            string deviceName = i_deviceName.Trim();
            var result = await Common.LocalDevice.Current.ReMacName(this.listNewDevice, deviceName);
            if (result == false)
            {
                return;
            }
 
            Application.RunOnMainThread(() =>
            {
                this.ActionFormClose?.Invoke(deviceName);
            });
        }
 
        #endregion
 
        #region ■ 关闭界面___________________________
 
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        {
            this.ActionFormClose = null;
            base.CloseForm();
        }
 
        #endregion
 
        #region ■ 删除界面___________________________
 
        /// <summary>
        /// 初始化删除设备的界面
        /// </summary>
        private void InitDeleteDeviceForm()
        {
            var btnIcon = new TopLayoutMostRightView();
            btnIcon.UnSelectedImagePath = "Item/More.png";
            btnIcon.SelectedImagePath = "Item/MoreSelected.png";
            topFrameLayout.AddChidren(btnIcon);
            btnIcon.MouseUpEventHandler += ((sender, e) =>
            {
                //显示删除设备的弹窗界面
                this.ShowDeleteDeviceDialogForm();
            });
        }
 
        /// <summary>
        /// 显示删除设备的弹窗界面
        /// </summary>
        private void ShowDeleteDeviceDialogForm()
        {
            var frame = new TopRightMenuControl(this, 1);
            //删除设备
            string deviceMenu = Language.StringByID(R.MyInternationalizationString.uDeleteDevice);
            frame.AddRowMenu(deviceMenu, (obj) =>
            {
                //确认要删除该设备?{0}(删除设备后,绑定目标将消失)
                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteDeviceMsg);
                if (msg.Contains("{0}") == true)
                {
                    msg = string.Format(msg, "\r\n");
                }
                this.ShowConfirmMsg(msg, "DoDeleteDevice");
            });
        }
 
        /// <summary>
        /// 删除指定设备
        /// </summary>
        public async void DoDeleteDevice()
        {
            //开启进度条
            this.ShowProgressBar();
            //删除设备
            bool result = await Common.LocalDevice.Current.DeleteDevice(listNewDevice);
 
            this.CloseProgressBar();
 
            if (result == false)
            {
                return;
            }
 
            Application.RunOnMainThread(() =>
            {
                //关闭界面
                this.CloseForm();
                //移除设备列表界面指定的设备
                //this.LoadFormMethodByName("DeviceManagementMainForm", "RemoveDeviceFromMemory", listNewDevice);
            });
        }
        #endregion
    }
}