PopUpsUtils.java
4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.wd.common.dialog;
import android.content.Context;
import com.wd.base.log.Logger;
import com.wd.foundation.wdkitcore.tools.HostUtil;
import com.wd.common.utils.ProcessUtils;
import com.wd.foundation.bean.custom.content.ContentBean;
import com.wd.foundation.bean.pop.PopUpsBean;
import com.wd.foundation.wdkit.utils.SpUtils;
import com.wd.foundation.bean.utils.TimeUtil;
import java.util.ArrayList;
import java.util.List;
/**
* 彩蛋工具类
* @author baozhaoxin
* @version [V1.0.0, 2022/8/20]
*/
public class PopUpsUtils {
private static String TAG = "PopUpsUtils";
/**
*
* @param hasPopUp 是否有彩蛋
* @param originalList 原始数据集合
* @return
*/
public static PopUpsBean handlerPopUps(boolean hasPopUp, List<PopUpsBean> originalList, String type){
if(!hasPopUp){
//没有彩蛋
return null;
}
if(originalList==null||originalList.size()==0){
//彩蛋数据为空
return null;
}
List<PopUpsBean> resultlList = new ArrayList<>();
//按时间和exposureOnce过滤数据
handlerByDataAndExposureOnce(resultlList,originalList,type);
if(resultlList!=null&&resultlList.size()>0){
//返回符合条件的第一条数据
return resultlList.get(0);
}
return null;
}
/**
*按时间和exposureOnce过滤数据
* @param resultlList
* @param originalList
*/
private static void handlerByDataAndExposureOnce(List<PopUpsBean> resultlList,List<PopUpsBean> originalList,String type){
long currentTimeStamp = HostUtil.serverTime;
for (PopUpsBean bean : originalList) {
PopUpsBean popUpsBean = SpUtils.getPopUpById(bean.getId());
if(popUpsBean != null && (
popUpsBean.getAlreadyDailyExposureTimes() == popUpsBean.getDailyExposureTimes() ||
popUpsBean.getAlreadyDailyExposureTimes() > popUpsBean.getDailyExposureTimes())){
//当日看到N次彩蛋后,当日不会再看到彩蛋
continue;
}
try {
long startTimeStamp = TimeUtil.time2timestamp(bean.getStartTime());
long endTimeStamp = TimeUtil.time2timestamp(bean.getEndTime());
if (currentTimeStamp >= startTimeStamp
&& currentTimeStamp <= endTimeStamp) {
resultlList.add(bean);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 显示彩蛋
*/
public static EasterEggsDialog showEasterEggsDialog(Context context,PopUpsBean mPopUpsBean,String type,
EasterEggsDialog.DialogClickListener mListener) {
if (mPopUpsBean != null) {
EasterEggsDialog easterEggsDialog = new EasterEggsDialog(context).builder()
.setMaterialUrl(mPopUpsBean.getMaterialUrl())
.setDurations(mPopUpsBean.getDurations())
.setClickListener(mListener)
.show();
Logger.t(TAG).d("easterEggsResult=" + mPopUpsBean.toString());
SpUtils.savePopUpToCache(mPopUpsBean);
return easterEggsDialog;
}
return null;
}
/**
* 彩蛋点击跳转
*
* @param mPopUpsBean
*/
public static void easterEggsDialogJump(PopUpsBean mPopUpsBean) {
if(mPopUpsBean==null){
return;
}
ContentBean contentBean = new ContentBean();
contentBean.setPageId(mPopUpsBean.getPageId());
contentBean.setLinkUrl(mPopUpsBean.getLinkUrl());
contentBean.setObjectId(mPopUpsBean.getObjectId());
contentBean.setObjectType(mPopUpsBean.getObjectType());
contentBean.setObjectLevel(mPopUpsBean.getObjectLevel());
contentBean.setBottomNavId(mPopUpsBean.getBottomNavId());
contentBean.setRelId(mPopUpsBean.getRelId());
//专题模板 --->专题样式 1:常规, 2:作者, 3:时间线
// contentBean.setTopicTemplate(mPopUpsBean.getTopicTemplate());
ProcessUtils.processPage(contentBean);
}
}