From 9ab5bd54fadd8fc9c542b48c99a117a4e182669b Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期四, 14 十月 2021 16:37:56 +0800
Subject: [PATCH] 智能空开能源界面数据更新

---
 HDL-ON_Android/Other/JPush/JPushReceiver.cs |  252 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 170 insertions(+), 82 deletions(-)

diff --git a/HDL-ON_Android/Other/JPush/JPushReceiver.cs b/HDL-ON_Android/Other/JPush/JPushReceiver.cs
index 61b99f9..9438176 100644
--- a/HDL-ON_Android/Other/JPush/JPushReceiver.cs
+++ b/HDL-ON_Android/Other/JPush/JPushReceiver.cs
@@ -1,34 +1,30 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
+锘�
+using System;
 using Android.App;
 using Android.Content;
-using Android.OS;
-using Android.Runtime;
-using Android.Views;
-using Android.Widget;
 using CN.Jpush.Android.Api;
 using CN.Jpush.Android.Service;
 using HDL_ON;
+using HDL_ON.DAL.Server;
 using Shared;
+using Android.OS;
 
 namespace HDL_ON_Android
-{
-    
+{
+
     [BroadcastReceiver(Enabled = true, Exported = false)]
     [Android.App.IntentFilter(new string[]
     {
         "cn.jpush.android.intent.RECEIVE_MESSAGE"
     },
-    Categories=new string[] 
+    Categories = new string[]
     {
         "com.hdl.onpro"
     })]
     public class JPushReceiver : JPushMessageReceiver
-    {
-
+    {
+
+
         private static string TAG = "JPushReceiver";
         /// <summary>
         /// 鐢ㄦ埛鐐瑰嚮鎵撳紑浜嗛�氱煡
@@ -38,13 +34,10 @@
         /// <param name="notificationMessage"></param>
         public override void OnNotifyMessageOpened(Context context, NotificationMessage notificationMessage)
         {
-            base.OnNotifyMessageOpened(context, notificationMessage);
+            //2020-12-23 瑙e喅鐐瑰嚮閫氱煡鏍忔墦寮�涓嶄簡APP闂
+            //base.OnNotifyMessageOpened(context, notificationMessage);
 
-            //App.Paras = p1.NotificationExtras;
-
-            //Utlis.ShowTip("鏀跺埌鎺ㄩ�侊細" + p1.NotificationExtras);
-            Utlis.WriteLine("鏋佸厜OnNotifyMessageOpened: " + notificationMessage.NotificationContent);
-            Utlis.WriteLine("鏋佸厜OnNotifyMessageOpened: " + notificationMessage.NotificationExtras);
+            OpenNotification(context, notificationMessage);
         }
 
         /// <summary>
@@ -55,9 +48,57 @@
         public override void OnNotifyMessageArrived(Context context, NotificationMessage notificationMessage)
         {
             base.OnNotifyMessageArrived(context, notificationMessage);
-            Utlis.WriteLine("鏋佸厜OnNotifyMessageArrived: " + notificationMessage.NotificationContent);
-            Utlis.WriteLine("鏋佸厜OnNotifyMessageArrived: " + notificationMessage.NotificationExtras);
+
+            var pushMes = new JPushMessageInfo()
+            {
+                Title = notificationMessage.NotificationTitle,
+                Content = notificationMessage.NotificationContent,
+                Extras = notificationMessage.NotificationExtras
+            };
+
+            var jpushExpandData = GetJPushExpandData(pushMes);
+            if (jpushExpandData != null && jpushExpandData.messageType != null)
+            {
+                pushMes.messageType = jpushExpandData.messageType;
+                pushMes.expantContent = jpushExpandData.expantContent;
+                pushMes.HomeId = jpushExpandData.homeId;
+                Utlis.WriteLine("PushMes messageType : " + pushMes.messageType);
+            }
+
+            Utlis.WriteLine("PushMes title : " + pushMes.Title);
+            Utlis.WriteLine("PushMes message : " + pushMes.Content);
+            Utlis.WriteLine("PushMes extras : " + pushMes.Extras);
+            Utlis.WriteLine("PushMes HomeId : " + pushMes.HomeId);
+
+            Shared.Application.RunOnMainThread(() =>
+            {
+                HDLCommon.Current.AdjustPushMessage(pushMes);
+            });
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="pushMes"></param>
+        /// <returns></returns>
+        static ExpandData GetJPushExpandData(JPushMessageInfo pushMes)
+        {
+            try
+            {
+                if (pushMes.Extras != null)
+                {
+                    var jpushExpandData = Newtonsoft.Json.JsonConvert.DeserializeObject<JPushExpandData>(pushMes.Extras.ToString());
+                    return Newtonsoft.Json.JsonConvert.DeserializeObject<ExpandData>(jpushExpandData.expandData);
+                }
+                return null;
+            }
+            catch
+            {
+                return null;
+            }
         }
+
 
         /// <summary>
         /// 娉ㄥ唽鎴愬姛鍥炶皟
@@ -67,82 +108,129 @@
         public override void OnRegister(Context context, string p1)
         {
             base.OnRegister(context, p1);
-
             Utlis.WriteLine("JPushOnRegister: " + p1);
         }
 
         ///// <summary>
-        ///// 鏀跺埌鑷畾涔夋秷鎭洖璋�
+        ///// 澶勭悊鏋佸厜淇℃伅鎺ㄩ��
         ///// </summary>
-        ///// <param name="p0"></param>
-        ///// <param name="p1"></param>
-        //public override void OnMessage(Context p0, CustomMessage p1)
+        ///// <param name="title">鏍囬</param>
+        ///// <param name="message">淇℃伅</param>
+        ///// <param name="extras">璐熻浇鏁版嵁</param>
+        //public void AdjustJiguangMsgPush(JPushMessageInfo JPushMessageInfo)
         //{
-        //    base.OnMessage(p0, p1);
+        //    try
+        //    {
+        //        if (JPushMessageInfo.Extras.Contains("Offline") == true)
+        //        {
+        //            Shared.Application.RunOnMainThread(() =>
+        //            {
+        //                //璐﹀彿鍦ㄥ埆澶勭櫥闄嗭紝琚涪涓嬬嚎 璺宠浆鍒扮櫥褰曢〉闈�
+        //                new Alert(Language.StringByID(StringId.Tip), Language.StringByID(StringId.LoggedOnOtherDevices), Language.StringByID(StringId.Close)).Show();
+        //                //2020-12-04 寰呭鍔犻��鍑虹櫥褰曟搷浣�
+        //            });
+        //            return;
+        //        }
+        //        else
+        //        {
+        //            Shared.Application.RunOnMainThread(() =>
+        //            {
+        //                new Alert(JPushMessageInfo.Title, JPushMessageInfo.Content, Language.StringByID(StringId.Close)).Show();
+        //            });
+        //            return;
 
-        //    Utlis.WriteLine("鏋佸厜OnMessage: " + p1.Message.ToString());
+        //        }
+        //    }
+        //    catch
+        //    {
+
+        //    }
         //}
 
-
         /// <summary>
-        /// 澶勭悊鏋佸厜淇℃伅鎺ㄩ��
+        /// 鎵撳紑娑堟伅鏄剧ず鐣岄潰.010000
         /// </summary>
-        /// <param name="title">鏍囬</param>
-        /// <param name="message">淇℃伅</param>
-        /// <param name="extras">璐熻浇鏁版嵁</param>
-        public void AdjustJiguangMsgPush(NotificationMessage notificationMessage)
-        {
-            string title = notificationMessage.NotificationTitle;
-            System.Console.WriteLine(TAG, " title : " + title);
-            string message = notificationMessage.NotificationContent;
-            System.Console.WriteLine(TAG, "message : " + message);
-            string extras = notificationMessage.NotificationExtras;
-            System.Console.WriteLine(TAG, "extras : " + extras);
-
-
-            if (extras.Contains("Offline") == true)
-            {
-
-                Shared.Application.RunOnMainThread(() =>
-                {
-                    //姝ゅ笎鍙峰凡鍦ㄥ埆澶勭櫥褰�,鎮ㄨ杩笅绾�
-                    //ShowAlert("姝ゅ笎鍙峰凡鍦ㄥ埆澶勭櫥褰�,鎮ㄨ杩笅绾�");
-                    //璐﹀彿鍦ㄥ埆澶勭櫥闄嗭紝琚涪涓嬬嚎 璺宠浆鍒扮櫥褰曢〉闈�
-                    HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
-
-                });
-                return;
-            }
-        }
-
-        /// <summary>
-        /// 鎵撳紑娑堟伅鏄剧ず鐣岄潰
-        /// </summary>
-        /// <param name="context">Context.</param>
-        /// <param name="bundle">Bundle.</param>
-        private void OpenNotification(Context context, Bundle bundle)
-        {
-
-            Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class);
-            i.PutExtras(bundle);
-            i.SetFlags(ActivityFlags.NewTask);
-            context.StartActivity(i);
-
-            String extras = bundle.GetString(JPushInterface.ExtraExtra);
-            //String myValue = "";
+        /// <param name="context"></param>
+        /// <param name="notificationMessage"></param>
+        public static void OpenNotification(Context context, NotificationMessage notificationMessage)
+        {
+
             try
             {
-               
+                var pushMes = new JPushMessageInfo()
+                {
+                    Title = notificationMessage.NotificationTitle,
+                    Content = notificationMessage.NotificationContent,
+                    Extras = notificationMessage.NotificationExtras
+                };
 
+                var jpushExpandData = GetJPushExpandData(pushMes);
+                if (jpushExpandData != null && jpushExpandData.messageType != null)
+                {
+                    pushMes.messageType = jpushExpandData.messageType;
+                    pushMes.expantContent = jpushExpandData.expantContent; ;
+                    pushMes.HomeId = jpushExpandData.homeId;
+                    Utlis.WriteLine("PushMes messageType : " + pushMes.messageType);
+                }
+
+                Utlis.WriteLine("PushMes title : " + pushMes.Title);
+                Utlis.WriteLine("PushMes message : " + pushMes.Content);
+                Utlis.WriteLine("PushMes extras : " + pushMes.Extras);
+                Utlis.WriteLine("PushMes HomeId : " + pushMes.HomeId);
+
+
+                Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class);
+                i.SetFlags(ActivityFlags.NewTask);
+                context.StartActivity(i);
+                //瑙f瀽msg
+                AdjustPushMessage(pushMes);
+
+                //Shared.Application.RunOnMainThread(() =>
+                //{
+                //    if (Shared.Application.Activity == null)
+                //    {
+                //        var tempIntent = new Intent(context, typeof(Shared.BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class);
+                //        tempIntent.SetFlags(ActivityFlags.BroughtToFront);
+                //        context.StartActivity(tempIntent);
+
+                //        HDLCommon.Current.AdjustPushMessage(pushMes);
+                //    }
+                //    else
+                //    {
+
+                //        (Shared.Application.Activity as BaseActivity).MoveToFront();
+                //        HDLCommon.Current.AdjustPushMessage(pushMes);
+                //    }
+                //});
             }
-            catch (Exception e)
+            catch
             {
-                System.Console.WriteLine("JPush", "Unexpected: extras is not a valid json", e);
-                return;
-            }
 
-           
+            }
+            //catch (Exception ex)
+            //{
+            //    Utlis.WriteLine(ex.ToString());
+            //}
         }
-    }
-    
+
+
+
+        public static void AdjustPushMessage(JPushMessageInfo pushMes)
+        {
+
+            new System.Threading.Thread(new System.Threading.ThreadStart(() =>
+            {
+                while (MainPage.BasePageView == null)
+                {
+                    System.Threading.Thread.Sleep(300);
+                }
+                Shared.Application.RunOnMainThread(() =>
+                {
+                    HDLCommon.Current.AdjustPushMessage(pushMes);
+                });
+            })).Start();
+
+        }
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.8.0