using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// 消息中心控件
|
/// </summary>
|
public class MessageManagementControl : ButtonBase
|
{
|
/// <summary>
|
/// 消息中心控件
|
/// </summary>
|
public MessageManagementControl()
|
{
|
this.Height = this.GetPictrueRealSize(69);
|
this.Width = this.GetPictrueRealSize(69);
|
this.UnSelectedImagePath = "Item/MessageManagement.png";
|
this.SelectedImagePath = "Item/MessageManagementSelected.png";
|
|
//如果住宅为虚拟住宅,则此功能无效
|
if (Common.Config.Instance.Home.IsVirtually == false)
|
{
|
this.ButtonClickEvent += (sender, e) =>
|
{
|
//点击后,清空状态
|
this.IsSelected = false;
|
ControlCommonResourse.HadNewMessage = false;
|
|
var form = new UserMain.MessageManagementForm();
|
form.AddForm();
|
};
|
//添加缓存
|
ControlCommonResourse.listMessageManaContr.Add(this);
|
//刷新状态
|
this.RefreshStatu();
|
}
|
}
|
|
/// <summary>
|
/// 刷新状态(也就是如果数据有更新的话,会显示红色角标)
|
/// </summary>
|
public void RefreshStatu()
|
{
|
//如果住宅为虚拟住宅,则此功能无效
|
if (Common.Config.Instance.Home.IsVirtually == true)
|
{
|
return;
|
}
|
|
if (ControlCommonResourse.HadNewMessage == true)
|
{
|
//如果已经有新消息过来了,就不用读了
|
ControlCommonResourse.ReadMessageAgain = false;
|
this.IsSelected = true;
|
return;
|
}
|
if (ControlCommonResourse.ReadMessageAgain == false)
|
{
|
//无需再次读取
|
return;
|
}
|
ControlCommonResourse.ReadMessageAgain = false;
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
string nowHomeId = Common.Config.Instance.Home.Id;
|
var pra = new MessageInfoPra();
|
pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
|
var result = UserCenterLogic.GetResponseDataByRequestHttps("MessageCenter/GetMessageCenterPagger", false, pra, new List<string>() { "NotCheck" });
|
if (string.IsNullOrEmpty(result) == true)
|
{
|
//出错,需要重新读取
|
ControlCommonResourse.ReadMessageAgain = true;
|
return;
|
}
|
if (nowHomeId != Common.Config.Instance.Home.Id)
|
{
|
//检测:切换了住宅??
|
return;
|
}
|
var dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<MessageCentetInfo>(result);
|
for (int i = 0; i < dataInfo.PageData.Count; i++)
|
{
|
if (dataInfo.PageData[i].IsReading == false)
|
{
|
if (dataInfo.PageData[i].Topic == "/DoorLock/DoorLockOperatingEventNotificationCommand")
|
{
|
//暂时不处理这个主题
|
continue;
|
}
|
ControlCommonResourse.HadNewMessage = true;
|
Application.RunOnMainThread(() =>
|
{
|
//有新消息
|
this.IsSelected = true;
|
});
|
break;
|
}
|
}
|
});
|
}
|
|
/// <summary>
|
/// 控件移除
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
ControlCommonResourse.listMessageManaContr.Remove(this);
|
|
base.RemoveFromParent();
|
}
|
}
|
}
|