黄学彪
2019-11-25 5727cf0b9b54da0a191dd1e23cb5abf21320fbff
ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareInfoForm.cs
@@ -8,22 +8,18 @@
    /// <summary>
    /// 设备固件信息界面
    /// </summary>
    public class DeviceFirmwareInfoForm : UserCenterCommonForm
    public class DeviceFirmwareInfoForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout listView = null;
        /// <summary>
        /// 设备对象
        /// 设备mac地址
        /// </summary>
        private List<CommonDevice> listNewDevice = null;
        private string deviceMac = null;
        /// <summary>
        /// OTADevice
        /// 固件信息
        /// </summary>
        private OTADevice oTADevice = null;
        private FirmwareVersionInfo deviceFirmware = null;
        #endregion
@@ -32,28 +28,24 @@
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="listdevices">设备列表</param>
        public void ShowForm(List<CommonDevice> listdevices)
        /// <param name="i_deviceMac">设备mac地址</param>
        public void ShowForm(string i_deviceMac)
        {
            if (listNewDevice != null && listNewDevice[0].DeviceAddr != listdevices[0].DeviceAddr)
            if (deviceMac != null && deviceMac != i_deviceMac)
            {
                //不是同一个东西
                return;
            }
            this.listNewDevice = listdevices;
            this.deviceMac = i_deviceMac;
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uFirmwareInformation));
            //拥有200端口这个东西的时候,才会显示
            this.oTADevice = Common.LocalDevice.Current.GetOTADevice(listNewDevice[0].DeviceAddr);
            if (oTADevice == null || oTADevice.ImgVersion == -1)
            {
                return;
            }
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uFirmwareUpdate));
            //初始化中部控件
            this.InitMiddleFrame();
            //历史版本
            this.InitTopRightMenu();
        }
        /// <summary>
@@ -61,146 +53,245 @@
        /// </summary>
        private void InitMiddleFrame()
        {
            bodyFrameLayout.RemoveAll();
            var oTADevice = Common.LocalDevice.Current.GetOTADevice(deviceMac);
            //获取设备最新版本
            this.deviceFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.ZigbeeDevice,
                oTADevice.HwVersion.ToString(),
                oTADevice.ImgTypeId.ToString(),
                oTADevice.ImgVersion);
            listView = new VerticalScrolViewLayout();
            listView.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listView);
            //添加镜像ID行
            this.AddImageIdRow();
            //添加固件版本行
            this.AddFirmwareVersionRow();
            //添加硬件版本行
            this.AddHardwareVersionRow();
            //成员没有升级权限
            if (UserCenterResourse.UserInfo.AuthorityNo != 3)
            if (deviceFirmware != null && deviceFirmware.FirmwareVersion > oTADevice.ImgVersion)
            {
                //添加固件升级行
                this.AddFirmwareUpdateRow();
                //拥有新版本
                this.InitControlByNewVersion();
            }
            else
            {
                //没有新版本
                this.InitControlByNotNewVersion();
            }
        }
        #endregion
        #region ■ 添加镜像ID行_______________________
        #region ■ 右上角菜单_________________________
        /// <summary>
        /// 添加镜像ID行
        /// 初始化右上角菜单
        /// </summary>
        private void AddImageIdRow()
        private void InitTopRightMenu()
        {
            var row = new RowLayout();
            row.Height = ControlCommonResourse.ListViewRowHeight;
            listView.AddChidren(row);
            //设备镜像ID
            var btnUpview = new RowCenterView(false);
            btnUpview.TextID = R.MyInternationalizationString.uDeviceImageId;
            row.AddChidren(btnUpview);
            //镜像ID
            var btnVersion = new RowMostRightTextView();
            btnVersion.TextColor = UserCenterColor.Current.TextGrayColor;
            btnVersion.Text = oTADevice.ImgTypeId.ToString();
            row.AddChidren(btnVersion);
        }
        #endregion
        #region ■ 添加固件版本行_____________________
        /// <summary>
        /// 添加固件版本行
        /// </summary>
        private void AddFirmwareVersionRow()
        {
            var row = new RowLayout();
            row.Height = ControlCommonResourse.ListViewRowHeight;
            listView.AddChidren(row);
            //设备固件版本
            var btnUpview = new RowCenterView(false);
            btnUpview.TextID = R.MyInternationalizationString.uDeviceFirmwareVersion;
            row.AddChidren(btnUpview);
            //版本号
            var btnVersion = new RowMostRightTextView();
            btnVersion.TextColor = UserCenterColor.Current.TextGrayColor;
            btnVersion.Text = Common.LocalDevice.Current.AppendVersion(oTADevice.ImgVersion);
            row.AddChidren(btnVersion);
        }
        #endregion
        #region ■ 添加硬件版本行_____________________
        /// <summary>
        /// 添加硬件版本行
        /// </summary>
        private void AddHardwareVersionRow()
        {
            var row = new RowLayout();
            row.Height = ControlCommonResourse.ListViewRowHeight;
            listView.AddChidren(row);
            //设备硬件版本
            var btnUpview = new RowCenterView(false);
            btnUpview.TextID = R.MyInternationalizationString.uDeviceHardwareVersion;
            row.AddChidren(btnUpview);
            //版本号
            var btnVersion = new RowMostRightTextView();
            btnVersion.TextColor = UserCenterColor.Current.TextGrayColor;
            btnVersion.Text = Common.LocalDevice.Current.AppendVersion(oTADevice.HwVersion);
            row.AddChidren(btnVersion);
        }
        #endregion
        #region ■ 添加固件升级行_____________________
        /// <summary>
        /// 添加固件升级行
        /// </summary>
        private void AddFirmwareUpdateRow()
        {
            var statuRow = new StatuRowLayout(listView);
            //固件升级
            var btnUpview = new RowCenterView(false);
            btnUpview.TextID = R.MyInternationalizationString.uFirmwareUpdate;
            statuRow.AddChidren(btnUpview);
            //提示有新版本
            var btnNewVersion = new RowNewVersionTipView();
            btnNewVersion.Visible = false;
            statuRow.AddChidren(btnNewVersion);
            //获取设备最新版本
            var deviceFirmware = FirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.ZigbeeDevice,
                oTADevice.HwVersion.ToString(),
                oTADevice.ImgTypeId.ToString(),
                oTADevice.ImgVersion);
            if (deviceFirmware != null)
            var btnIcon = new MostRightIconControl(69, 69);
            btnIcon.UnSelectedImagePath = "Item/More.png";
            topFrameLayout.AddChidren(btnIcon);
            btnIcon.InitControl();
            btnIcon.ButtonClickEvent += ((sender, e) =>
            {
                if (deviceFirmware.FirmwareVersion > oTADevice.ImgVersion)
                //显示右上角菜单界面
                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) =>
                {
                    btnNewVersion.Visible = true;
                }
                else
                    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;
                Shared.Common.CommonPage.BackKeyCanClick = false;
                var form = new DeviceFirmwareUpdateForm();
                form.CloseFormByClickBack = false;
                form.AddForm(oTADevice, deviceFirmware);
                //完成升级事件
                form.FinishUpdateEvent += (() =>
                {
                    deviceFirmware = null;
                }
                    //初始化中部控件
                    this.InitMiddleFrame();
                });
            };
            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;
            }
            //版本向右的图标
            statuRow.AddRightIconControl();
            statuRow.MouseUpEvent += (sender, e) =>
            //添加头部空白间隙
            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 form = new DeviceFirmwareUpdateForm();
                this.AddForm(form, listNewDevice, deviceFirmware, oTADevice.ImgVersion);
            };
                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