wxr
2024-12-02 f60b17fa18701c2cee017a5117e96510f54b44cf
HDL_ON/UI/UI2/1-HomePage/MessageCenterPage.cs
@@ -4,9 +4,7 @@
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
//#if DEBUG
//using Xamarin.Essentials;
//#endif
namespace HDL_ON.UI
{
    /// <summary>
@@ -81,9 +79,6 @@
            AddMessageView();
            MenuButtonSelect(showMesType);
            RegisterGetPushMessageAction();
            //测试代码
            //AddEmptyTipView();
            //TestLoad();
        }
        /// <summary>
@@ -91,10 +86,9 @@
        /// </summary>
        void AddTopMenuView()
        {
            menuView = new HorizontalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64+10),
                Y = Application.GetRealHeight(64 + 10),
                Height = Application.GetRealWidth(117),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                HorizontalScrollBarEnabled = false//隐藏滚动条
@@ -126,10 +120,10 @@
            //测试提前当前推送ID
            allMenuButton.ImageButton.MouseLongEventHandler = (sender, e) =>
            {
//#if DEBUG
                //#if DEBUG
//                CopyToClipboard("推送ID:" + OnAppConfig.Instance.PushId);
//#else
                //                CopyToClipboard("推送ID:" + OnAppConfig.Instance.PushId);
                //#else
                //检测是否获取推送ID成功,提示推送注册是否正常
                if (string.IsNullOrEmpty(OnAppConfig.Instance.PushId))
                {
@@ -139,7 +133,7 @@
                {
                    Utlis.ShowTip(Language.StringByID(StringId.PushNormal));
                }
//#endif
                //#endif
            };
            #endregion
@@ -202,7 +196,7 @@
                X = systemMenuButton.Right,
                Y = Application.GetRealWidth(16),
            };
            menuView.AddChidren(propertyMenuButton);
            menuView.AddChidren(propertyMenuButton);
            propertyMenuButton.ImageButton.SelectedImagePath = "Collection/MesCenter/PropertyOn.png";
            propertyMenuButton.ImageButton.UnSelectedImagePath = "Collection/MesCenter/Property.png";
            propertyMenuButton.TextButton.TextID = StringId.Propertynotice;
@@ -304,8 +298,6 @@
            GetPushMessageList(showMesType);
        }
        /// <summary>
        /// 添加内容为空提示页面
        /// </summary>
@@ -338,7 +330,7 @@
        {
            var rowView = new RowLayout()
            {
                Height = Application.GetRealHeight(65),
                Height = Application.GetRealWidth(76),
                LineColor = CSS_Color.MainBackgroundColor,
            };
            VerticalScrolViewMiddle.AddChidren(rowView);
@@ -347,29 +339,29 @@
            var btnTilte = new TextButton()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(12),
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealWidth(20),
                Width = Application.GetRealWidth(258),
                Height = Application.GetRealWidth(20 + 23),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                Text = pushMessageInfo.messageContent,
                //IsMoreLines = true,
                IsMoreLines = true,
            };
            rowView.AddChidren(btnTilte);
            //
            var needHeight = btnTilte.GetMoreLineNeedHeight();
            btnTilte.IsMoreLines = true;
            btnTilte.Height = needHeight;
            rowView.Height = Application.GetRealHeight(45) + needHeight;
            //var needHeight = btnTilte.GetMoreLineNeedHeight();
            //btnTilte.IsMoreLines = true;
            //btnTilte.Height = needHeight;
            //rowView.Height = Application.GetRealWidth(45) + needHeight;
            //副标题
            var btnSubtitle = new TextButton()
            {
                X = Application.GetRealWidth(16),
                Y = btnTilte.Bottom + Application.GetRealHeight(4),
                Width = Application.GetRealWidth(240),
                Height = Application.GetRealHeight(17),
                Y = btnTilte.Bottom + Application.GetRealWidth(4),
                Width = Application.GetRealWidth(258),
                Height = Application.GetRealWidth(17),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
@@ -406,8 +398,6 @@
            {
                DeleteThePush(pushMessageInfo, rowView);
            };
            btnDatetime.Text = GetUnixToDateTime2(pushMessageInfo.createTime);
            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
@@ -419,6 +409,55 @@
            btnTilte.MouseUpEventHandler = eventHandler;
            btnSubtitle.MouseUpEventHandler = eventHandler;
            if (!string.IsNullOrEmpty(pushMessageInfo.messageExpandInfo.ExpantContentInfo.picUrl) &&
                pushMessageInfo.messageExpandInfo.ExpantContentInfo.picUrl != "null")
            {
                ImageView imageView = new ImageView()
                {
                    X = Application.GetRealWidth(291),
                    Y = Application.GetRealWidth(8),
                    Width = Application.GetRealWidth(52),
                    Height = Application.GetRealWidth(32),
                    Radius = (uint)Application.GetRealWidth(4),
                    BorderColor = 0x00FFFFFF,
                    BorderWidth = 1,
                    ImagePath = "Collection/MesCenter/default_image.png"
                };
                rowView.AddChidren(imageView);
                imageView.MouseUpEventHandler = (sender, e) => {
                    Dialog dialog = new Dialog();
                    var dialogView = new FrameLayout();
                    dialog.AddChidren(dialogView);
                    dialogView.MouseUpEventHandler = (sender, e) => {
                        dialog.Close();
                    };
                    var dialogContentView = new ImageView()
                    {
                        Width = Application.GetRealWidth(375),
                        Height = Application.GetRealWidth(211),
                        ImageBytes = imageView.ImageBytes,
                        Gravity = Gravity.Center,
                    };
                    dialogView.AddChidren(dialogContentView);
                    dialog.Show();
                };
                new Thread(() => {
                    var headImageBytes = HttpUtil.HttpsDownload(pushMessageInfo.messageExpandInfo.ExpantContentInfo.picUrl);
                    if (headImageBytes != null && headImageBytes.Length > 0)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            imageView.ImageBytes = headImageBytes;
                        });
                    }
                })
                { IsBackground = true }.Start();
            }
        }
@@ -570,6 +609,7 @@
                    {
                        //PushMessageInfoList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PushMessageInfo>>(result.Data.ToString());
                        //2021-08-28 改为分页接口
                        MainPage.Log(result.Data.ToString());
                        var mPushMesList = Newtonsoft.Json.JsonConvert.DeserializeObject<PushMessageInfoList>(result.Data.ToString());
                        if (mPushMesList != null)
                        {
@@ -580,7 +620,6 @@
                        {
                            if (PushMessageInfoList != null && PushMessageInfoList.Count > 0)
                            {
                                ParseAndDisplayPushList();
                                PushSerivceMarkAllMessageRead();
                            }
@@ -601,6 +640,7 @@
                }
                catch (Exception ex)
                {
                    MainPage.Log("Error", $"获取推送消息列表异常:{ex.StackTrace}");
                }
                finally
                {
@@ -622,6 +662,7 @@
        /// </summary>
        void ParseAndDisplayPushList()
        {
            bodyScrolView.RemoveAll();
            foreach (var info in PushMessageInfoList)
            {
                //年份解析 判断是否需要添加年份标题
@@ -694,18 +735,23 @@
        /// <param name="pushMessageInfo"></param>
        void OnClickPushMessageInfo(PushMessageInfo pushMessageInfo)
        {
            if (pushMessageInfo.pushType == PushType.Notice.ToString())
            {
                //Utlis.WriteLine("物业通知");
                string noticeId = GetNoticeId(pushMessageInfo.messageExpand);
                if (!string.IsNullOrEmpty(noticeId))
                try
                {
                    GetPropertyNoticeDetails(noticeId);
                    //Utlis.WriteLine("物业通知");
                    if (!string.IsNullOrEmpty(pushMessageInfo.messageExpand))
                    {
                        GetPropertyNoticeDetails(pushMessageInfo.messageExpandInfo.targetId);
                    }
                    else
                    {
                        Utlis.WriteLine("noticeId null");
                    }
                }
                else
                catch (Exception ex)
                {
                    Utlis.WriteLine("noticeId null");
                    MainPage.Log("Error", $"通知信息点击事件:{ex.StackTrace}");
                }
            }
            else
@@ -713,112 +759,6 @@
                Utlis.WriteLine("其它通知类型");
            }
        }
        /// <summary>
        /// 解析messageExpand 提取targetId
        /// </summary>
        /// <param name="messageExpand"></param>
        /// <returns></returns>
        string GetNoticeId(string messageExpand)
        {
            try
            {
                if (!string.IsNullOrEmpty(messageExpand))
                {
                    var mMessageExpandInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<MessageExpandInfo>(messageExpand);
                    if (mMessageExpandInfo != null)
                    {
                        var mExpantContentInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ExpantContentInfo>(mMessageExpandInfo.expantContent);
                        if(mExpantContentInfo != null)
                        {
                            return mExpantContentInfo.targetId;
                        }
                    }
                }
                return null;
            }
            catch
            {
                return null;
            }
        }
        #region 测试
#if DEBUG
        /// <summary>
        ///
        /// </summary>
        void TestLoad()
        {
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息",
                messageContent = "门锁被打开",
                createTime = 1606900275,
            });
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息1",
                messageContent = "门锁被打开",
                createTime = 1606895454,
            });
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息2",
                messageContent = "门锁被打开",
                createTime = 1606895454,
            });
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息2019",
                messageContent = "门锁被打开",
                createTime = 1575277874,
            });
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息2019",
                messageContent = "门锁被打开",
                createTime = 1572685874,
            });
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息2018",
                messageContent = "门锁被打开",
                createTime = 1541149874,
            });
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息2017",
                messageContent = "门锁被打开",
                createTime = 1509613874,
            });
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息2017",
                messageContent = "门锁被打开",
                createTime = 1509613874,
            });
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息2017",
                messageContent = "门锁被打开",
                createTime = 1506935474,
            });
            ParseAndDisplayPushList();
        }
#endif
        #endregion
        /// <summary>
        /// 标记所有推送消息已读
@@ -836,8 +776,6 @@
                {
                    Utlis.WriteLine("标记失败");
                }
            })
            { IsBackground = true }.Start();
        }
@@ -851,7 +789,6 @@
            {
                if (bodyView != null)
                {
                    //Utlis.WriteLine("GetPushMessageAction M收到推送");
                    GetPushMessageList(showMesType);
                }
@@ -865,19 +802,6 @@
        {
            HDLCommon.GetPushMessageAction = null;
        }
//#if DEBUG
//        /// <summary>
//        /// 复制到剪切板
//        /// </summary>
//        /// <param name="text"></param>
//        void CopyToClipboard(string text)
//        {
//            Clipboard.SetTextAsync(text);
//            Utlis.ShowTip(text + "\n" + Language.StringByID(StringId.CopySuccess));
//        }
//#endif
    }
@@ -913,6 +837,25 @@
        /// 扩展数据
        /// </summary>
        public string messageExpand;
        MessageExpand _messageExpandInfo;
        public MessageExpand messageExpandInfo
        {
            get
            {
                if (_messageExpandInfo == null)
                {
                    if (!string.IsNullOrEmpty(messageExpand))
                    {
                        _messageExpandInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<MessageExpand>(messageExpand);
                    }
                    else
                    {
                        _messageExpandInfo = new MessageExpand();
                    }
                }
                return _messageExpandInfo;
            }
        }
        ///// <summary>
        ///// 消息类型;0:提示;1:报警;2:丰林可是对讲呼叫;3:强制下线推送
        ///// </summary>
@@ -927,6 +870,59 @@
        public long createTime;
    }
    [System.Serializable]
    public class MessageExpand
    {
        /// <summary>
        /// 扩展数据内容
        /// </summary>
        public string expantContent;
        private ExpantContent _expantContent;
        public ExpantContent ExpantContentInfo
        {
            get
            {
                if (_expantContent == null)
                {
                    if (!string.IsNullOrEmpty(expantContent))
                    {
                        _expantContent = Newtonsoft.Json.JsonConvert.DeserializeObject<ExpantContent>(expantContent);
                    }
                    else
                    {
                        _expantContent = new ExpantContent();
                    }
                }
                return _expantContent;
            }
        }
        public string homeId;
        public int messageLevel;
        public string messageType;
        public string targetId;
    }
    [System.Serializable]
    public class ExpantContent
    {
        public string currentTime;
        public string picUrl;
        public string devSerial;
        public string interphoneTypeEnum;
        public string subToken;
        public string deviceSid;
        public string msgId;
        public string type;
        public string pushTime;
        public string extDevId;
        public string deviceId;
        public string spk;
    }
    /// <summary>
    // 推送消息分页对象
@@ -964,29 +960,8 @@
    [System.Serializable]
    public class MessageExpandInfo
    {
        /// <summary>
        /// expantContent
        /// </summary>
        public string expantContent;
    }
    /// <summary>
    /// 推送扩展信息
    /// </summary>
    [System.Serializable]
    public class ExpantContentInfo
    {
        /// <summary>
        /// targetId
        /// </summary>
        public string targetId;
        /// <summary>
        /// messageType
        /// </summary>
        public string messageType;
    }
}
}