using System; using Shared; using HDL_ON.UI.CSS; using System.Net; using System.Text; using HDL_ON.DAL.Server; using System.Threading.Tasks; namespace HDL_ON.UI { public class AboutOnPage : FrameLayout { FrameLayout bodyView; public AboutOnPage() { bodyView = this; } public void LoadPage() { new TopViewDiv(bodyView, Language.StringByID(StringId.About)).LoadTopView(); Button btnOnIcon = new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealWidth(106), Width = Application.GetRealWidth(58), Height = Application.GetRealWidth(58), UnSelectedImagePath = "OnIcon.png", }; bodyView.AddChidren(btnOnIcon); Button btnOnTitle = new Button() { //Gravity = Gravity.CenterHorizontal, Y = Application.GetRealWidth(184), Height = Application.GetRealWidth(28), TextAlignment = TextAlignment.Center, Text = "ON+", TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.EmphasisFontSize_Secondary, IsBold = true, }; bodyView.AddChidren(btnOnTitle); Button btnOnVersion = new Button() { Y = btnOnTitle.Bottom, Height = Application.GetRealWidth(25), TextAlignment = TextAlignment.Center, TextColor = CSS_Color.TextualColor, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, Text = Language.StringByID(StringId.VersionNumber) + " " + MainPage.VersionString, }; bodyView.AddChidren(btnOnVersion); var lineView = new FrameLayout() { Y = Application.GetRealHeight(281), Height = Application.GetRealHeight(1), BackgroundColor = CSS_Color.DividingLineColor, }; bodyView.AddChidren(lineView); #region 功能介绍 var functionView = new ListCellView() { Y = lineView.Bottom, }; bodyView.AddChidren(functionView); functionView.btnTilte.TextID = StringId.FunctionIntroduced; Action functionAction = () => { var mPage = new FunctionIntroductionPage(); MainPage.BasePageView.AddChidren(mPage); mPage.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; functionView.goAction = functionAction; #endregion #region 投诉 var complaintsView = new ListCellView() { Y = functionView.Bottom, }; bodyView.AddChidren(complaintsView); complaintsView.btnTilte.TextID = StringId.Complaints; Action complaintsAction = () => { var mPage = new ComplaintsPage(); MainPage.BasePageView.AddChidren(mPage); mPage.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; complaintsView.goAction = complaintsAction; #endregion #region 版本更新 var versionUpdateView = new ListCellView() { Y = complaintsView.Bottom, }; bodyView.AddChidren(versionUpdateView); versionUpdateView.btnTilte.TextID = StringId.VersionUpdate; Action versionUpdateAction = () => { CheckIfNeedUpdateAsync(); }; versionUpdateView.goAction = versionUpdateAction; #endregion } /// /// 检测是否需要更新 /// /// void CheckIfNeedUpdateAsync() { new System.Threading.Thread(() => { var newVersion = CanUpdateAsync(); Application.RunOnMainThread(() => { if (!string.IsNullOrEmpty(newVersion)) { Action okAction = () => { OpenUrl(); }; var mesStr = Language.StringByID(StringId.DiscoverNewVersion) + "(" + newVersion + ")"; new ConfirmDialog().ShowDialog(Language.StringByID(StringId.Tip), mesStr, okAction, null, StringId.Cancel, StringId.Update); } else { Utlis.ShowTip(Language.StringByID(StringId.IsLatestVersion)); } }); }) { IsBackground = true }.Start(); } /// /// 检查版本 /// /// string CanUpdateAsync() { #if __IOS__ try { var versionResult = RequestHttpsiOSAppVersionAsync(); if (versionResult == null || versionResult.Results == null) { return ""; } var results = Newtonsoft.Json.Linq.JArray.Parse(versionResult.Results.ToString()); if (results[0] == null) { return ""; } var newVersion = results[0]["version"]?.ToString(); //var updateContent = results[0]["releaseNotes"]?.ToString(); if (newVersion.CompareTo(MainPage.VersionString) > 0) { return newVersion; } return ""; } catch { return ""; } #else try { var versionResult = GetAndroidAppVersion(); if (versionResult == null) { return ""; } var newVersion = versionResult.AndroidVersion; if (newVersion.CompareTo(MainPage.VersionString) > 0) { AndroidUrl = versionResult.AndroidUrl; return newVersion; } return ""; } catch (Exception ex) { return ""; } #endif } #if __IOS__ /// /// 获取iOS-APP版本信息 /// /// The https app version async. ResultPack RequestHttpsiOSAppVersionAsync() { try { var webClient = new WebClient { }; var result = webClient.DownloadData("https://itunes.apple.com/cn/lookup?id=1532353432"); if (result == null) { return null; } return Newtonsoft.Json.JsonConvert.DeserializeObject(Encoding.UTF8.GetString(result)); } catch { return null; } } /// /// 跳转到APP Store /// void OpenUrl() { HDLUtils.OpenUrl("https://apps.apple.com/cn/app/on/id1532353432"); } #else string AndroidUrl = ""; /// /// 跳转到Android 下载地址 /// void OpenUrl() { HDLUtils.OpenUrl(AndroidUrl); } /// /// 获取 Android-APP 版本信息 /// /// The https app version async. private APPVersion GetAndroidAppVersion() { try { var result = new HttpServerRequest().GetAppVersion(); if (result.Code == StateCode.SUCCESS) { if (result.Data == null) { return null; } var responeData = Newtonsoft.Json.JsonConvert.DeserializeObject(result.Data.ToString()); return responeData; } return null; } catch (Exception ex) { return null; } } #endif } [System.Serializable] public class ResultPack { public int ResultCount { get; set; } public object Results { get; set; } } }