黄学彪
2019-10-18 97e259d966cb5cb5d73c105d5dbaadcc1f920614
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Device
{
    /// <summary>
    /// 设备固件信息界面
    /// </summary>
    public class DeviceFirmwareInfoForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 设备mac地址
        /// </summary>
        private string deviceMac = null;
        /// <summary>
        /// 固件信息
        /// </summary>
        private FirmwareVersionInfo deviceFirmware = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_deviceMac">设备mac地址</param>
        public void ShowForm(string i_deviceMac)
        {
            if (deviceMac != null && deviceMac != i_deviceMac)
            {
                //不是同一个东西
                return;
            }
            this.deviceMac = i_deviceMac;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uFirmwareUpdate));
 
            //初始化中部控件
            this.InitMiddleFrame();
 
            //历史版本
            this.InitTopRightMenu();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            var oTADevice = Common.LocalDevice.Current.GetOTADevice(deviceMac);
            //获取设备最新版本
            this.deviceFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.ZigbeeDevice,
                oTADevice.HwVersion.ToString(),
                oTADevice.ImgTypeId.ToString(),
                oTADevice.ImgVersion);
 
            if (deviceFirmware != null && deviceFirmware.FirmwareVersion > oTADevice.ImgVersion)
            {
                //拥有新版本
                this.InitControlByNewVersion();
            }
            else
            {
                //没有新版本
                this.InitControlByNotNewVersion();
            }
        }
 
        #endregion
 
        #region ■ 右上角菜单_________________________
 
        /// <summary>
        /// 初始化右上角菜单
        /// </summary>
        private void InitTopRightMenu()
        {
            var btnIcon = new MostRightIconControl(69, 69);
            btnIcon.UnSelectedImagePath = "Item/More.png";
            topFrameLayout.AddChidren(btnIcon);
            btnIcon.InitControl();
            btnIcon.ButtonClickEvent += ((sender, e) =>
            {
                //显示右上角菜单界面
                this.ShowTopRightMenu();
            });
        }
 
        /// <summary>
        /// 显示右上角菜单界面
        /// </summary>
        private void ShowTopRightMenu()
        {
            var frame = new TopRightMenuControl(1);
            //历史版本
            var deviceMenu = Language.StringByID(R.MyInternationalizationString.uHistoryVersion);
            frame.AddRowMenu(deviceMenu, "", "", () =>
            {
                var form = new DeviceHistoryFirmwareVersionForm();
                form.AddForm(deviceMac);
                form.SelectFirmwareInfoEvent += (info) =>
                {
                    this.deviceFirmware = info;
                    //拥有新版本
                    this.InitControlByNewVersion();
                };
            });
        }
 
        #endregion
 
        #region ■ 拥有新版本_________________________
 
        /// <summary>
        /// 拥有新版本
        /// </summary>
        private void InitControlByNewVersion()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var oTADevice = Common.LocalDevice.Current.GetOTADevice(deviceMac);
 
            //升级
            var btnUpdate = new BottomClickButton();
            btnUpdate.TextID = R.MyInternationalizationString.uLevelUp;
            bodyFrameLayout.AddChidren(btnUpdate);
            btnUpdate.ButtonClickEvent += (sender, e) =>
            {
                //界面右划不可
                UserView.HomePage.Instance.ScrollEnabled = false;
 
                var form = new DeviceFirmwareUpdateForm();
                form.AddForm(oTADevice, deviceFirmware);
                //完成升级事件
                form.FinishUpdateEvent += (() =>
                {
                    //初始化中部控件
                    this.InitMiddleFrame();
                    //界面右划可
                    UserView.HomePage.Instance.ScrollEnabled = true;
                });
            };
 
            var frameWhiteBack = new FrameLayout();
            frameWhiteBack.Height = Application.GetRealHeight(286);
            frameWhiteBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameWhiteBack);
 
            //当前固件版本
            var frameNow = new FrameRowControl();
            frameNow.UseClickStatu = false;
            frameNow.Y = Application.GetRealHeight(20);
            frameWhiteBack.AddChidren(frameNow);
            frameNow.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNowFirmwareVersion), 500);
            frameNow.AddMostRightView(Common.LocalDevice.Current.AppendVersion(oTADevice.ImgVersion), 500);
            frameNow.AddBottomLine();
 
            //最新固件版本
            var frameNew = new FrameRowControl();
            frameNew.UseClickStatu = false;
            frameNew.Y = frameNow.Bottom + Application.GetRealHeight(12);
            frameWhiteBack.AddChidren(frameNew);
            frameNew.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNewFirmwareVersion), 500);
            frameNew.AddMostRightView(Common.LocalDevice.Current.AppendVersion(deviceFirmware.FirmwareVersion), 500);
            frameNew.AddBottomLine();
 
            //添加固件介绍行
            int maxHeight = btnUpdate.Y - ControlCommonResourse.BottomButtonAndListViewSpace - frameNew.Bottom;
            this.AddUpdateContent(deviceFirmware, maxHeight, frameNew.Bottom);
        }
 
        #endregion
 
        #region ■ 没有新版本_________________________
 
        /// <summary>
        /// 没有新版本
        /// </summary>
        private void InitControlByNotNewVersion()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var oTADevice = Common.LocalDevice.Current.GetOTADevice(deviceMac);
 
            var frameWhiteBack = new FrameLayout();
            frameWhiteBack.Height = Application.GetRealHeight(308);
            frameWhiteBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameWhiteBack);
 
            //当前固件版本
            var frameNow = new FrameRowControl();
            frameNow.UseClickStatu = false;
            frameNow.Y = Application.GetRealHeight(20);
            frameWhiteBack.AddChidren(frameNow);
            frameNow.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNowFirmwareVersion), 500);
            frameNow.AddMostRightView(Common.LocalDevice.Current.AppendVersion(oTADevice.ImgVersion), 500);
            frameNow.AddBottomLine();
 
            //最新固件版本
            var frameNew = new FrameRowControl();
            frameNew.UseClickStatu = false;
            frameNew.Y = frameNow.Bottom + Application.GetRealHeight(12);
            frameWhiteBack.AddChidren(frameNew);
            frameNew.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNewFirmwareVersion), 500);
            frameNew.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uNothing), 500);
        }
 
        #endregion
 
        #region ■ 添加固件介绍行_____________________
 
        /// <summary>
        /// 添加固件介绍行
        /// </summary>
        /// <param name="versionInfo">固件对象</param>
        /// <param name="Maxheight">最大高度</param>
        /// <param name="YY"></param>
        private void AddUpdateContent(FirmwareVersionInfo versionInfo, int Maxheight,int YY)
        {
            FrameListControl listFrame = null;
            VerticalListControl listView = null;
 
            var realHeight = Application.GetRealHeight(40 + 12) * versionInfo.UpdateContent.Count;
            realHeight += Application.GetRealHeight(17 + 12 + 49 + 8 + 63);
 
            //行间距
            int rowSpace = 0;
            if (realHeight > Maxheight)
            {
                realHeight = Maxheight;
                listView = new VerticalListControl(12);
                listView.Height = realHeight;
                listView.Y = YY;
                listView.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(listView);
                rowSpace = listView.rowSpace / 2;
            }
            else
            {
                listFrame = new FrameListControl(12);
                listFrame.Height = realHeight;
                listFrame.Y = YY;
                listFrame.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(listFrame);
                rowSpace = listFrame.rowSpace / 2;
            }
 
            //添加头部空白间隙
            var frameSpace1 = new FrameLayout();
            frameSpace1.Height = Application.GetRealHeight(17);
            listView?.AddChidren(frameSpace1);
            listFrame?.AddChidren(frameSpace1);
 
            //修改内容
            var btnContentRow = new FrameRowControl(rowSpace);
            btnContentRow.UseClickStatu = false;
            btnContentRow.Height = Application.GetRealHeight(49);
            listView?.AddChidren(btnContentRow);
            listFrame?.AddChidren(btnContentRow);
            var btnContent = btnContentRow.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uEditorContent), 500);
            btnContent.TextSize = 12;
 
            //稍微再添加空白间隙
            var frameSpace2 = new FrameLayout();
            frameSpace2.Height = Application.GetRealHeight(8);
            listView?.AddChidren(frameSpace2);
            listFrame?.AddChidren(frameSpace2);
 
            foreach (var msg in versionInfo.UpdateContent)
            {
                var btnRow = new FrameRowControl(rowSpace);
                btnRow.UseClickStatu = false;
                btnRow.Height = Application.GetRealHeight(40);
                listView?.AddChidren(btnRow);
                listFrame?.AddChidren(btnRow);
 
                var btnMsg = btnRow.AddLeftCaption(msg, 965);
                btnMsg.TextSize = 10;
                btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
            }
 
            //添加底部空白间隙
            var frameSpace3 = new FrameLayout();
            frameSpace3.Height = Application.GetRealHeight(63);
            listView?.AddChidren(frameSpace3);
            listFrame?.AddChidren(frameSpace3);
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseForm()
        {
            //界面右划可
            UserView.HomePage.Instance.ScrollEnabled = true;
 
            base.CloseForm();
        }
 
        #endregion
    }
}