From c44b10e4447e84dbdfa9105edf460ef364a8f2b3 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期一, 30 十一月 2020 19:53:35 +0800
Subject: [PATCH] Merge branch 'master' into WJC

---
 HDL_ON/Common/HDLCommon.cs |  156 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 135 insertions(+), 21 deletions(-)

diff --git a/HDL_ON/Common/HDLCommon.cs b/HDL_ON/Common/HDLCommon.cs
index f0295ef..43e137d 100644
--- a/HDL_ON/Common/HDLCommon.cs
+++ b/HDL_ON/Common/HDLCommon.cs
@@ -2,6 +2,8 @@
 using Shared;
 using HDL_ON;
 using HDL_ON.UI.CSS;
+using HDL_ON.DAL.Server;
+using HDL_ON.UI;
 
 namespace HDL_ON
 {
@@ -11,25 +13,25 @@
     /// </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寮圭獥鎻愮ず_______________________
@@ -50,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();
@@ -62,9 +65,120 @@
         #endregion
 
         #region 鈻� 閫氱敤Dialog_______________________
-       
+
         #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 = Newtonsoft.Json.JsonConvert.SerializeObject(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