From 0f2e0147e8990e913d16d99bc1b94fb6bc53abd7 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期四, 03 十二月 2020 15:35:42 +0800 Subject: [PATCH] 2020-12-03-1 --- HDL_ON/Common/HDLCommon.cs | 285 +++++++++++++++++++++++++++----------------------------- 1 files changed, 138 insertions(+), 147 deletions(-) diff --git a/HDL_ON/Common/HDLCommon.cs b/HDL_ON/Common/HDLCommon.cs index 95bf73c..df996d7 100644 --- a/HDL_ON/Common/HDLCommon.cs +++ b/HDL_ON/Common/HDLCommon.cs @@ -2,30 +2,36 @@ using Shared; using HDL_ON; using HDL_ON.UI.CSS; +using HDL_ON.DAL.Server; +using HDL_ON.UI; namespace HDL_ON { + /// <summary> + /// HDLCommon + /// 鏆傛椂娌$敤 + /// </summary> public class HDLCommon { - #region 鈻� 鍙橀噺澹版槑___________________________ - /// <summary> - /// 閫氱敤鏂规硶 - /// </summary> - private static HDLCommon m_Current = null; - /// <summary> - /// 閫氱敤鏂规硶 - /// </summary> - public static HDLCommon Current - { - get - { - if (m_Current == null) - { - m_Current = new HDLCommon(); - } - return m_Current; - } - } + #region 鈻� 鍙橀噺澹版槑___________________________ + /// <summary> + /// 閫氱敤鏂规硶 + /// </summary> + private static HDLCommon m_Current = null; + /// <summary> + /// 閫氱敤鏂规硶 + /// </summary> + public static HDLCommon Current + { + get + { + if (m_Current == null) + { + m_Current = new HDLCommon(); + } + return m_Current; + } + } #endregion #region 鈻� Alter寮圭獥鎻愮ず_______________________ @@ -46,7 +52,8 @@ public void ShowActionAlert(string mes, Action okAction) { Alert alert = new Alert("", mes, Language.StringByID(StringId.Cancel), Language.StringByID(StringId.Confirm)); - alert.ResultEventHandler += (sender2, e2) => { + alert.ResultEventHandler += (sender2, e2) => + { if (e2) { okAction?.Invoke(); @@ -58,136 +65,120 @@ #endregion #region 鈻� 閫氱敤Dialog_______________________ - /// <summary> - /// 鍔犺浇鎻愮ずDialog - /// </summary> - /// <param name="titleId"></param> - /// <param name="msgId"></param> - /// <param name="callBackAction"></param> - void ShowConfirmDialogBase(int titleId, int msgId, Action okAction, Action cancelAction, int cancelID = StringId.Cancel, int confirmID = StringId.Confirm) - { - Dialog dialog = new Dialog() - { - BackgroundColor = CSS_Color.DialogTransparentColor1, - }; - FrameLayout contentView = new FrameLayout() - { - Gravity = Gravity.Center, - Width = Application.GetRealWidth(270), - Height = Application.GetRealHeight(140), - BackgroundColor = CSS_Color.MainBackgroundColor, - BorderColor = 0x00000000, - BorderWidth = 0, - Radius = (uint)Application.GetMinRealAverage(10), - }; - dialog.AddChidren(contentView); - - Button btnTitle = new Button() - { - Y = Application.GetRealHeight(16), - Height = Application.GetRealHeight(30), - TextColor = CSS_Color.MainColor, - TextSize = CSS_FontSize.SubheadingFontSize, - TextAlignment = TextAlignment.Center, - IsBold = true, - TextID = titleId, - }; - contentView.AddChidren(btnTitle); - - Button btnMsg = new Button() - { - Gravity = Gravity.CenterHorizontal, - Height = Application.GetRealHeight(25), - Y = btnTitle.Bottom, - Width = Application.GetRealHeight(200), - TextAlignment = TextAlignment.Center, - TextColor = CSS_Color.TextualColor, - TextSize = CSS_FontSize.PromptFontSize_FirstLevel, - TextID = msgId, - }; - contentView.AddChidren(btnMsg); - - Button btnLine = new Button() - { - Y = Application.GetRealHeight(96), - Height = Application.GetRealHeight(1), - Width = Application.GetRealWidth(270 / 2), - BackgroundColor = CSS_Color.DividingLineColor, - }; - contentView.AddChidren(btnLine); - - Button btnCancel = new Button() - { - Y = btnLine.Bottom, - Width = Application.GetRealWidth(135), - Height = Application.GetRealHeight(43), - TextAlignment = TextAlignment.Center, - TextColor = CSS_Color.TextualColor, - TextSize = CSS_FontSize.SubheadingFontSize, - TextID = cancelID, - }; - contentView.AddChidren(btnCancel); - - Button btnConfirm = new Button() - { - X = btnCancel.Right, - Y = btnLine.Y, - Width = Application.GetRealWidth(135), - Height = Application.GetRealHeight(45), - TextAlignment = TextAlignment.Center, - //TextColor = CSS_Color.TextualColor, - TextSize = CSS_FontSize.SubheadingFontSize, - TextColor = CSS_Color.MainBackgroundColor, - BackgroundColor = CSS_Color.MainColor, - TextID = confirmID, - }; - contentView.AddChidren(btnConfirm); - //渚嬶細鍙充笅鍦嗚 澶у皬涓�50 - int mRectCornerID = HDLUtils.RectCornerBottomRight; - btnConfirm.SetCornerWithSameRadius((uint)Application.GetMinRealAverage(10), mRectCornerID); - dialog.Show(); - btnCancel.MouseUpEventHandler += (sender, e) => - { - dialog.Close(); - cancelAction?.Invoke(); - }; - - btnConfirm.MouseUpEventHandler += (sender, e) => - { - dialog.Close(); - okAction?.Invoke(); - }; - - } - - /// <summary> - /// 鍔犺浇鎻愮ずDialog - /// </summary> - /// <param name="titleId"></param> - /// <param name="msgId"></param> - /// <param name="callBackAction"></param> - public void ShowConfirmDialog(int titleId, int msgId, Action okAction, Action cancelAction = null) - { - ShowConfirmDialogBase(titleId, msgId, okAction, cancelAction); - } - - /// <summary> - /// 鍔犺浇鎻愮ずDialog - /// 鍙互鑷畾涔夋寜閽枃瀛� - /// </summary> - /// <param name="titleId"></param> - /// <param name="msgId"></param> - /// <param name="okAction"></param> - /// <param name="cancelAction"></param> - /// <param name="cancelID"></param> - /// <param name="confirmID"></param> - public void ShowConfirmDialog(int titleId, int msgId, Action okAction, Action cancelAction, int cancelID, int confirmID) - { - ShowConfirmDialogBase(titleId, msgId, okAction, cancelAction, cancelID, confirmID); - } #endregion + #region 妫�娴嬫洿鏂� + /// <summary> + /// 妫�娴嬫洿鏂扮嚎绋� + /// </summary> + public void CheckIfNeedForceUpdate() + { + System.Threading.Tasks.Task.Run(() => + { + try + { + var requestObj = new ForceUpdateObj() + { + LanguageType = Utlis.GetPostLanguageType() + }; +#if __IOS__ + requestObj.DeviceType = PhoneDeviceType.IOS.ToString(); +#endif + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_CheckAppVersion, requestJson); + if (revertObj.Code == StateCode.SUCCESS) + { + var mForceUpdateInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ForceUpdateInfo>(revertObj.Data.ToString()); + if (mForceUpdateInfo != null) + { + Application.RunOnMainThread(() => + { + ShowForceUpdateDialog(mForceUpdateInfo); + }); + } + } + else + { + Utlis.WriteLine("璇锋眰澶辫触"); + } + } + catch (Exception ex) + { + //Shared.Utlis.WriteLine (ex.ToString ()); + } + finally + { + } + + }); + + } + + /// <summary> + /// 鎻愮ず寮哄埗鏇存柊Dialog + /// 鐐瑰嚮纭璺宠浆娴忚鍣� + /// </summary> + public void ShowForceUpdateDialog(ForceUpdateInfo mForceUpdateInfo) + { + // 1.1 娌℃湁鏇存柊 杩斿洖 + if (mForceUpdateInfo.UpdateType == 0) return; + // 1.2 鏈夋柊鐗堟湰浣嗘槸蹇界暐杩� 杩斿洖 + if (mForceUpdateInfo.UpdateType == 1 && (UserInfo.Current.IgnoreUpdateVersion == mForceUpdateInfo.NewVersion)) return; + // 2.1 鏈夋柊鐗堟湰娌℃湁蹇界暐杩� 鎻愮ず鏇存柊 + if (mForceUpdateInfo.UpdateType == 1) + { + Action okAction = () => + { + if (string.IsNullOrEmpty(mForceUpdateInfo.NewVersionUrl)) return; + + HDLUtils.OpenUrl(mForceUpdateInfo.NewVersionUrl); + }; + + Action cancelAction = () => + { + //UserInfo.Current.IgnoreUpdateVersion = mForceUpdateInfo.NewVersion; + //UserInfo.Current.SaveUserInfo(); + }; + + //1鎻愮ず鏇存柊 + var dialog = new UpdateTipDialog(); + var tipStr = Language.StringByID(StringId.VersionNumber) + mForceUpdateInfo.NewVersion; + dialog.ShowUpdateDialog(Language.StringByID(StringId.DiscoverNewVersion), tipStr, mForceUpdateInfo.ReasonStr, okAction, cancelAction); + + } + else if (mForceUpdateInfo.UpdateType == 2) //2.2 闇�瑕佸己鍒舵洿鏂� + { + //2寮哄埗鏇存柊 + //"1.鍙戠幇鏂扮増鏈珹pp,褰撳墠鐗堟湰宸插仠鐢�,椹笂鏇存柊!\n2.璇蜂笅杞藉拰瀹夎鏂扮増鏈�!....." + Action okAction = () => + { + if (string.IsNullOrEmpty(mForceUpdateInfo.NewVersionUrl)) { + Utlis.ShowTip(Language.StringByID(StringId.DataExceptionPleaseTryAgain)); + return; + }; + + HDLUtils.OpenUrl(mForceUpdateInfo.NewVersionUrl); + }; + + //1鎻愮ず鏇存柊 + var dialog = new UpdateTipDialog(); + var tipStr = Language.StringByID(StringId.VersionNumber) + mForceUpdateInfo.NewVersion; + dialog.ShowForcedUpdateDialog(Language.StringByID(StringId.DiscoverNewVersion), tipStr, mForceUpdateInfo.ReasonStr, okAction); + } + else //3. 鍙渶鎻愮ず + { + //3鎻愮ず閫氱煡 + Action okAction = () => + { + + }; + var dialog = new UpdateTipDialog(); + dialog.ShowTipDialog(Language.StringByID(StringId.Tip), mForceUpdateInfo.ReasonStr, okAction); + } + } + + #endregion } } -- Gitblit v1.8.0