From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期四, 17 十二月 2020 09:07:13 +0800 Subject: [PATCH] 新云端Ver1.3 --- ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs | 500 ++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 325 insertions(+), 175 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs index 80f6c2c..212caf9 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs @@ -1,227 +1,377 @@ 锘縰sing System; using System.Collections.Generic; using System.Text; -using System.Threading.Tasks; using ZigBee.Device; namespace Shared.Phone.UserCenter.Device { /// <summary> - /// 鍥轰欢鍗囩骇鐢婚潰 + /// 璁惧鍥轰欢鍗囩骇鐣岄潰 /// </summary> - public class DeviceFirmwareUpdateForm : UserCenterCommonForm + public class DeviceFirmwareUpdateForm : EditorCommonForm { - /// <summary> - /// 鍗囩骇鐨勮澶� - /// </summary> - private List<CommonDevice> listUpdateDevice = null; + #region 鈻� 鍙橀噺澹版槑___________________________ + /// <summary> - /// 璁惧鏂扮増鏈殑鍥轰欢淇℃伅 - /// </summary> - private FirmwareVersionInfo deviceFirmware = null; - /// <summary> - /// 褰撳墠闀滃儚鐗堟湰 + /// 璁惧mac鍦板潃 /// </summary> - private int imageVersion = 0; + private string deviceMac = null; + /// <summary> + /// 鍥轰欢淇℃伅 + /// </summary> + private FirmwareVersionInfo deviceFirmware = null; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ /// <summary> /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) /// </summary> - /// <param name="i_listdevice">璁惧</param> - /// <param name="i_deviceFirmware">璁惧鏂扮増鏈�</param> - /// <param name="i_imageVersion">褰撳墠闀滃儚鐗堟湰</param> - public void ShowForm(List<CommonDevice> i_listdevice, FirmwareVersionInfo i_deviceFirmware, int i_imageVersion) - { - this.listUpdateDevice = i_listdevice; - this.imageVersion = i_imageVersion; - this.deviceFirmware = i_deviceFirmware; - - //璁剧疆鏍囬淇℃伅 - base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uFirmwareUpdate)); - - var btnIcon = new TopLayoutMostRightView(); - btnIcon.UnSelectedImagePath = "Item/More.png"; - btnIcon.SelectedImagePath = "Item/MoreSelected.png"; - topFrameLayout.AddChidren(btnIcon); - btnIcon.MouseUpEventHandler += (sender, e) => - { - //鑿滃崟鎺т欢 - var frameMenu = new TopRightMenuControl(this, 1); - //鍘嗗彶鐗堟湰 - string menu1 = Language.StringByID(R.MyInternationalizationString.uHistoryVersion); - frameMenu.AddRowMenu(menu1, (obj) => - { - var form = new DeviceHistoryFirmwareVersionForm(); - this.AddForm(form, listUpdateDevice); - form.FormCloseAction += ((firmwareInfo) => - { - //濡傛灉褰撳墠姝e湪鍗囩骇锛屽垯鍘嗗彶鐗堟湰鏃犳晥 - if (FirmwareUpdateResourse.dicDeviceUpdateList.ContainsKey(this.listUpdateDevice[0].DeviceAddr) == false) - { - //閲嶆柊鍒锋柊鐣岄潰 - this.ShowForm(listUpdateDevice, firmwareInfo, firmwareInfo.FirmwareVersion); - } - }); - }); - }; - - //鍒濆鍖栦腑閮ㄦ帶浠� - this.InitMiddleFrame(); - } - - /// <summary> - /// 鍒濆鍖栦腑閮ㄦ帶浠� - /// </summary> - private void InitMiddleFrame() + /// <param name="i_deviceMac">璁惧mac鍦板潃</param> + public void ShowForm(string i_deviceMac) { - bodyFrameLayout.RemoveAll(); - - //娌℃湁鏂扮増鏈� - if (deviceFirmware == null) + if (deviceMac != null && deviceMac != i_deviceMac) { - //鏄剧ず宸茬粡鏄柊鐗堟湰 - this.ShowIsMostVewVersion(); - } - else - { - //鏄剧ず宸茬粡鏄柊鐗堟湰 - this.ShowIsHadNewVersion(); - } - } - - /// <summary> - /// 鏄剧ず宸茬粡鏄柊鐗堟湰 - /// </summary> - private void ShowIsMostVewVersion() - { - //濡傛灉鐐圭殑鏄巻鍙茬増鏈紝鍒欏悓姝ョ晫闈� - string mainKeys = this.listUpdateDevice[0].DeviceAddr; - if (FirmwareUpdateResourse.dicDeviceUpdateList.ContainsKey(mainKeys) == true) - { - var btnUpdateControl = FirmwareUpdateResourse.dicDeviceUpdateList[mainKeys]; - bodyFrameLayout.AddChidren(btnUpdateControl); - //鍒濆鍖栧崌绾ф帶浠� - this.InitDeviceUpdateControl(btnUpdateControl); + //涓嶆槸鍚屼竴涓笢瑗� return; } + this.deviceMac = i_deviceMac; - //褰撳墠绋嬪簭鐗堟湰 - var btnVersionMsg = new MsgViewControl(800, true); - btnVersionMsg.TextID = R.MyInternationalizationString.uIsMostNewVersion; - btnVersionMsg.Y = Application.GetRealHeight(100); - btnVersionMsg.TextAlignment = TextAlignment.Center; - btnVersionMsg.Gravity = Gravity.CenterHorizontal; - bodyFrameLayout.AddChidren(btnVersionMsg); + //璁剧疆鏍囬淇℃伅 + base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uFirmwareUpdate)); - //鐗堟湰 - var btnVersion = new MsgViewControl(800, true); - btnVersion.Text = Common.LocalDevice.Current.AppendVersion(this.imageVersion); - btnVersion.Y = btnVersionMsg.Bottom + Application.GetRealHeight(10); - btnVersion.TextAlignment = TextAlignment.Center; - btnVersion.Gravity = Gravity.CenterHorizontal; - bodyFrameLayout.AddChidren(btnVersion); + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + + //鍘嗗彶鐗堟湰 + this.InitTopRightMenu(); } /// <summary> - /// 鏄剧ず瀛樺湪鏈�鏂扮増鏈� + /// 鍒濆鍖栦腑閮ㄦ帶浠� /// </summary> - private void ShowIsHadNewVersion() + private void InitMiddleFrame() { - //鍗囩骇鎺т欢 - string mainKeys = this.listUpdateDevice[0].DeviceAddr; + var oTADevice = HdlDeviceCommonLogic.Current.GetOTADevice(deviceMac); + //鑾峰彇璁惧鏈�鏂扮増鏈� + this.deviceFirmware = HdlFirmwareUpdateLogic.Current.GetFirmwareMostVersionInfo(FirmwareLevelType.A璁惧, + oTADevice.HwVersion.ToString(), + oTADevice.ImgTypeId.ToString(), + oTADevice.ImgVersion); - //涓存椂鎺т欢 - var btnTemp = new ButtonCommon(); - Common.LocalDevice.Current.SetDeviceBeloneIconToControl(btnTemp, this.listUpdateDevice); - - DeviceFirmwareUpdateControl btnUpdateControl = null; - if (FirmwareUpdateResourse.dicDeviceUpdateList.ContainsKey(mainKeys) == true) + //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�,鎴栬�呮槸灞曠ず妯℃澘,鍒欐病鏈夋柊鐗堟湰鐨勮娉� + if (Common.Config.Instance.Home.IsVirtually == true + || Common.Config.Instance.Home.IsShowTemplate == true) { - btnUpdateControl = FirmwareUpdateResourse.dicDeviceUpdateList[mainKeys]; - bodyFrameLayout.AddChidren(btnUpdateControl); + this.deviceFirmware = null; + } + + if (deviceFirmware != null && deviceFirmware.FirmwareVersion > oTADevice.ImgVersion) + { + //鎷ユ湁鏂扮増鏈� + this.InitControlByNewVersion(); } else { - btnUpdateControl = new DeviceFirmwareUpdateControl(null, this.listUpdateDevice, this.deviceFirmware); - bodyFrameLayout.AddChidren(btnUpdateControl); - btnUpdateControl.InitChidrenControl(btnTemp.UnSelectedImagePath); + //娌℃湁鏂扮増鏈� + this.InitControlByNotNewVersion(); } - //鍒濆鍖栧崌绾ф帶浠� - this.InitDeviceUpdateControl(btnUpdateControl); + } + + #endregion + + #region 鈻� 鍙充笂瑙掕彍鍗昣________________________ + + /// <summary> + /// 鍒濆鍖栧彸涓婅鑿滃崟 + /// </summary> + private void InitTopRightMenu() + { + if (HdlUserCenterResourse.HideOption.DeviceHistory != 1) + { + return; + } + var btnIcon = new MostRightIconControl(69, 69); + btnIcon.UnSelectedImagePath = "Item/More.png"; + topFrameLayout.AddChidren(btnIcon); + btnIcon.InitControl(); + btnIcon.ButtonClickEvent += ((sender, e) => + { + //鏄剧ず鍙充笂瑙掕彍鍗曠晫闈� + this.ShowTopRightMenu(); + }); } /// <summary> - /// 鍒濆鍖栧崌绾ф帶浠� + /// 鏄剧ず鍙充笂瑙掕彍鍗曠晫闈� /// </summary> - /// <param name="btnUpdateControl"></param> - private void InitDeviceUpdateControl(DeviceFirmwareUpdateControl btnUpdateControl) + private void ShowTopRightMenu() { - //鍗囩骇 - BottomClickButton btnUpdate = btnUpdateControl.btnUpdateButton; - if (btnUpdate == null) + var frame = new TopRightMenuControl(1, 2); + //鍘嗗彶鐗堟湰 + var deviceMenu = Language.StringByID(R.MyInternationalizationString.uHistoryVersion); + frame.AddRowMenu(deviceMenu, "", "", () => { - btnUpdate = new BottomClickButton(); - btnUpdate.UseClickStatu = false; - btnUpdate.TextID = R.MyInternationalizationString.uLevelUp; - btnUpdate.Gravity = Gravity.BottomCenter; - btnUpdate.MouseUpTime = 0; - btnUpdate.Radius = 0; - btnUpdate.Width = Application.CurrentWidth; - btnUpdate.MouseUpEvent += (sender, e) => + var form = new DeviceHistoryFirmwareVersionForm(); + form.AddForm(deviceMac); + form.SelectFirmwareInfoEvent += (info) => { - if (btnUpdateControl.UpdateStatu == UpdateStatuMode.UpdateSuccess) - { - //鍗囩骇鎴愬姛鐨勬椂鍊欙紝濡傛灉鍗曞嚮姝ゆ寜閽紝鍒欏叧闂晫闈� - this.CloseForm(); - return; - } - //杩涘叆鎵ц鏇存柊鎿嶄綔鍑嗗闃舵 - btnUpdateControl.StartUpdateReady(); + this.deviceFirmware = info; + //鎷ユ湁鏂扮増鏈� + this.InitControlByNewVersion(); }; - } - btnUpdateControl.btnUpdateButton = btnUpdate; - bodyFrameLayout.AddChidren(btnUpdate); - - var listView = new VerticalScrolViewLayout(); - listView.Y = btnUpdateControl.Bottom; - listView.Height = bodyFrameLayout.Height - btnUpdateControl.Height - btnUpdate.Height; - bodyFrameLayout.AddChidren(listView); - - //鍋氭垚鏇存柊鍐呭鎺т欢 - ViewNormalControl btnTempMsg = null; - //涓存椂鎺т欢 - ButtonCommon btnTemp = null; - //鍋氭垚鏇存柊璁板綍鎺т欢 - foreach (string msg in btnUpdateControl.deviceFirmware.UpdateContent) - { - var btnmsg = new ViewNormalControl(listView.Width); - btnmsg.X = ControlCommonResourse.XXLeft; - if (btnTemp != null) - { - btnmsg.Y = btnTemp.Bottom + Application.GetRealHeight(5); - } - btnmsg.Text = msg; - listView.AddChidren(btnmsg); - btnTempMsg = btnmsg; - } + }); } + + #endregion + + #region 鈻� 鎷ユ湁鏂扮増鏈琠________________________ /// <summary> - /// 鐢婚潰鍏抽棴 + /// 鎷ユ湁鏂扮増鏈� /// </summary> - /// <param name="isCloseForm">鏄惁鍏抽棴鐣岄潰,false鐨勬椂鍊�,鍙細璋冪敤鍏抽棴鍑芥暟閲岄潰鐨勯檮鍔犲姛鑳�</param> - public override void CloseForm(bool isCloseForm = true) + private void InitControlByNewVersion() { - //鍗囩骇鎺т欢 - string mainKeys = this.listUpdateDevice[0].DeviceAddr; - if (FirmwareUpdateResourse.dicDeviceUpdateList.ContainsKey(mainKeys) == true - && FirmwareUpdateResourse.dicDeviceUpdateList[mainKeys].IsFinishUpdate == true) + //娓呯┖bodyFrame + this.ClearBodyFrame(); + + var oTADevice = HdlDeviceCommonLogic.Current.GetOTADevice(deviceMac); + + //鍗囩骇 + var btnUpdate = new BottomClickButton(); + btnUpdate.TextID = R.MyInternationalizationString.uLevelUp; + bodyFrameLayout.AddChidren(btnUpdate); + btnUpdate.ButtonClickEvent += (sender, e) => { - //濡傛灉璁惧宸茬粡鍗囩骇瀹屾垚锛岀晫闈㈠叧闂椂锛屽垯绉婚櫎鍐呭瓨 - FirmwareUpdateResourse.dicDeviceUpdateList.Remove(mainKeys); + //璁惧鍗囩骇 + HdlThreadLogic.Current.RunThread(() => + { + this.DoDeviceUpdate(oTADevice); + }); + }; + + 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(HdlDeviceCommonLogic.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(HdlDeviceCommonLogic.Current.AppendVersion(deviceFirmware.FirmwareVersion), 500); + frameNew.AddBottomLine(); + + //娣诲姞鍥轰欢浠嬬粛琛� + int maxHeight = btnUpdate.Y - HdlControlResourse.BottomButtonAndListViewSpace - frameNew.Bottom; + this.AddUpdateContent(deviceFirmware, maxHeight, frameNew.Bottom); + } + + #endregion + + #region 鈻� 娌℃湁鏂扮増鏈琠________________________ + + /// <summary> + /// 娌℃湁鏂扮増鏈� + /// </summary> + private void InitControlByNotNewVersion() + { + //娓呯┖bodyFrame + this.ClearBodyFrame(); + + var oTADevice = HdlDeviceCommonLogic.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(HdlDeviceCommonLogic.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; } - base.CloseForm(isCloseForm); + //娣诲姞澶撮儴绌虹櫧闂撮殭 + 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> + private void DoDeviceUpdate(OTADevice oTADevice) + { + //鎵撳紑杩涘害鏉� + ProgressFormBar.Current.Start(); + //璁惧鍗囩骇 + var updateLogic = new HdlDeviceUpdateLogic(oTADevice, deviceFirmware); + //鏇存柊鐘舵�佸彉鍖栫殑浜嬩欢 + updateLogic.UpdateStatuChangedEvent += (div, msg) => + { + HdlThreadLogic.Current.RunMain(() => + { + if (div == -1) + { + //寮傚父 + this.ShowMassage(ShowMsgType.Tip, msg); + ProgressFormBar.Current.Close(); + } + else if (div == 0) + { + //涓�鑸俊鎭� + ProgressFormBar.Current.SetMsg(msg); + } + else if (div == 1) + { + //鍗囩骇瀹屾垚 + ProgressFormBar.Current.Close(); + this.ShowMassage(ShowMsgType.Tip, msg); + + HdlThreadLogic.Current.RunMain(() => + { + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + }); + } + else if (div == 2) + { + //涓诲姩缁堟鍗囩骇 + ProgressFormBar.Current.Close(); + } + }); + }; + //杩涘害鍊兼敼鍙樹簨浠� + updateLogic.ProgressEvent += (value) => + { + ProgressFormBar.Current.SetValue(value, 100); + }; + //璁惧鍗囩骇寮�濮� + updateLogic.StartUpdateReady(); + //缁堟鍗囩骇 + ProgressFormBar.Current.MsgClickEvent += () => + { + //鍐嶆璋冪敤,鍐呴儴鏉′欢杈炬垚鏃�,鍙互閫夋嫨缁堟鍗囩骇 + updateLogic.StartUpdateReady(); + }; + //鍏抽棴浜嬩欢 + ProgressFormBar.Current.CloseEvent += () => + { + //鍗囩骇瀵硅薄 + if (HdlFirmwareUpdateResourse.dicUpdateList.ContainsKey(deviceMac) == true + && HdlFirmwareUpdateResourse.dicUpdateList[deviceMac].IsFinishUpdate == true) + { + //濡傛灉璁惧宸茬粡鍗囩骇瀹屾垚锛岀晫闈㈠叧闂椂锛屽垯绉婚櫎鍐呭瓨 + HdlFirmwareUpdateResourse.dicUpdateList[deviceMac].Dispose(); + HdlFirmwareUpdateResourse.dicUpdateList.Remove(deviceMac); + } + }; + } + + #endregion } } -- Gitblit v1.8.0