using LitJson;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
namespace Snxxz.UI
|
{
|
public class ActivitiesPushMgr : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
|
{
|
public const int WholePeopleMountRank = 2090001; //全民冲榜坐骑榜
|
public const int WholePeopleMountRankEnd = 2090002; //全民冲榜坐骑榜截止
|
|
ImpactRankModel impactRank { get { return ModelCenter.Instance.GetModel<ImpactRankModel>(); } }
|
|
public override void Init()
|
{
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
SetMountRankPushInfo();
|
SetMountRankEndPushInfo();
|
GlobalTimeEvent.Instance.minuteEvent -= RefreshMinuteTime;
|
GlobalTimeEvent.Instance.minuteEvent += RefreshMinuteTime;
|
OpenServerActivityCenter.Instance.openServerActivityStateChange -= RefreshOpenServerState;
|
OpenServerActivityCenter.Instance.openServerActivityStateChange += RefreshOpenServerState;
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
|
private void RefreshMinuteTime()
|
{
|
RemovePushByTime(PushInfoType.MountRankStart,11);
|
RemovePushByTime(PushInfoType.MountRankEnd,23);
|
}
|
|
private void RefreshOpenServerState()
|
{
|
SetMountRankPushInfo();
|
SetMountRankEndPushInfo();
|
}
|
|
private void SetMountRankPushInfo()
|
{
|
if(impactRank.IsActivityClose(2))
|
{
|
RemovePushInfo(WholePeopleMountRank);
|
return;
|
}
|
|
int day = impactRank.GetOpenDay(2);
|
int remainHour = 11 - TimeUtility.ServerNow.Hour;
|
int remainMinute = 0 - TimeUtility.ServerNow.Minute;
|
int remainSecond = day * 24 * 60 * 60 + remainHour * 60 * 60 + remainMinute * 60;
|
if(remainSecond > 0)
|
{
|
GetPushJsonData(WholePeopleMountRank, remainSecond,Language.Get("SetUpPrivate106"),Language.Get("SetUpPrivate107"));
|
}
|
}
|
|
private void SetMountRankEndPushInfo()
|
{
|
if (impactRank.IsActivityClose(2))
|
{
|
RemovePushInfo(WholePeopleMountRankEnd);
|
return;
|
}
|
|
int day = impactRank.GetSurplusDay(2);
|
int remainHour = 23 - TimeUtility.ServerNow.Hour;
|
int remainMinute = 0 - TimeUtility.ServerNow.Minute;
|
int remainSecond = (day - 1) * 24 * 60 * 60 + remainHour * 60 * 60 + remainMinute * 60;
|
if (remainSecond > 0)
|
{
|
GetPushJsonData(WholePeopleMountRankEnd, remainSecond, Language.Get("SetUpPrivate106"), Language.Get("SetUpPrivate108"));
|
}
|
}
|
|
private void RemovePushByTime(PushInfoType type,int time)
|
{
|
int remainHour = time - TimeUtility.ServerNow.Hour;
|
int remainMinute = 0 - TimeUtility.ServerNow.Minute;
|
int remainSecond = remainHour * 60 * 60 + remainMinute * 60;
|
switch (type)
|
{
|
case PushInfoType.MountRankStart:
|
if (impactRank.IsActivityClose(2))
|
{
|
RemovePushInfo(WholePeopleMountRank);
|
}
|
else
|
{
|
int day = impactRank.GetOpenDay(2);
|
if(day <= 0 && remainSecond <= 120)
|
{
|
RemovePushInfo(WholePeopleMountRank);
|
}
|
}
|
break;
|
case PushInfoType.MountRankEnd:
|
if (impactRank.IsActivityClose(2))
|
{
|
RemovePushInfo(WholePeopleMountRankEnd);
|
}
|
else
|
{
|
int day = impactRank.GetSurplusDay(2);
|
if (day <= 1 && remainSecond <= 120)
|
{
|
RemovePushInfo(WholePeopleMountRankEnd);
|
}
|
}
|
break;
|
}
|
}
|
|
public void RemovePushInfo(int pushId)
|
{
|
SDKUtility.Instance.GeTui_RemoveLocalMessage(pushId.ToString());
|
}
|
|
public JsonData GetPushJsonData(int pushId,int pushtime,string title,string content)
|
{
|
JsonData _params = new JsonData();
|
_params["code"] = 2005;
|
_params["id"] = pushId;// id 重要, 标示每个通知的更新或者移除
|
_params["title"] = title;// 推送标题
|
_params["subtitle"] = "";// 副标题
|
_params["content"] = content;// 具体内容
|
_params["badge"] = -1;// 角标
|
|
// 以下为决定应该多久后弹出此通知
|
System.TimeSpan ts = System.DateTime.UtcNow - new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
|
long ret = System.Convert.ToInt64(ts.TotalSeconds) + pushtime;// 表示3秒后
|
_params["fireTime"] = ret;
|
return _params;
|
}
|
|
public enum PushInfoType
|
{
|
MountRankStart,
|
MountRankEnd,
|
}
|
}
|
}
|