using System;
|
using Shared;
|
using HDL_ON.UI.CSS;
|
using System.Collections.Generic;
|
using System.Threading;
|
using HDL_ON.DAL.Server;
|
#if DEBUG
|
using Xamarin.Essentials;
|
#endif
|
namespace HDL_ON.UI
|
{
|
/// <summary>
|
/// 信息中心页面
|
/// </summary>
|
public class MessageCenterPage : FrameLayout
|
{
|
FrameLayout bodyView;
|
/// <summary>
|
/// 当前
|
/// </summary>
|
VerticalScrolViewLayout bodyScrolView;
|
/// <summary>
|
/// 内容为空提示View
|
/// </summary>
|
FrameLayout emptyTipView;
|
|
/// <summary>
|
/// menuView
|
/// </summary>
|
FrameLayout menuView;
|
MenuButton allMenuButton;
|
MenuButton shareMenuButton;
|
MenuButton alarmMenuButton;
|
MenuButton systemMenuButton;
|
FrameLayout messageView;
|
|
/// <summary>
|
/// 显示的消息类型
|
/// 0全部 1分享与功能 2报警类 3系统信息
|
/// </summary>
|
int showMesType = 0;
|
/// <summary>
|
/// 推送消息列表
|
/// </summary>
|
List<PushMessageInfo> PushMessageInfoList = new List<PushMessageInfo>();
|
|
/// <summary>
|
/// 页面关闭时间
|
/// </summary>
|
Action backAction;
|
|
public override void RemoveFromParent()
|
{
|
UnregisterGetPushMessageAction();
|
base.RemoveFromParent();
|
backAction?.Invoke();
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public MessageCenterPage()
|
{
|
bodyView = this;
|
BackgroundColor = CSS_Color.BackgroundColor;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="backAction"></param>
|
public void LoadPage(Action backAction)
|
{
|
this.backAction = backAction;
|
new TopViewDiv(bodyView, Language.StringByID(StringId.MessageCenter)).LoadTopView();
|
|
AddTopMenuView();
|
AddMessageView();
|
MenuButtonSelect(showMesType);
|
RegisterGetPushMessageAction();
|
//测试代码
|
//AddEmptyTipView();
|
//TestLoad();
|
}
|
|
/// <summary>
|
/// 顶部菜单选项
|
/// </summary>
|
void AddTopMenuView()
|
{
|
|
menuView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(64),
|
Height = Application.GetRealWidth(117),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
bodyView.AddChidren(menuView);
|
|
|
#region 全部按钮
|
allMenuButton = new MenuButton()
|
{
|
X = Application.GetRealWidth(15),
|
Y = Application.GetRealWidth(16),
|
};
|
menuView.AddChidren(allMenuButton);
|
allMenuButton.ImageButton.SelectedImagePath = "Collection/MesCenter/AllOn.png";
|
allMenuButton.ImageButton.UnSelectedImagePath = "Collection/MesCenter/All.png";
|
allMenuButton.TextButton.TextID = StringId.All;
|
Action allAction = () =>
|
{
|
MenuButtonSelect(0);
|
};
|
allMenuButton.SelectAction = allAction;
|
//测试提前当前推送ID
|
allMenuButton.ImageButton.MouseLongEventHandler = (sender, e) =>
|
{
|
#if DEBUG
|
|
CopyToClipboard("推送ID:" + OnAppConfig.Instance.PushId);
|
#else
|
//检测是否获取推送ID成功,提示推送注册是否正常
|
if (string.IsNullOrEmpty(OnAppConfig.Instance.PushId))
|
{
|
Utlis.ShowTip(Language.StringByID(StringId.PushException));
|
}
|
else
|
{
|
Utlis.ShowTip(Language.StringByID(StringId.PushNormal));
|
}
|
#endif
|
|
};
|
#endregion
|
|
#region 分享与功能
|
shareMenuButton = new MenuButton()
|
{
|
X = allMenuButton.Right,
|
Y = Application.GetRealWidth(16),
|
};
|
menuView.AddChidren(shareMenuButton);
|
shareMenuButton.ImageButton.SelectedImagePath = "Collection/MesCenter/ShareOn.png";
|
shareMenuButton.ImageButton.UnSelectedImagePath = "Collection/MesCenter/Share.png";
|
shareMenuButton.TextButton.TextID = StringId.SharingAndFunctionality;
|
shareMenuButton.TextButton.IsMoreLines = true;
|
Action shateAction = () =>
|
{
|
MenuButtonSelect(1);
|
};
|
shareMenuButton.SelectAction = shateAction;
|
#endregion
|
|
#region 报警类
|
alarmMenuButton = new MenuButton()
|
{
|
X = shareMenuButton.Right,
|
Y = Application.GetRealWidth(16),
|
};
|
menuView.AddChidren(alarmMenuButton);
|
alarmMenuButton.ImageButton.SelectedImagePath = "Collection/MesCenter/AlarmOn.png";
|
alarmMenuButton.ImageButton.UnSelectedImagePath = "Collection/MesCenter/Alarm.png";
|
alarmMenuButton.TextButton.TextID = StringId.AlarmType;
|
Action alarmAction = () =>
|
{
|
MenuButtonSelect(2);
|
};
|
alarmMenuButton.SelectAction = alarmAction;
|
#endregion
|
|
#region 系统信息
|
systemMenuButton = new MenuButton()
|
{
|
X = alarmMenuButton.Right,
|
Y = Application.GetRealWidth(16),
|
};
|
menuView.AddChidren(systemMenuButton);
|
systemMenuButton.ImageButton.SelectedImagePath = "Collection/MesCenter/SystemOn.png";
|
systemMenuButton.ImageButton.UnSelectedImagePath = "Collection/MesCenter/System.png";
|
systemMenuButton.TextButton.TextID = StringId.SystemMessage;
|
Action systemAction = () =>
|
{
|
MenuButtonSelect(3);
|
};
|
systemMenuButton.SelectAction = systemAction;
|
#endregion
|
|
}
|
|
/// <summary>
|
/// 中间信息内容
|
/// </summary>
|
void AddMessageView()
|
{
|
int messageViewY = menuView.Bottom + Application.GetRealWidth(8);
|
int messageViewHeight = bodyView.Height - messageViewY;
|
messageView = new FrameLayout()
|
{
|
Y = messageViewY,
|
Height = messageViewHeight,
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
bodyView.AddChidren(messageView);
|
|
bodyScrolView = new VerticalScrolViewLayout()
|
{
|
Height = messageViewHeight,
|
};
|
messageView.AddChidren(bodyScrolView);
|
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="selectId">0全部 1分享与功能 2报警类 3系统信息</param>
|
void MenuButtonSelect(int selectId)
|
{
|
showMesType = selectId;
|
|
if (selectId == 0)
|
{
|
allMenuButton.IsSelected = true;
|
shareMenuButton.IsSelected = true;
|
alarmMenuButton.IsSelected = true;
|
systemMenuButton.IsSelected = true;
|
|
}
|
else if (selectId == 1)
|
{
|
allMenuButton.IsSelected = false;
|
shareMenuButton.IsSelected = true;
|
alarmMenuButton.IsSelected = false;
|
systemMenuButton.IsSelected = false;
|
|
}
|
else if (selectId == 2)
|
{
|
allMenuButton.IsSelected = false;
|
shareMenuButton.IsSelected = false;
|
alarmMenuButton.IsSelected = true;
|
systemMenuButton.IsSelected = false;
|
}
|
else if (selectId == 3)
|
{
|
allMenuButton.IsSelected = false;
|
shareMenuButton.IsSelected = false;
|
alarmMenuButton.IsSelected = false;
|
systemMenuButton.IsSelected = true;
|
|
}
|
|
GetPushMessageList(showMesType);
|
}
|
|
|
|
/// <summary>
|
/// 添加内容为空提示页面
|
/// </summary>
|
void AddEmptyTipView()
|
{
|
emptyTipView = new FrameLayout()
|
{
|
Height = bodyScrolView.Height,
|
Width = bodyScrolView.Width,
|
};
|
bodyScrolView.AddChidren(emptyTipView);
|
|
var tipView = new EmptyTipView()
|
{
|
Gravity = Gravity.Center
|
};
|
emptyTipView.AddChidren(tipView);
|
}
|
|
/// <summary>
|
/// 年份标记
|
/// </summary>
|
string YearMark = "";
|
/// <summary>
|
/// 加载报警信息RowView
|
/// </summary>
|
/// <param name="VerticalScrolViewMiddle"></param>
|
/// <param name="pushMessageInfo"></param>
|
void AddRowView(VerticalScrolViewLayout VerticalScrolViewMiddle, PushMessageInfo pushMessageInfo)
|
{
|
var rowView = new RowLayout()
|
{
|
Height = Application.GetRealHeight(65),
|
LineColor = CSS_Color.MainBackgroundColor,
|
};
|
VerticalScrolViewMiddle.AddChidren(rowView);
|
|
//标题
|
var btnTilte = new TextButton()
|
{
|
X = Application.GetRealWidth(16),
|
Y = Application.GetRealHeight(12),
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealWidth(20),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
Text = pushMessageInfo.messageContent,
|
//IsMoreLines = true,
|
};
|
rowView.AddChidren(btnTilte);
|
//
|
var needHeight = btnTilte.GetMoreLineNeedHeight();
|
btnTilte.IsMoreLines = true;
|
btnTilte.Height = needHeight;
|
rowView.Height = Application.GetRealHeight(45) + needHeight;
|
|
//副标题
|
var btnSubtitle = new TextButton()
|
{
|
X = Application.GetRealWidth(16),
|
Y = btnTilte.Bottom + Application.GetRealHeight(4),
|
Width = Application.GetRealWidth(240),
|
Height = Application.GetRealHeight(17),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.PromptingColor1,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
Text = pushMessageInfo.messageTitle
|
};
|
rowView.AddChidren(btnSubtitle);
|
|
//日期
|
var btnDatetime = new Button()
|
{
|
X = Application.GetRealWidth(259),
|
Y = btnTilte.Bottom + Application.GetRealHeight(4),
|
Width = Application.GetRealWidth(100),
|
Height = Application.GetRealHeight(17),
|
TextAlignment = TextAlignment.CenterRight,
|
TextColor = CSS_Color.PromptingColor1,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
};
|
rowView.AddChidren(btnDatetime);
|
|
var lineView = new LineView(rowView.Height - Application.GetRealHeight(1));
|
rowView.AddChidren(lineView);
|
|
//删除按钮
|
var deleteBtn = new Button()
|
{
|
TextID = StringId.Del,
|
BackgroundColor = CSS_Color.AuxiliaryColor2,
|
TextColor = CSS_Color.MainBackgroundColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
};
|
rowView.AddRightView(deleteBtn);
|
deleteBtn.MouseUpEventHandler = (sender, e) =>
|
{
|
DeleteThePush(pushMessageInfo, rowView);
|
};
|
|
|
btnDatetime.Text = GetUnixToDateTime(pushMessageInfo.createTime);
|
//2020-12-23 去掉点击弹窗事件
|
//EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
|
//{
|
// new Alert(pushMessageInfo.messageTitle, pushMessageInfo.messageContent, Language.StringByID(StringId.Close)).Show();
|
//};
|
//rowView.MouseUpEventHandler = eventHandler;
|
//btnTilte.MouseUpEventHandler = eventHandler;
|
//btnSubtitle.MouseUpEventHandler = eventHandler;
|
|
|
}
|
|
/// <summary>
|
/// 时间格式转换处理
|
/// </summary>
|
/// <param name="time">毫秒时间戳</param>
|
/// <returns></returns>
|
string GetUnixToDateTime(long time)
|
{
|
try
|
{
|
return Utlis.UnixToDateTimeWithFormatMS(time, "MM/dd HH:mm");
|
}
|
catch (Exception ex)
|
{
|
return "";
|
}
|
}
|
|
/// <summary>
|
/// 删除推送消息
|
/// <param name="pushMessageInfo"></param>
|
/// <param name="rowView"></param>
|
void DeleteThePush(PushMessageInfo pushMessageInfo, RowLayout rowView)
|
{
|
var waitPage = new Loading();
|
bodyView.AddChidren(waitPage);
|
waitPage.Start(Language.StringByID(StringId.PleaseWait));
|
|
new Thread(() =>
|
{
|
try
|
{
|
var result = new HttpServerRequest().PushSerivceDeleteMessage(pushMessageInfo.id);
|
if (result)
|
{
|
PushMessageInfoList.Remove(pushMessageInfo);
|
//删除成功
|
Application.RunOnMainThread(() =>
|
{
|
rowView.RemoveFromParent();
|
});
|
|
}
|
}
|
catch (Exception ex)
|
{
|
}
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
if (waitPage != null)
|
{
|
waitPage.RemoveFromParent();
|
waitPage = null;
|
}
|
});
|
}
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 加载年份标题
|
/// </summary>
|
/// <param name="VerticalScrolViewMiddle"></param>
|
/// <param name="yearStr"></param>
|
void AddYearRowView(VerticalScrolViewLayout VerticalScrolViewMiddle, string yearStr)
|
{
|
var bgView = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(57),
|
};
|
VerticalScrolViewMiddle.AddChidren(bgView);
|
|
var yearBtn = new TextButton()
|
{
|
X = Application.GetRealWidth(16),
|
Y = Application.GetRealHeight(16),
|
Width = Application.GetRealWidth(320),
|
Height = Application.GetRealHeight(33),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel,
|
IsBold = true,
|
};
|
bgView.AddChidren(yearBtn);
|
yearBtn.Text = yearStr + Language.StringByID(StringId.Years);
|
}
|
|
/// <summary>
|
/// 查询推送记录
|
/// </summary>
|
/// <param name="queryType"></param>
|
void GetPushMessageList(int queryType = 0)
|
{
|
bodyScrolView.RemoveAll();
|
if(PushMessageInfoList == null)
|
{
|
PushMessageInfoList = new List<PushMessageInfo>();
|
}
|
else
|
{
|
PushMessageInfoList.Clear();
|
}
|
|
YearMark = "";//标记清空
|
if (string.IsNullOrEmpty(OnAppConfig.Instance.PushId))
|
{
|
AddEmptyTipView();
|
return;
|
}
|
|
var waitPage = new Loading();
|
bodyView.AddChidren(waitPage);
|
waitPage.Start(Language.StringByID(StringId.PleaseWait));
|
|
new Thread(() =>
|
{
|
try
|
{
|
var result = new HttpServerRequest().PushSerivceGetPushmessagelist(queryType);
|
if (result.Code == StateCode.SUCCESS)
|
{
|
PushMessageInfoList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PushMessageInfo>>(result.Data.ToString());
|
Application.RunOnMainThread(() =>
|
{
|
if (PushMessageInfoList != null && PushMessageInfoList.Count > 0)
|
{
|
|
ParseAndDisplayPushList();
|
PushSerivceMarkAllMessageRead();
|
}
|
else
|
{
|
AddEmptyTipView();
|
}
|
});
|
}
|
else
|
{
|
Application.RunOnMainThread(() =>
|
{
|
AddEmptyTipView();
|
});
|
IMessageCommon.Current.ShowErrorInfoAlter(result.Code);
|
}
|
}
|
catch (Exception ex)
|
{
|
}
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
if (waitPage != null)
|
{
|
waitPage.RemoveFromParent();
|
waitPage = null;
|
}
|
});
|
}
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 解析和显示推送消息
|
/// </summary>
|
void ParseAndDisplayPushList()
|
{
|
foreach (var info in PushMessageInfoList)
|
{
|
//年份解析 判断是否需要添加年份标题
|
var mesYear = Utlis.UnixToDateTimeYearMS(info.createTime);
|
if (string.IsNullOrEmpty(YearMark))
|
{
|
//刚开始YearMark标记为空,添加第一个年份标题
|
YearMark = mesYear;
|
AddYearRowView(bodyScrolView, YearMark);
|
}
|
else if (YearMark != mesYear)
|
{
|
//当前信息年份和之前的不一样,重新添加一个年份标题
|
YearMark = mesYear;
|
AddYearRowView(bodyScrolView, YearMark);
|
}
|
|
AddRowView(bodyScrolView, info);
|
}
|
}
|
|
#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>
|
/// 标记所有推送消息已读
|
/// </summary>
|
void PushSerivceMarkAllMessageRead()
|
{
|
new Thread(() =>
|
{
|
var result = new HttpServerRequest().PushSerivceMarkAllMessageRead();
|
if (result)
|
{
|
Utlis.WriteLine("标记成功");
|
}
|
else
|
{
|
Utlis.WriteLine("标记失败");
|
}
|
|
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 注册收到推送监听
|
/// </summary>
|
void RegisterGetPushMessageAction()
|
{
|
HDLCommon.GetPushMessageAction = () =>
|
{
|
if (bodyView != null)
|
{
|
//Utlis.WriteLine("GetPushMessageAction M收到推送");
|
GetPushMessageList(showMesType);
|
}
|
};
|
}
|
|
/// <summary>
|
/// 取消收到推送监听
|
/// </summary>
|
void UnregisterGetPushMessageAction()
|
{
|
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
|
|
}
|
|
/// <summary>
|
/// 推送消息类型详情
|
/// </summary>
|
[System.Serializable]
|
public class PushMessageInfo
|
{
|
/// <summary>
|
/// 记录id
|
/// </summary>
|
public string id;
|
/// <summary>
|
/// 推送Token记录Id
|
/// </summary>
|
public string pushId;
|
/// <summary>
|
/// 云端定义 推送类型;0:默认;1:报警;2:提示;3:新闻;4:推荐;
|
///
|
/// Default:分享与功能;Alarm:报警类;Prompt:系统消息
|
/// </summary>
|
public string pushType;
|
/// <summary>
|
/// 消息主题
|
/// </summary>
|
public string messageTitle;
|
/// <summary>
|
/// 消息内容
|
/// </summary>
|
public string messageContent;
|
///// <summary>
|
///// 扩展数据
|
///// </summary>
|
//public string messageExpand;
|
///// <summary>
|
///// 消息类型;0:提示;1:报警;2:丰林可是对讲呼叫;3:强制下线推送
|
///// </summary>
|
//public string messageType;
|
/// <summary>
|
/// 是否已读
|
/// </summary>
|
public bool isRead;
|
/// <summary>
|
/// 推送时间
|
/// </summary>
|
public long createTime;
|
}
|
|
}
|