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 | 410 +++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 290 insertions(+), 120 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs index c168dc1..212caf9 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs @@ -1,26 +1,25 @@ 锘縰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 : DialogCommonForm + public class DeviceFirmwareUpdateForm : EditorCommonForm { #region 鈻� 鍙橀噺澹版槑___________________________ /// <summary> - /// 璁惧鐨凪ac鍦板潃 + /// 璁惧mac鍦板潃 /// </summary> - private string deviceMac = string.Empty; + private string deviceMac = null; /// <summary> - /// 璁惧鎴愬姛鍗囩骇瀹屾垚鐨勫洖璋冨嚱鏁� + /// 鍥轰欢淇℃伅 /// </summary> - public Action FinishUpdateEvent = null; + private FirmwareVersionInfo deviceFirmware = null; #endregion @@ -29,74 +28,273 @@ /// <summary> /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) /// </summary> - /// <param name="device">ota璁惧瀵硅薄</param> - /// <param name="deviceFirmware">鍥轰欢鍗囩骇淇℃伅</param> - public void ShowForm(OTADevice device, FirmwareVersionInfo deviceFirmware) + /// <param name="i_deviceMac">璁惧mac鍦板潃</param> + public void ShowForm(string i_deviceMac) { - this.deviceMac = device.DeviceAddr; - //鍒濆鍖栦腑閮ㄤ俊鎭� - this.InitMiddleFrame(device, deviceFirmware); + if (deviceMac != null && deviceMac != i_deviceMac) + { + //涓嶆槸鍚屼竴涓笢瑗� + return; + } + this.deviceMac = i_deviceMac; + + //璁剧疆鏍囬淇℃伅 + base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uFirmwareUpdate)); + + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + + //鍘嗗彶鐗堟湰 + this.InitTopRightMenu(); } /// <summary> - /// 鍒濆鍖栦腑閮ㄤ俊鎭� + /// 鍒濆鍖栦腑閮ㄦ帶浠� /// </summary> - /// <param name="device">ota璁惧瀵硅薄</param> - /// <param name="deviceFirmware">鍥轰欢鍗囩骇淇℃伅</param> - private void InitMiddleFrame(OTADevice device, FirmwareVersionInfo deviceFirmware) + private void InitMiddleFrame() { - var frameBack = new FrameLayout(); - frameBack.Width = Application.GetRealWidth(674); - frameBack.Height = Application.GetRealHeight(386); - frameBack.BackgroundColor = UserCenterColor.Current.White; - frameBack.Gravity = Gravity.CenterHorizontal; - frameBack.Y = Application.GetRealHeight(683); - frameBack.Radius = 6; - bodyFrameLayout.AddChidren(frameBack); + var oTADevice = HdlDeviceCommonLogic.Current.GetOTADevice(deviceMac); + //鑾峰彇璁惧鏈�鏂扮増鏈� + this.deviceFirmware = HdlFirmwareUpdateLogic.Current.GetFirmwareMostVersionInfo(FirmwareLevelType.A璁惧, + oTADevice.HwVersion.ToString(), + oTADevice.ImgTypeId.ToString(), + oTADevice.ImgVersion); - //杩涘害鏄剧ず鏂囨湰 - var btnText = new NormalViewControl(frameBack.Width, Application.GetRealHeight(58), false); - btnText.Y = Application.GetRealHeight(248); - btnText.TextColor = UserCenterColor.Current.TextGrayColor1; - btnText.TextAlignment = TextAlignment.Center; - //btnText.Text = "鍗囩骇涓�"; - frameBack.AddChidren(btnText); + //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�,鎴栬�呮槸灞曠ず妯℃澘,鍒欐病鏈夋柊鐗堟湰鐨勮娉� + if (Common.Config.Instance.Home.IsVirtually == true + || Common.Config.Instance.Home.IsShowTemplate == true) + { + this.deviceFirmware = null; + } - //杩涘害鏉� - var btnProRow = new FrameLayout(); - btnProRow.Gravity = Gravity.CenterHorizontal; - btnProRow.Y = Application.GetRealHeight(161); - btnProRow.Width = Application.GetRealWidth(559); - btnProRow.Height = Application.GetRealHeight(29); - btnProRow.BackgroundColor = 0xfff5f5f5; - btnProRow.Radius = (uint)Application.GetRealHeight(29) / 2; - frameBack.AddChidren(btnProRow); - var btnProgressBar = new FrameLayout(); - btnProgressBar.Width = 0; - btnProgressBar.Height = btnProRow.Height; - btnProgressBar.Radius = btnProRow.Radius; - btnProgressBar.BackgroundColor = 0xfffb744a; - btnProgressBar.Radius = (uint)Application.GetRealHeight(29) / 2; - btnProRow.AddChidren(btnProgressBar); + if (deviceFirmware != null && deviceFirmware.FirmwareVersion > oTADevice.ImgVersion) + { + //鎷ユ湁鏂扮増鏈� + this.InitControlByNewVersion(); + } + else + { + //娌℃湁鏂扮増鏈� + this.InitControlByNotNewVersion(); + } + } - //杩涘害鍊兼枃鏈� - var frameProgress = new FrameLayout(); - frameProgress.Width = Application.GetRealWidth(84); - frameProgress.Height = Application.GetRealHeight(60); - frameProgress.Y = Application.GetRealHeight(86); - frameBack.AddChidren(frameProgress); - frameProgress.X = btnProRow.X + btnProgressBar.Right - frameProgress.Width / 2; - var btnProgressPic = new PicViewControl(84, 60); - btnProgressPic.UnSelectedImagePath = "Item/ProgressMsg.png"; - frameProgress.AddChidren(btnProgressPic); - var btnProgressView = new NormalViewControl(84, 32, true); - btnProgressView.TextSize = 10; - btnProgressView.TextAlignment = TextAlignment.Center; - btnProgressView.Text = "0%"; - frameProgress.AddChidren(btnProgressView); + #endregion - //璁惧鍗囩骇 - this.DeviceUpdateMethod(device, deviceFirmware, btnText, btnProgressView, frameProgress, btnProgressBar, btnProRow.Width); + #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> + private void ShowTopRightMenu() + { + var frame = new TopRightMenuControl(1, 2); + //鍘嗗彶鐗堟湰 + 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 = HdlDeviceCommonLogic.Current.GetOTADevice(deviceMac); + + //鍗囩骇 + var btnUpdate = new BottomClickButton(); + btnUpdate.TextID = R.MyInternationalizationString.uLevelUp; + bodyFrameLayout.AddChidren(btnUpdate); + btnUpdate.ButtonClickEvent += (sender, e) => + { + //璁惧鍗囩骇 + 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; + } + + //娣诲姞澶撮儴绌虹櫧闂撮殭 + 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 @@ -106,18 +304,12 @@ /// <summary> /// 璁惧鍗囩骇 /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <param name="deviceFirmware">鍥轰欢淇℃伅</param> - /// <param name="btnText">鏍囬鎺т欢</param> - /// <param name="btnProgressView">杩涘害鍊兼枃鏈殑鏄剧ず鎺т欢</param> - /// <param name="frameProgress">杩涘害鍊艰兘澶熺Щ鍔ㄧ殑閭d釜妗嗘帶浠�</param> - /// <param name="btnProgressBar">杩涘害鏉�</param> - /// <param name="ProRowWidth">杩涘害鏉″鍣ㄧ殑鏈�澶у搴�</param> - private void DeviceUpdateMethod(OTADevice device, FirmwareVersionInfo deviceFirmware, NormalViewControl btnText, - NormalViewControl btnProgressView, FrameLayout frameProgress, FrameLayout btnProgressBar, int ProRowWidth) + private void DoDeviceUpdate(OTADevice oTADevice) { + //鎵撳紑杩涘害鏉� + ProgressFormBar.Current.Start(); //璁惧鍗囩骇 - var updateLogic = new HdlDeviceUpdateLogic(device, deviceFirmware); + var updateLogic = new HdlDeviceUpdateLogic(oTADevice, deviceFirmware); //鏇存柊鐘舵�佸彉鍖栫殑浜嬩欢 updateLogic.UpdateStatuChangedEvent += (div, msg) => { @@ -127,79 +319,57 @@ { //寮傚父 this.ShowMassage(ShowMsgType.Tip, msg); - this.CloseForm(); + ProgressFormBar.Current.Close(); } else if (div == 0) { //涓�鑸俊鎭� - btnText.Text = msg; + ProgressFormBar.Current.SetMsg(msg); } else if (div == 1) { //鍗囩骇瀹屾垚 + ProgressFormBar.Current.Close(); this.ShowMassage(ShowMsgType.Tip, msg); - //璋冪敤鍥炶皟鍑芥暟 - this.FinishUpdateEvent?.Invoke(); - this.CloseForm(); + + HdlThreadLogic.Current.RunMain(() => + { + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + }); } else if (div == 2) { //涓诲姩缁堟鍗囩骇 - this.CloseForm(); + ProgressFormBar.Current.Close(); } }); }; //杩涘害鍊兼敼鍙樹簨浠� updateLogic.ProgressEvent += (value) => { - Application.RunOnMainThread(() => - { - //杩涘害鏉� - decimal result = value / 100; - int width = (int)(result * ProRowWidth); - btnProgressBar.Width = width; - - //鏂囨湰鏄剧ず - btnProgressView.Text = value + "%"; - //鏂囨湰鏄剧ず鐨勯偅涓浘鐗囨绉诲姩 - frameProgress.X = ControlCommonResourse.XXLeft + btnProgressBar.Right - frameProgress.Width / 2; - }); - + ProgressFormBar.Current.SetValue(value, 100); }; //璁惧鍗囩骇寮�濮� updateLogic.StartUpdateReady(); //缁堟鍗囩骇 - btnText.ButtonClickEvent += (sender, e) => + ProgressFormBar.Current.MsgClickEvent += () => { //鍐嶆璋冪敤,鍐呴儴鏉′欢杈炬垚鏃�,鍙互閫夋嫨缁堟鍗囩骇 updateLogic.StartUpdateReady(); }; - } - - #endregion - - #region 鈻� 鐣岄潰鍏抽棴___________________________ - - /// <summary> - /// 鐢婚潰鍏抽棴 - /// </summary> - public override void CloseFormBefore() - { - //瀹夊崜鍙互鐐瑰嚮绯荤粺鐨勮繑鍥為敭 - UserView.HomePage.Instance.ScrollEnabled = true; - Shared.Common.CommonPage.BackKeyCanClick = true; - - //鍗囩骇瀵硅薄 - if (FirmwareUpdateResourse.dicDeviceUpdateList.ContainsKey(deviceMac) == true - && FirmwareUpdateResourse.dicDeviceUpdateList[deviceMac].IsFinishUpdate == true) + //鍏抽棴浜嬩欢 + ProgressFormBar.Current.CloseEvent += () => { - //濡傛灉璁惧宸茬粡鍗囩骇瀹屾垚锛岀晫闈㈠叧闂椂锛屽垯绉婚櫎鍐呭瓨 - FirmwareUpdateResourse.dicDeviceUpdateList[deviceMac].Dispose(); - FirmwareUpdateResourse.dicDeviceUpdateList.Remove(deviceMac); - } - this.FinishUpdateEvent = null; - - base.CloseFormBefore(); + //鍗囩骇瀵硅薄 + if (HdlFirmwareUpdateResourse.dicUpdateList.ContainsKey(deviceMac) == true + && HdlFirmwareUpdateResourse.dicUpdateList[deviceMac].IsFinishUpdate == true) + { + //濡傛灉璁惧宸茬粡鍗囩骇瀹屾垚锛岀晫闈㈠叧闂椂锛屽垯绉婚櫎鍐呭瓨 + HdlFirmwareUpdateResourse.dicUpdateList[deviceMac].Dispose(); + HdlFirmwareUpdateResourse.dicUpdateList.Remove(deviceMac); + } + }; } #endregion -- Gitblit v1.8.0