using System;
using Shared;
using HDL_ON.UI.CSS;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
namespace HDL_ON.UI
{
///
/// 信息中心页面
///
public class MessageCenterPage : FrameLayout
{
FrameLayout bodyView;
///
/// 当前
///
VerticalScrolViewLayout bodyScrolView;
///
/// 内容为空提示View
///
EmptyTipView emptyTipView;
///
/// menuView
///
FrameLayout menuView;
MenuButton allMenuButton;
MenuButton shareMenuButton;
MenuButton alarmMenuButton;
MenuButton systemMenuButton;
FrameLayout messageView;
///
/// 显示的消息类型
/// 1全部 2分享与功能 3报警类 4系统信息
///
int showMesType = 1;
///
/// 推送消息列表
///
List PushMessageInfoList = new List();
///
///
///
public MessageCenterPage()
{
bodyView = this;
BackgroundColor = CSS_Color.BackgroundColor;
}
///
///
///
public void LoadPage()
{
new TopViewDiv(bodyView, Language.StringByID(StringId.MessageCenter)).LoadTopView();
AddTopMenuView();
AddMessageView();
MenuButtonSelect(1);
//TestLoad();
GetPushMessageList();
}
///
/// 顶部菜单选项
///
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(1);
};
allMenuButton.SelectAction = allAction;
#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;
Action shateAction = () =>
{
MenuButtonSelect(2);
};
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(3);
};
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(4);
};
systemMenuButton.SelectAction = systemAction;
#endregion
}
///
/// 中间信息内容
///
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);
}
///
///
///
/// 1全部 2分享与功能 3报警类 4系统信息
void MenuButtonSelect(int selectId)
{
showMesType = selectId;
if (selectId == 1)
{
allMenuButton.IsSelected = true;
shareMenuButton.IsSelected = false;
alarmMenuButton.IsSelected = false;
systemMenuButton.IsSelected = false;
}
else if (selectId == 2)
{
allMenuButton.IsSelected = false;
shareMenuButton.IsSelected = true;
alarmMenuButton.IsSelected = false;
systemMenuButton.IsSelected = false;
}
else if (selectId == 3)
{
allMenuButton.IsSelected = false;
shareMenuButton.IsSelected = false;
alarmMenuButton.IsSelected = true;
systemMenuButton.IsSelected = false;
}
else if (selectId == 4)
{
allMenuButton.IsSelected = false;
shareMenuButton.IsSelected = false;
alarmMenuButton.IsSelected = false;
systemMenuButton.IsSelected = true;
}
}
///
/// 添加内容为空提示页面
///
void AddEmptyTipView()
{
emptyTipView = new EmptyTipView()
{
Gravity = Gravity.Center
};
messageView.AddChidren(emptyTipView);
}
///
/// 加载报警信息RowView
///
///
///
void AddRowView(VerticalScrolViewLayout VerticalScrolViewMiddle, PushMessageInfo pushMessageInfo)
{
var rowView = new RowLayout()
{
Height = Application.GetRealHeight(65),
LineColor = CSS_Color.MainBackgroundColor,
};
VerticalScrolViewMiddle.AddChidren(rowView);
//标题
var btnTilte = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealHeight(12),
Width = Application.GetRealWidth(320),
Height = Application.GetRealHeight(20),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
Text = pushMessageInfo.messageTitle
};
rowView.AddChidren(btnTilte);
//副标题
var btnSubtitle = new Button()
{
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.messageContent
};
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,
Text = pushMessageInfo.createTime
};
rowView.AddChidren(btnDatetime);
var lineView = new LineView(rowView.Height);
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) =>
{
rowView.RemoveFromParent();
};
//EventHandler eventHandler = (sender, e) =>
//{
//};
//btnTilte.MouseUpEventHandler = eventHandler;
//btnSubtitle.MouseUpEventHandler = eventHandler;
}
///
/// 加载年份标题
///
///
///
void AddYearRowView(VerticalScrolViewLayout VerticalScrolViewMiddle, string yearStr)
{
var bgView = new FrameLayout()
{
Height = Application.GetRealHeight(57),
};
VerticalScrolViewMiddle.AddChidren(bgView);
var yearBtn = new Button()
{
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,
Text = yearStr
};
bgView.AddChidren(yearBtn);
}
///
///
///
void GetPushMessageList()
{
var waitPage = new Loading();
waitPage.Start(Language.StringByID(StringId.PleaseWait));
bodyScrolView.RemoveAll();
PushMessageInfoList.Clear();
new Thread(() =>
{
try
{
var result = new HttpServerRequest().PushSerivceGetPushmessagelist();
if (result.Code == StateCode.SUCCESS)
{
PushMessageInfoList = Newtonsoft.Json.JsonConvert.DeserializeObject>(result.Data.ToString());
Application.RunOnMainThread(() =>
{
if (PushMessageInfoList != null && PushMessageInfoList.Count > 0)
{
ParseAndDisplayPushList();
}
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();
}
///
/// 解析和显示推送消息
///
void ParseAndDisplayPushList()
{
//
if (showMesType == 1)
{
}
}
#region 测试
///
///
///
void TestLoad()
{
PushMessageInfoList.Add(new PushMessageInfo()
{
messageTitle = "报警信息",
messageContent = "门锁被打开",
createTime = "11月30 10:50",
});
PushMessageInfoList.Add(new PushMessageInfo()
{
messageTitle = "报警信息1",
messageContent = "门锁被打开",
createTime = "11月30 11:50",
});
PushMessageInfoList.Add(new PushMessageInfo()
{
messageTitle = "报警信息2",
messageContent = "门锁被打开",
createTime = "11月30 12:50",
});
AddYearRowView(bodyScrolView, "2020年");
foreach (var info in PushMessageInfoList)
{
AddRowView(bodyScrolView, info);
}
AddYearRowView(bodyScrolView, "2019年");
foreach (var info in PushMessageInfoList)
{
AddRowView(bodyScrolView, info);
}
}
#endregion
}
///
/// 推送消息类型
///
[System.Serializable]
public class PushMessageInfo
{
///
/// 记录Id
///
public string id;
///
/// 是否已读
///
public bool isRead;
///
/// 消息内容
///
public string messageContent;
///
/// 扩展数据
///
public string messageExpand;
///
/// 消息主题
///
public string messageTitle;
///
/// 消息类型;0:提示;1:报警;2:丰林可是对讲呼叫;3:强制下线推送
///
public string messageType;
///
/// 推送Token记录Id
///
public string pushId;
///
/// 推送类型;0:默认;1:报警;2:提示;3:新闻;4:推荐;
///
public string pushType;
///
/// 推送时间
///
public string createTime;
}
}