From a7ab4b610972e20753dfedb3e5d80e4d9f017d07 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期五, 14 八月 2020 10:39:08 +0800 Subject: [PATCH] 临时备份,测试1 --- ZigbeeApp/Shared/Phone/UserCenter/Abount/AbountForm.cs | 475 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 475 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Abount/AbountForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Abount/AbountForm.cs new file mode 100755 index 0000000..862f8f5 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/Abount/AbountForm.cs @@ -0,0 +1,475 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Net; +using System.Text; +using Shared.Common; + +namespace Shared.Phone.UserCenter.Abount +{ + /// <summary> + /// 鍏充簬鐨勭敾闈� + /// </summary> + public class AbountForm : EditorCommonForm + { + #region 鈼� 鍙橀噺____________________________ + /// <summary> + /// 鏄惁姝e湪鏇存柊涓� + /// </summary> + public bool isUpdating; + /// <summary> + /// The web client. + /// </summary> + public WebClient webClient = new WebClient { }; + /// <summary> + /// 鏇存柊涓� + /// </summary> + public NormalViewControl btnUpdating; + /// <summary> + /// distributedMark + /// </summary> + public string distributedMark; + /// <summary> + /// updateRow + /// </summary> + public FrameRowControl rowUpdate; + /// <summary> + /// 涓嬭浇瀹夊崜apk鐨刡yte闀垮害 + /// </summary> + public long ApkBytesTotalLength = 0; + + #endregion + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + public void ShowForm() + { + //璁剧疆鏍囬淇℃伅 + base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAboutMe)); + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + } + /// <summary> + /// Closes the form. + /// </summary> + public override void CloseFormBefore() + { +#if Android + 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); + //Evoyo Home + var btnName = new NormalViewControl(700, 60, true); + btnName.Y = Application.GetRealHeight(294); + btnName.Gravity = Gravity.CenterHorizontal; + btnName.Text = "Evoyo 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) => + { + 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 (result) + { + //鏇存柊鏈�鏂扮増 + btnRightView.TextID = R.MyInternationalizationString.Update; + rowUpdate.CanClick = true; + } + else + { + btnRightView.TextID = R.MyInternationalizationString.TheAppVersionIsNewest; + } + }); + + }); + } + + /// <summary> + /// 璁剧疆杩涘害鎺т欢涓嶅彲瑙� + /// </summary> + private void SetDownLoadBtnNoVisible() + { + isUpdating = false; + btnUpdating.Visible = false; + } + /// <summary> + /// 璁剧疆杩涘害鎺т欢鍙 + /// </summary> + private void SetDownLoadBtnVisible() + { + isUpdating = true; + btnUpdating.Visible = true; + rowUpdate.CanClick = false; + } + + /// <summary> + /// 妫�鏌ョ増鏈� + /// </summary> + /// <returns></returns> + private async System.Threading.Tasks.Task<bool> CanUpdateAsync() + { +#if iOS + try + { + var versionResult = await RequestHttpsiOSAppVersionAsync(); + if (versionResult == null || versionResult.Results == null) + { + return false; + } + var results = Newtonsoft.Json.Linq.JArray.Parse(versionResult.Results.ToString()); + if (results[0] == null) + { + return false; + } + var newVersion = results[0]["version"]?.ToString(); + var updateContent = results[0]["releaseNotes"]?.ToString(); + if (newVersion.CompareTo(CommonPage.CodeIDString) > 0) + { + return true; + } + return false; + } + catch + { + return false; + } + +#elif Android + try + { + var versionResult = RequestHttpsAndroidAppVersionAsync(); + if (versionResult == null) + { + return false; + } + if (int.Parse(versionResult.FirmwareVersion.Replace(".", "")) > int.Parse(CommonPage.CodeIDString.Replace(".", ""))) + { + distributedMark = versionResult.DistributedMark; + return true; + } + return false; + } + catch (Exception ex) + { + return false; + } +#endif + } + + /// <summary> + /// 鏇存柊 + /// </summary> + private async void UpdateVersion() + { +#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 = 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> + /// 璺宠浆鍒癆PP 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> + /// <param name="context">Context.</param> + private static void Install(Android.Content.Context context) + { + + //var file = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads), "home.apk"); + var file = new Java.IO.File(System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, "home.apk")); + var intent = new Android.Content.Intent(Android.Content.Intent.ActionInstallPackage); + // 鐢变簬娌℃湁鍦ˋctivity鐜涓嬪惎鍔ˋctivity,璁剧疆涓嬮潰鐨勬爣绛� + intent.SetFlags(Android.Content.ActivityFlags.NewTask); + + if (Android.OS.BuildVersionCodes.M < Android.OS.Build.VERSION.SdkInt) + { + //鍙傛暟1 涓婁笅鏂�, 鍙傛暟2 Provider涓绘満鍦板潃 鍜岄厤缃枃浠朵腑淇濇寔涓�鑷� 鍙傛暟3 鍏变韩鐨勬枃浠� + var apkUri = Android.Support.V4.Content.FileProvider.GetUriForFile(context, "com.evoyo.home.fileProvider", file); + //娣诲姞杩欎竴鍙ヨ〃绀哄鐩爣搴旂敤涓存椂鎺堟潈璇ri鎵�浠h〃鐨勬枃浠� + intent.AddFlags(Android.Content.ActivityFlags.GrantReadUriPermission); + intent.SetDataAndType(apkUri, "application/vnd.android.package-archive"); + } + else + { + intent.SetDataAndType(Android.Net.Uri.FromFile(file), "application/vnd.android.package-archive"); + } + context.StartActivity(intent); + } + + /// <summary> + /// 鑾峰彇 Android-APP 鐗堟湰淇℃伅 + /// </summary> + /// <returns>The https app version async.</returns> + private Common.ResponseEntity.ApkInfoOBJ RequestHttpsAndroidAppVersionAsync() + { + try + { + var requestOBJ = new SendDataToServer.GetAndroidApkInfoOBJ + { + Name = "ZigbeeApp", + RequestVersion = CommonPage.CodeIDString + }; + var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestOBJ); + var result = 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 + + } +} -- Gitblit v1.8.0