Laya 首日红点逻辑
Laya 首日红点逻辑
@author ixenos 2019-08-26 10:50:27
1.原理:显然,首日红点意味着包含进程销毁的情况,那么就要持久化存储信息,这里我们使用LocalStorage存储时间点,
存入时,进行时间判断来决定是否销毁标志,然后在每次登陆时进行非值刷新,时间未达到不销毁标标志
1 /** 2 * 设置每日首次显示红点 3 * @param id 4 * @param showRed 5 * @forceFlush 6 */ 7 public function setDailyFirstRed(id:String, showRed:Boolean, forceFlush:Boolean=false):void{ 8 var key:String = "DAILY_FIRST_RED_"+id; 9 var lastTime:int = Number(LocalStorageManager.ins.getItem(key)); 10 var curTime:int = TimeManager.ins.getCurTime(); 11 if(showRed){ 12 LocalStorageManager.ins.setItem(key, curTime+""); 13 }else{ 14 if(lastTime){ 15 if(forceFlush){ 16 LocalStorageManager.ins.removeItem(key); 17 }else{ 18 var nextDayTime:int = TimeManager.ins.getNextDayTime(lastTime); 19 if(curTime>nextDayTime){ 20 LocalStorageManager.ins.removeItem(key); 21 } 22 } 23 } 24 } 25 }
1 public function getDailyFirstRed(id:String):Boolean{ 2 return LocalStorageManager.ins.getItem("DAILY_FIRST_RED_"+id)!=null; 3 }
2.当然,LocalStoregeManager中对key肯定要加上用户ID处理,不然切账号就乱了