| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Net;
|
| | | using System.Runtime.Remoting.Contexts;
|
| | | using System.Text;
|
| | | using Shared.Common;
|
| | | using Shared.Phone.Device.CommonForm;
|
| | |
|
| | | namespace Shared.Phone.UserCenter.Abount
|
| | | {
|
| | | /// <summary>
|
| | |
| | | /// </summary>
|
| | | public class AbountForm : EditorCommonForm
|
| | | {
|
| | | #region **变量*****************************
|
| | | #region ◆ 变量____________________________
|
| | | /// <summary>
|
| | | /// 是否正在更新中
|
| | | /// </summary>
|
| | | public bool isUpdating=false;
|
| | | public bool isUpdating;
|
| | | /// <summary>
|
| | | /// The web client.
|
| | | /// </summary>
|
| | | public WebClient webClient=new WebClient { };
|
| | | /// <summary>
|
| | | /// 进度条
|
| | | /// </summary>
|
| | | public HorizontalSeekBar seekBar;
|
| | | /// <summary>
|
| | | /// 进度百分比
|
| | | /// </summary>
|
| | | public Button seekBarTitle;
|
| | | /// <summary>
|
| | | /// 取消下载按钮
|
| | | /// </summary>
|
| | | public Button cancelDownLoadBtn;
|
| | | /// <summary>
|
| | | /// 更新按钮
|
| | | /// </summary>
|
| | | public Button updateBtn;
|
| | | public WebClient webClient = new WebClient { };
|
| | | /// <summary>
|
| | | /// 更新中
|
| | | /// </summary>
|
| | | public Button updatingBtn;
|
| | | public NormalViewControl btnUpdating;
|
| | | /// <summary>
|
| | | /// The instance.
|
| | | /// distributedMark
|
| | | /// </summary>
|
| | | public static AbountForm instance;
|
| | | public string distributedMark;
|
| | | /// <summary>
|
| | | /// updateRow
|
| | | /// </summary>
|
| | | public FrameRowControl rowUpdate;
|
| | | /// <summary>
|
| | | /// 下载安卓apk的byte长度
|
| | | /// </summary>
|
| | | public long ApkBytesTotalLength = 0;
|
| | |
|
| | | #endregion
|
| | |
|
| | | /// <summary>
|
| | | /// Initializes a new instance of the <see cref="T:Shared.Phone.UserCenter.Abount.AbountForm"/> class.
|
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
| | | /// </summary>
|
| | | public AbountForm()
|
| | | public void ShowForm()
|
| | | {
|
| | | instance = this;
|
| | | //设置标题信息
|
| | | base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAboutMe));
|
| | | //初始化中部控件
|
| | | this.InitMiddleFrame();
|
| | | }
|
| | | /// <summary> |
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建) |
| | | /// </summary> |
| | | public void ShowForm() |
| | | { |
| | | //设置标题信息 |
| | | base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uVersionInformation)); |
| | | //初始化中部控件 |
| | | this.InitMiddleFrame(); |
| | | } |
| | | /// <summary>
|
| | | /// Closes the form.
|
| | | /// </summary>
|
| | | public override void CloseForm()
|
| | | public override void CloseFormBefore()
|
| | | {
|
| | | #if Android
|
| | | if(isUpdating==true)
|
| | | SetDownLoadBtnNoVisible();
|
| | | CancelDownLoadApkAsync();
|
| | | base.CloseFormBefore();
|
| | | #elif iOS
|
| | | base.CloseFormBefore();
|
| | | #endif
|
| | | }
|
| | | /// <summary>
|
| | | /// 初始化中部控件
|
| | | /// </summary>
|
| | | private void InitMiddleFrame()
|
| | | {
|
| | | //头部白色背景
|
| | | var frameLogo = new FrameLayoutBase();
|
| | | frameLogo.Height = Application.GetRealHeight(484);
|
| | | frameLogo.BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
|
| | | bodyFrameLayout.AddChidren(frameLogo);
|
| | | //图标的容器
|
| | | var frameLogoBackground = new FrameLayoutBase();
|
| | | frameLogoBackground.Y = Application.GetRealHeight(104);
|
| | | frameLogoBackground.Width = this.GetPictrueRealSize(167);
|
| | | frameLogoBackground.Height = this.GetPictrueRealSize(167);
|
| | | frameLogoBackground.Gravity = Gravity.CenterHorizontal;
|
| | | frameLogoBackground.BackgroundColor = ZigbeeColor.Current.GXCButtonBlackSelectedColor;
|
| | | frameLogoBackground.Radius = (uint)Application.GetRealHeight(37);
|
| | | frameLogo.AddChidren(frameLogoBackground);
|
| | | //图标
|
| | | var btnLogo = new IconViewControl(144);
|
| | | btnLogo.UnSelectedImagePath = "Account/Logo_White.png";
|
| | | btnLogo.Gravity = Gravity.Center;
|
| | | frameLogoBackground.AddChidren(btnLogo);
|
| | | //HDL Home
|
| | | var btnName = new NormalViewControl(700, 60, true);
|
| | | btnName.Y = Application.GetRealHeight(294);
|
| | | btnName.Gravity = Gravity.CenterHorizontal;
|
| | | btnName.Text = "HDL Home";
|
| | | btnName.TextSize = 15;
|
| | | btnName.TextColor = ZigbeeColor.Current.GXCTextDeepBlackColor;
|
| | | btnName.TextAlignment = TextAlignment.Center;
|
| | | frameLogo.AddChidren(btnName);
|
| | | //版本号
|
| | | var btnVersion = new NormalViewControl(700, 50, true);
|
| | | btnVersion.Y = Application.GetRealHeight(366);
|
| | | btnVersion.Gravity = Gravity.CenterHorizontal;
|
| | | btnVersion.Text = $"{Language.StringByID(R.MyInternationalizationString.VersionCode)} {CommonPage.CodeIDString}";
|
| | | btnVersion.TextSize = 12;
|
| | | btnVersion.TextColor = ZigbeeColor.Current.GXCTextGrayColor;
|
| | | btnVersion.TextAlignment = TextAlignment.Center;
|
| | | frameLogo.AddChidren(btnVersion);
|
| | | //列表控件
|
| | | var listView = new FrameListControl(12);
|
| | | listView.Y = frameLogo.Bottom + Application.GetRealHeight(23);
|
| | | listView.BackgroundColor = UserCenterColor.Current.White;
|
| | | listView.Height = Application.GetRealHeight(500);
|
| | | bodyFrameLayout.AddChidren(listView);
|
| | | //服务协议
|
| | | //var rowService = new FrameRowControl(listView.rowSpace / 2);
|
| | | //listView.AddChidren(rowService);
|
| | | //rowService.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.SLA), 400);
|
| | | //rowService.AddRightArrow();
|
| | | //rowService.AddBottomLine();
|
| | | //版本更新
|
| | | this.rowUpdate = new FrameRowControl(listView.rowSpace / 2);
|
| | | listView.AddChidren(rowUpdate);
|
| | | rowUpdate.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.UpdateVersion), 400);
|
| | | rowUpdate.AddRightArrow();
|
| | | var btnRightView = rowUpdate.AddMostRightView("", 400);
|
| | | rowUpdate.CanClick = false;
|
| | | rowUpdate.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.CancelUpdating), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim));
|
| | | alert.Show();
|
| | | alert.ResultEventHandler += (send, e) =>
|
| | | UpdateVersion();
|
| | | };
|
| | | //调整桌布高度
|
| | | listView.AdjustRealHeight(Application.GetRealHeight(23));
|
| | |
|
| | | //更新中
|
| | | this.btnUpdating = new NormalViewControl(556, 106, true);
|
| | | btnUpdating.Y = Application.GetRealHeight(994);
|
| | | btnUpdating.Radius = (uint)Application.GetRealHeight(53);
|
| | | btnUpdating.BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor;
|
| | | btnUpdating.TextID = R.MyInternationalizationString.Updating;
|
| | | btnUpdating.TextSize = 15;
|
| | | btnUpdating.TextColor = ZigbeeColor.Current.GXCTextWhiteColor;
|
| | | btnUpdating.Gravity = Gravity.CenterHorizontal;
|
| | | btnUpdating.TextAlignment = TextAlignment.Center;
|
| | | bodyFrameLayout.AddChidren(btnUpdating);
|
| | |
|
| | | //设置进度控件不可见
|
| | | this.SetDownLoadBtnNoVisible();
|
| | |
|
| | | //检测新版本
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | var result = await CanUpdateAsync();
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | if (e)
|
| | | if (result)
|
| | | {
|
| | | updateBtn.Visible = true;
|
| | | SetDownLoadBtnNoVisible();
|
| | | CommonPage.CancelDownLoadApkAsync();
|
| | | base.CloseForm();
|
| | | //更新最新版
|
| | | btnRightView.TextID = R.MyInternationalizationString.Update;
|
| | | rowUpdate.CanClick = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | return;
|
| | | btnRightView.TextID = R.MyInternationalizationString.TheAppVersionIsNewest;
|
| | | }
|
| | | };
|
| | | }
|
| | | else
|
| | | {
|
| | | Phone.UserView.HomePage.Instance.ScrollEnabled = true;
|
| | | base.CloseForm();
|
| | | }
|
| | | #elif iOS
|
| | | base.CloseForm();
|
| | | #endif
|
| | | });
|
| | |
|
| | | });
|
| | | }
|
| | | /// <summary> |
| | | /// 初始化中部控件 |
| | | /// </summary> |
| | | private void InitMiddleFrame() |
| | | {
|
| | | var logoBtn = new Button()
|
| | | {
|
| | | Width = Application.GetMinRealAverage(270),
|
| | | Height = Application.GetMinRealAverage(270),
|
| | | Y = Application.GetRealHeight(100),
|
| | | UnSelectedImagePath = "Logo/Logo.png",
|
| | | Gravity = Gravity.CenterHorizontal
|
| | | };
|
| | | bodyFrameLayout.AddChidren(logoBtn);
|
| | |
|
| | | var nameBtn = new Button()
|
| | | {
|
| | | Width = Application.GetMinRealAverage(700),
|
| | | Height = Application.GetMinRealAverage(100),
|
| | | Y = Application.GetRealHeight(100)+logoBtn.Bottom,
|
| | | Gravity = Gravity.CenterHorizontal,
|
| | | Text="HDL Home",
|
| | | TextSize=20,
|
| | | TextColor=ZigbeeColor.Current.GXCTextBlackColor
|
| | | };
|
| | | bodyFrameLayout.AddChidren(nameBtn);
|
| | |
|
| | | var versionBtn = new Button()
|
| | | {
|
| | | Width = Application.GetMinRealAverage(700),
|
| | | Height = Application.GetMinRealAverage(100),
|
| | | Y = Application.GetRealHeight(10) + nameBtn.Bottom,
|
| | | Gravity = Gravity.CenterHorizontal,
|
| | | Text = $"v{CommonPage.CodeIDString}",
|
| | | TextSize = 14,
|
| | | TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor
|
| | | };
|
| | | bodyFrameLayout.AddChidren(versionBtn);
|
| | |
|
| | | updateBtn = new Button()
|
| | | {
|
| | | Y= Application.GetRealHeight(50)+versionBtn.Bottom,
|
| | | Width = Application.GetMinRealAverage(700),
|
| | | Gravity = Gravity.CenterHorizontal,
|
| | | Height =Application.GetRealHeight(Shared.Common.CommonPage.ButtonHeight),
|
| | | TextID=R.MyInternationalizationString.Update,
|
| | | TextColor=ZigbeeColor.Current.GXCTextBlueColor
|
| | | };
|
| | | bodyFrameLayout.AddChidren(updateBtn);
|
| | | updateBtn.MouseUpEventHandler += GetVersion;
|
| | |
|
| | | seekBar = new HorizontalSeekBar()
|
| | | {
|
| | | Y = updateBtn.Bottom + Application.GetRealHeight(50),
|
| | | Width = Application.GetRealWidth(750),
|
| | | Height = Application.GetRealHeight(80),
|
| | | Gravity = Gravity.CenterHorizontal,
|
| | | BackgroundColor = ZigbeeColor.Current.GXCSliderUnSelectedColor,
|
| | | ThumbColor = 0x00000000,
|
| | | ProgressColor = ZigbeeColor.Current.GXCButtonBlueColor,
|
| | | Max = 100,
|
| | | Progress = 0,
|
| | | IsCanScrolled=false,
|
| | | IsCanMove=false
|
| | | };
|
| | | bodyFrameLayout.AddChidren(seekBar);
|
| | |
|
| | | seekBarTitle = new Button()
|
| | | {
|
| | | Y = updateBtn.Bottom + Application.GetRealHeight(50),
|
| | | X= seekBar.Right+Application.GetRealWidth(10),
|
| | | Width = Application.GetRealWidth(150),
|
| | | Height = Application.GetRealHeight(80),
|
| | | Text = $"{seekBar.Progress}%",
|
| | | TextAlignment=TextAlignment.CenterLeft,
|
| | | TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
| | | };
|
| | | bodyFrameLayout.AddChidren(seekBarTitle);
|
| | |
|
| | | updatingBtn = new Button()
|
| | | {
|
| | | Y = seekBar.Bottom + Application.GetRealHeight(20),
|
| | | Width = Application.GetRealWidth(300),
|
| | | Height = Application.GetRealHeight(80),
|
| | | TextID= R.MyInternationalizationString.Updating,
|
| | | TextAlignment = TextAlignment.Center,
|
| | | TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
| | | Gravity=Gravity.CenterHorizontal
|
| | | };
|
| | | bodyFrameLayout.AddChidren(updatingBtn);
|
| | | cancelDownLoadBtn = new Button()
|
| | | {
|
| | | TextID = R.MyInternationalizationString.Cancel,
|
| | | TextColor = ZigbeeColor.Current.GXCTextBlueColor,
|
| | | Height = Application.GetRealHeight(80),
|
| | | Width = Application.GetRealWidth(500),
|
| | | Gravity = Gravity.CenterHorizontal,
|
| | | Y = updatingBtn.Bottom + Application.GetRealHeight(500)
|
| | | };
|
| | | bodyFrameLayout.AddChidren(cancelDownLoadBtn);
|
| | | #if Android
|
| | | cancelDownLoadBtn.MouseUpEventHandler += CancelDownLoadApk;
|
| | | #endif
|
| | | SetDownLoadBtnNoVisible();
|
| | | }
|
| | | /// <summary>
|
| | | /// 设置进度控件不可见
|
| | | /// </summary>
|
| | | public void SetDownLoadBtnNoVisible()
|
| | | private void SetDownLoadBtnNoVisible()
|
| | | {
|
| | | Phone.UserView.HomePage.Instance.ScrollEnabled = true;
|
| | | isUpdating = false;
|
| | | updateBtn.Visible = true;
|
| | | seekBar.Visible = seekBarTitle.Visible = cancelDownLoadBtn.Visible = updatingBtn.Visible = false;
|
| | | btnUpdating.Visible = false;
|
| | | }
|
| | | /// <summary>
|
| | | /// 设置进度控件可见
|
| | | /// </summary>
|
| | | public void SetDownLoadBtnVisible()
|
| | | private void SetDownLoadBtnVisible()
|
| | | {
|
| | | Phone.UserView.HomePage.Instance.ScrollEnabled = false;
|
| | | isUpdating = true;
|
| | | updateBtn.Visible = false;
|
| | | seekBar.Visible = seekBarTitle.Visible = cancelDownLoadBtn.Visible = updatingBtn.Visible = true;
|
| | | btnUpdating.Visible = true;
|
| | | rowUpdate.CanClick = false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// Gets the version.
|
| | | /// 检查版本
|
| | | /// </summary>
|
| | | /// <param name="sender">Sender.</param>
|
| | | /// <param name="e">E.</param>
|
| | | private async void GetVersion(object sender, MouseEventArgs e)
|
| | | /// <returns></returns>
|
| | | private async System.Threading.Tasks.Task<bool> CanUpdateAsync()
|
| | | {
|
| | | #if iOS
|
| | | try
|
| | | {
|
| | | CommonPage.Loading.Start();
|
| | | var versionResult = await Shared.Common.CommonPage.Instance.RequestHttpsiOSAppVersionAsync();
|
| | | try
|
| | | {
|
| | | var versionResult = await RequestHttpsiOSAppVersionAsync();
|
| | | if (versionResult == null || versionResult.Results == null)
|
| | | {
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.UpdateAppFail);
|
| | | return;
|
| | | return false;
|
| | | }
|
| | | var results = Newtonsoft.Json.Linq.JArray.Parse(versionResult.Results.ToString());
|
| | | if (results[0] == null)
|
| | | {
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.UpdateAppFail);
|
| | | return;
|
| | | return false;
|
| | | }
|
| | | var newVersion = results[0]["version"]?.ToString();
|
| | | var updateContent = results[0]["releaseNotes"]?.ToString();
|
| | | if (newVersion != CommonPage.CodeIDString)
|
| | | if (newVersion.CompareTo(CommonPage.CodeIDString) > 0)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | var alert = new Alert(Language.StringByID(R.MyInternationalizationString.UpdateContent), updateContent, Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim));
|
| | | alert.Show();
|
| | | alert.ResultEventHandler += (sender1, e1) =>
|
| | | {
|
| | | if (e1)
|
| | | {
|
| | | CommonPage.Instance.OpenUrl();
|
| | | }
|
| | | };
|
| | | });
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.TheAppVersionIsNewest), Language.StringByID(R.MyInternationalizationString.Close));
|
| | | alert.Show();
|
| | | });
|
| | | }
|
| | | return false;
|
| | | }
|
| | | catch
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | | }
|
| | | finally
|
| | | {
|
| | | CommonPage.Loading.Hide();
|
| | | }
|
| | | #elif Android
|
| | | try
|
| | | {
|
| | | CommonPage.Loading.Start();
|
| | | var versionResult = await CommonPage.Instance.RequestHttpsAndroidAppVersionAsync();
|
| | | var versionResult = await RequestHttpsAndroidAppVersionAsync();
|
| | | if (versionResult == null)
|
| | | {
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.UpdateAppFail);
|
| | | return;
|
| | | return false;
|
| | | }
|
| | | if (int.Parse(versionResult.FirmwareVersion.Replace(".","")) > int.Parse(CommonPage.CodeIDString.Replace(".","")))
|
| | | if (int.Parse(versionResult.FirmwareVersion.Replace(".", "")) > int.Parse(CommonPage.CodeIDString.Replace(".", "")))
|
| | | {
|
| | | var alert = new Alert(Language.StringByID(R.MyInternationalizationString.UpdateContent), versionResult.Remarks, Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim));
|
| | | alert.Show();
|
| | | alert.ResultEventHandler += async (sender1, e1) =>
|
| | | {
|
| | | if (e1)
|
| | | {
|
| | | try
|
| | | {
|
| | | SetDownLoadBtnVisible();
|
| | | var requestObj = new SendDataToServer.DownLoadAndroidApk
|
| | | {
|
| | | RequestVersion = CommonPage.RequestVersion,
|
| | | DistributedMark = versionResult.DistributedMark
|
| | | };
|
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj);
|
| | |
|
| | | var bytesTotalLengthResult = await CommonPage.Instance.RequestHttpsZigbeeAsync("FirmwareMana/DownloadPlatformUploadFirmwarePreLength", Encoding.UTF8.GetBytes(requestJson));
|
| | | if (bytesTotalLengthResult == null || bytesTotalLengthResult.ResponseData == null)
|
| | | {
|
| | | SetDownLoadBtnNoVisible();
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.UpdateAppFail);
|
| | | return;
|
| | | }
|
| | | var bytesTotalLength = Newtonsoft.Json.JsonConvert.DeserializeObject<long>(bytesTotalLengthResult.ResponseData.ToString());
|
| | | if (bytesTotalLength == 0)
|
| | | {
|
| | | SetDownLoadBtnNoVisible();
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.UpdateAppFail);
|
| | | return;
|
| | | }
|
| | | CommonPage.ApkBytesTotalLength = bytesTotalLength;
|
| | | var bytes = await CommonPage.Instance.DownLoadApkAsync("FirmwareMana/DownloadPlatformUploadFirmware", Encoding.UTF8.GetBytes(requestJson));
|
| | | if (bytes == null)
|
| | | {
|
| | | SetDownLoadBtnNoVisible();
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.UpdateAppFail);
|
| | | return;
|
| | | }
|
| | | if(bytes.ToString().Contains("DownloadFail"))
|
| | | {
|
| | | SetDownLoadBtnNoVisible();
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
|
| | | return;
|
| | | }
|
| | | var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, "home.apk");
|
| | | Shared.IO.FileUtils.WriteFileByBytes(path, bytes);
|
| | | Install(Shared.Application.Activity);
|
| | | }
|
| | | catch(Exception ex)
|
| | | {
|
| | | SetDownLoadBtnNoVisible();
|
| | | System.Console.WriteLine($"下载失败--{ex.Message}");
|
| | | }
|
| | | }
|
| | | };
|
| | | distributedMark = versionResult.DistributedMark;
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.TheAppVersionIsNewest), Language.StringByID(R.MyInternationalizationString.Close));
|
| | | alert.Show();
|
| | | }
|
| | | return false;
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | SetDownLoadBtnNoVisible();
|
| | | System.Console.WriteLine(ex.Message);
|
| | | }
|
| | | finally
|
| | | {
|
| | | CommonPage.Loading.Hide();
|
| | | return false;
|
| | | }
|
| | | #endif
|
| | | }
|
| | |
|
| | | #if Android
|
| | | /// <summary>
|
| | | /// Cancels down load apk.
|
| | | /// 更新
|
| | | /// </summary>
|
| | | private void CancelDownLoadApk(object sender,MouseEventArgs mouseEventArgs)
|
| | | private async void UpdateVersion()
|
| | | {
|
| | | var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.CancelUpdating), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim));
|
| | | alert.Show();
|
| | | alert.ResultEventHandler += (send, e) =>
|
| | | {
|
| | | if (e)
|
| | | {
|
| | | isUpdating = false;
|
| | | updateBtn.Visible = true;
|
| | | SetDownLoadBtnNoVisible();
|
| | | CommonPage.CancelDownLoadApkAsync();
|
| | | }
|
| | | };
|
| | | #if iOS
|
| | | OpenUrl();
|
| | | #elif Android
|
| | | try
|
| | | {
|
| | | var requestObj = new SendDataToServer.DownLoadAndroidApk
|
| | | {
|
| | | RequestVersion = CommonPage.RequestVersion,
|
| | | DistributedMark = distributedMark
|
| | | };
|
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj);
|
| | |
|
| | | var bytesTotalLengthResult = await CommonPage.Instance.RequestHttpsZigbeeAsync("FirmwareMana/DownloadPlatformUploadFirmwarePreLength", Encoding.UTF8.GetBytes(requestJson));
|
| | | if (bytesTotalLengthResult == null || bytesTotalLengthResult.ResponseData == null)
|
| | | {
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.UpdateAppFail);
|
| | | return;
|
| | | }
|
| | | var bytesTotalLength = Newtonsoft.Json.JsonConvert.DeserializeObject<long>(bytesTotalLengthResult.ResponseData.ToString());
|
| | | if (bytesTotalLength == 0)
|
| | | {
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.UpdateAppFail);
|
| | | return;
|
| | | }
|
| | | ApkBytesTotalLength = bytesTotalLength;
|
| | | var bytes = await DownLoadApkAsync("FirmwareMana/DownloadPlatformUploadFirmware", Encoding.UTF8.GetBytes(requestJson));
|
| | | if (bytes == null)
|
| | | {
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.UpdateAppFail);
|
| | | return;
|
| | | }
|
| | | if (bytes.ToString().Contains("DownloadFail"))
|
| | | {
|
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
|
| | | return;
|
| | | }
|
| | | var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, "home.apk");
|
| | | Shared.IO.FileUtils.WriteFileByBytes(path, bytes);
|
| | | Install(Shared.Application.Activity);
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | System.Console.WriteLine($"下载失败--{ex.Message}");
|
| | | }
|
| | | #endif
|
| | | }
|
| | |
|
| | | #if iOS
|
| | | /// <summary>
|
| | | /// 获取iOS-APP版本信息
|
| | | /// </summary>
|
| | | /// <returns>The https app version async.</returns>
|
| | | public async System.Threading.Tasks.Task<Common.ResponseEntity.ResultPack> RequestHttpsiOSAppVersionAsync()
|
| | | {
|
| | | try
|
| | | {
|
| | | var webClient = new WebClient { };
|
| | | var result = await webClient.DownloadDataTaskAsync("https://itunes.apple.com/lookup?id=1461693569");
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.ResultPack>(Encoding.UTF8.GetString(result));
|
| | | }
|
| | | catch
|
| | | {
|
| | | return null;
|
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 跳转到APP Store
|
| | | /// </summary>
|
| | | public void OpenUrl()
|
| | | {
|
| | | Uri url = new Uri("https://itunes.apple.com/cn/app/hdl-home/id1461693569?mt=8");
|
| | | UIKit.UIApplication.SharedApplication.OpenUrl(url);
|
| | | }
|
| | | #elif Android
|
| | |
|
| | | /// <summary>
|
| | | /// Install the specified context.
|
| | | /// </summary>
|
| | |
| | | }
|
| | | context.StartActivity(intent);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取 Android-APP 版本信息
|
| | | /// </summary>
|
| | | /// <returns>The https app version async.</returns>
|
| | | private async System.Threading.Tasks.Task<Common.ResponseEntity.ApkInfoOBJ> RequestHttpsAndroidAppVersionAsync()
|
| | | {
|
| | | try
|
| | | {
|
| | | var requestOBJ = new SendDataToServer.GetAndroidApkInfoOBJ
|
| | | {
|
| | | Name = "ZigbeeApp",
|
| | | RequestVersion = CommonPage.CodeIDString
|
| | | };
|
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestOBJ);
|
| | | var result = await CommonPage.Instance.RequestHttpsZigbeeAsync("FirmwareMana/DetectionPlatformUploadFirmware", System.Text.Encoding.UTF8.GetBytes(requestJson));
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | if (result.StateCode.ToUpper() == "SUCCESS")
|
| | | {
|
| | | if (result.ResponseData == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | var responeData = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.ApkInfoRes>(result.ResponseData.ToString());
|
| | | if (responeData == null || responeData.pageData == null || responeData.pageData.Count == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | int MaxIndex = 0;
|
| | | int NewVersion = 0;
|
| | | for (int i = 0; i < responeData.pageData.Count; i++)
|
| | | {
|
| | | var apkInfo = responeData.pageData[i];
|
| | | var version = int.Parse(apkInfo.FirmwareVersion.Replace(".", ""));
|
| | | if (version > NewVersion)
|
| | | {
|
| | | NewVersion = version;
|
| | | MaxIndex = i;
|
| | | }
|
| | | }
|
| | | return responeData.pageData[MaxIndex];
|
| | | }
|
| | | return null;
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 下载安装apk
|
| | | /// </summary>
|
| | | /// <returns>The load apk async.</returns>
|
| | | /// <param name="requestUrl">请求链接</param>
|
| | | /// <param name="byteData">请求参数</param>
|
| | | private System.Threading.Tasks.Task<byte[]> DownLoadApkAsync(string requestUrl, byte[] byteData)
|
| | | {
|
| | | try
|
| | | {
|
| | | webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
|
| | | webClient.Headers.Add(HttpRequestHeader.Authorization, Config.Instance.Token);
|
| | | webClient.UploadProgressChanged += Client_DownloadProgressChanged;
|
| | | webClient.UploadDataCompleted += Client_UploadCompleted;
|
| | | var result = webClient.UploadDataTaskAsync($"{CommonPage.RequestHttpsHost}/{requestUrl}", "POST", byteData);
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return result;
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | finally
|
| | | {
|
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// apk下载进度
|
| | | /// </summary>
|
| | | /// <param name="sender">Sender.</param>
|
| | | /// <param name="e">E.</param>
|
| | | void Client_DownloadProgressChanged(object sender, UploadProgressChangedEventArgs e)
|
| | | {
|
| | | //System.Console.WriteLine($"当前进度--{(int)(e.BytesReceived / (float)ApkBytesTotalLength * 100)} % --BytesReceived--{e.BytesReceived}--totalByte{e.TotalBytesToReceive}");
|
| | | if (e.BytesReceived <= ApkBytesTotalLength)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | SetDownLoadBtnVisible();
|
| | | btnUpdating.Text = $"{ Language.StringByID(R.MyInternationalizationString.Updating)} {(int)(e.BytesReceived / (float)ApkBytesTotalLength * 100)}%";
|
| | | });
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// Client_UploadCompleted
|
| | | /// </summary>
|
| | | /// <param name="sender"></param>
|
| | | /// <param name="e"></param>
|
| | | void Client_UploadCompleted(object sender, UploadDataCompletedEventArgs e)
|
| | | {
|
| | | System.Console.WriteLine("下载apk完成");
|
| | | SetDownLoadBtnNoVisible();
|
| | | }
|
| | | /// <summary>
|
| | | /// 取消下载apk
|
| | | /// </summary>
|
| | | private void CancelDownLoadApkAsync()
|
| | | {
|
| | | webClient?.CancelAsync();
|
| | | SetDownLoadBtnNoVisible();
|
| | | System.Console.WriteLine("取消下载apk");
|
| | | }
|
| | | #endif
|
| | |
|
| | | }
|
| | | }
|