From ade5917841b0fdcb1df7353ef7c56b1a1bdc9282 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 22 九月 2020 10:03:32 +0800
Subject: [PATCH] 删除 Gateway.Ios文件

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs |  446 ++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 308 insertions(+), 138 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceFirmwareUpdateForm.cs
index c8e52c2..f023899 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>
+        /// 璁惧mac鍦板潃
+        /// </summary>
+        private string deviceMac = null;
         /// <summary>
-        /// 璁惧鐨凪ac鍦板潃
+        /// 鍥轰欢淇℃伅
         /// </summary>
-        private string deviceMac = string.Empty;
-        /// <summary>
-        /// 璁惧鎴愬姛鍗囩骇瀹屾垚鐨勫洖璋冨嚱鏁�
-        /// </summary>
-        public Action FinishUpdateEvent = null;
+        private FirmwareVersionInfo deviceFirmware = null;
 
         #endregion
 
@@ -29,74 +28,266 @@
         /// <summary>
         /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
         /// </summary>
-        /// <param name="device">ota璁惧瀵硅薄</param>
-        /// <param name="deviceFirmware">鍥轰欢鍗囩骇淇℃伅</param>
-        public void ShowForm(OTADevice device, FirmwareVersionInfo deviceFirmware)
-        {
-            this.deviceMac = device.DeviceAddr;
-            //鍒濆鍖栦腑閮ㄤ俊鎭�
-            this.InitMiddleFrame(device, deviceFirmware);
+        /// <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>
+        /// 鍒濆鍖栦腑閮ㄦ帶浠�
         /// </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 = (uint)Application.GetMinRealAverage(6);
-            bodyFrameLayout.AddChidren(frameBack);
-
-            //杩涘害鏄剧ず鏂囨湰
-            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);
+            var oTADevice = Common.LocalDevice.Current.GetOTADevice(deviceMac);
+            //鑾峰彇璁惧鏈�鏂扮増鏈�
+            this.deviceFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.ZigbeeDevice,
+                oTADevice.HwVersion.ToString(),
+                oTADevice.ImgTypeId.ToString(),
+                oTADevice.ImgVersion);
 
-            //杩涘害鏉�
-            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 (UserCenterResourse.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 = Common.LocalDevice.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(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
@@ -106,93 +297,72 @@
         /// <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) =>
             {
-                if (div == -1)
+                HdlThreadLogic.Current.RunMain(() =>
                 {
-                    //寮傚父
-                    this.ShowMassage(ShowMsgType.Tip, msg);
-                    this.CloseForm();
-                }
-                else if (div == 0)
-                {
-                    //涓�鑸俊鎭�
-                    btnText.Text = msg;
-                }
-                else if (div == 1)
-                {
-                    //鍗囩骇瀹屾垚
-                    this.ShowMassage(ShowMsgType.Tip, msg);
-                    //璋冪敤鍥炶皟鍑芥暟
-                    this.FinishUpdateEvent?.Invoke();
-                    this.CloseForm();
-                }
-                else if (div == 2)
-                {
-                    //涓诲姩缁堟鍗囩骇
-                    this.CloseForm();
-                }
+                    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) =>
             {
-                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 CloseForm()
-        {
-            //鍗囩骇瀵硅薄
-            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.CloseForm();
+                //鍗囩骇瀵硅薄
+                if (FirmwareUpdateResourse.dicUpdateList.ContainsKey(deviceMac) == true
+                    && FirmwareUpdateResourse.dicUpdateList[deviceMac].IsFinishUpdate == true)
+                {
+                    //濡傛灉璁惧宸茬粡鍗囩骇瀹屾垚锛岀晫闈㈠叧闂椂锛屽垯绉婚櫎鍐呭瓨
+                    FirmwareUpdateResourse.dicUpdateList[deviceMac].Dispose();
+                    FirmwareUpdateResourse.dicUpdateList.Remove(deviceMac);
+                }
+            };
         }
 
         #endregion

--
Gitblit v1.8.0