WebDataUtils.java
8.65 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package com.people.webview.util;
import com.wd.capability.layout.uitls.CompentLogicUtil;
import com.wd.common.constant.RegionNameConstants;
import com.wd.foundation.bean.analytics.TraceBean;
import com.wd.foundation.bean.analytics.TrackContentBean;
import com.wd.foundation.bean.custom.comp.TopicInfoBean;
import com.wd.foundation.bean.custom.content.ContentBean;
import com.wd.foundation.bean.custom.content.ContentTypeConstant;
import com.wd.foundation.bean.custom.content.ManuscriptImageBean;
import com.wd.foundation.bean.custom.content.TimeLineTopicPosterBean;
import com.wd.foundation.bean.custom.share.ShareBean;
import com.wd.foundation.bean.web.ArticleVideoBean;
import com.wd.foundation.bean.web.JSCallbackBean;
import com.wd.foundation.wdkit.json.GsonUtils;
import com.wd.foundation.wdkitcore.tools.ArrayUtils;
import com.wd.foundation.wdkitcore.tools.ResUtils;
import com.wd.foundation.wdkitcore.tools.StringUtils;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* 数据处理工具类
* @author baozhaoxin
* @version [V1.0.0, 2023/6/15]
* @since V1.0.0
*/
public class WebDataUtils {
/**
* 处理图文详情视频信息数据
* @param jsonObject
* @return
*/
public static ArticleVideoBean getArticleVideoInfo(JSONObject jsonObject){
if(jsonObject == null){
return null;
}
ArticleVideoBean articleVideoBean = new ArticleVideoBean();
String positionLeft = convertH5FloatData(jsonObject.optString("positionLeft"));
String positionTop = convertH5FloatData(jsonObject.optString("positionTop"));
String positionWidth = convertH5FloatData(jsonObject.optString("positionWidth"));
String positionHeight = convertH5FloatData(jsonObject.optString("positionHeight"));
String videoWidth = convertH5FloatData(jsonObject.optString("videoWidth"));
String videoHeight = convertH5FloatData(jsonObject.optString("videoHeight"));
String videoLandscape = jsonObject.optString("videoLandscape");
String videoUrl = jsonObject.optString("videoUrl");
String videoCoverUrl = jsonObject.optString("videoCoverUrl");
articleVideoBean.setPositionLeft(positionLeft);
articleVideoBean.setPositionTop(positionTop);
articleVideoBean.setPositionWidth(positionWidth);
articleVideoBean.setPositionHeight(positionHeight);
articleVideoBean.setVideoWidth(videoWidth);
articleVideoBean.setVideoHeight(videoHeight);
articleVideoBean.setVideoLandscape(videoLandscape);
articleVideoBean.setVideoUrl(videoUrl);
articleVideoBean.setVideoCoverUrl(videoCoverUrl);
return articleVideoBean;
}
/**
* 对h5返回的float数据进行处理
* @param data
* @return
*/
private static String convertH5FloatData(String data){
try {
float floatData = Float.parseFloat(data);
int intData = (int) floatData;
int resultData = (int) (intData * ResUtils.getResources().getDisplayMetrics().density);
return resultData + "";
} catch (Exception e) {
return "";
}
}
/**
* 处理h5JS回调数据
* @param mContentId
* @param jsCallbackBean
* @return
*/
public static Object converJSCallbackBean(String mContentId, JSCallbackBean jsCallbackBean){
if (jsCallbackBean != null && StringUtils.isEqual(mContentId,jsCallbackBean.getCallbackId())){
return jsCallbackBean.getCallbackData();
}
return null;
}
/**
* TopicInfo分享
*
* @param topicInfoBean
*/
public static TrackContentBean shareTopicInfoBean(TopicInfoBean topicInfoBean, ShareBean shareBean, TraceBean traceBean) {
if (topicInfoBean == null) {
return null;
}
// 点击埋点
TrackContentBean trackContentBean = new TrackContentBean();
topicInfoBean.setTitleName(topicInfoBean.getLocalPageName());
topicInfoBean.setLocalPageName(topicInfoBean.getLocalPageName());
topicInfoBean.setLocalPageId(topicInfoBean.getLocalPageId());
trackContentBean.topicInfoBeanBeantoBean(topicInfoBean);
trackContentBean.setTraceBean(traceBean);
trackContentBean.shareAction();
//通用设置、如果特别需要在 setTopicBeanToShareBean 设置
if (shareBean == null){
shareBean = new ShareBean();
}
shareBean.setContentId(topicInfoBean.getTopicId());
shareBean.setContentType(ContentTypeConstant.URL_TYPE_FIVE + "");
shareBean.setTitle(topicInfoBean.getShareTitle());
shareBean.setDescription(topicInfoBean.getShareSummary());
//分享链接缩略图,有分享图显示分享图,无显示头图
if (StringUtils.isNotBlank(topicInfoBean.getShareCoverUrl())){
shareBean.setImageUrl(topicInfoBean.getShareCoverUrl());
}else {
shareBean.setImageUrl(topicInfoBean.getBackgroundImgUrl());
}
shareBean.setShareUrl(topicInfoBean.getShareUrl());
shareBean.setTargetRelId(topicInfoBean.getRelId());
shareBean.setTargetRelType(topicInfoBean.getRelType());
//关联关系
shareBean.setRelType(topicInfoBean.getRelType());
shareBean.setContentRelId(topicInfoBean.getRelId());
shareBean.setShowReport(false);
shareBean.setShowLike(-1);
shareBean.setShareOpen(topicInfoBean.getShareOpen());
shareBean.setSharePosterOpen(topicInfoBean.getPosterFlag()+"");
CompentLogicUtil.setTopicBeanToShareBean(shareBean, topicInfoBean);
// bean.setShowCollect(0);
shareBean.setShowPoster(topicInfoBean.getPosterFlag() > 0 ? 1 : -1);
trackContentBean.setSummary_type(topicInfoBean.getTopicTypeWord());
trackContentBean.setRegion_name(RegionNameConstants.SUBJECT);
return trackContentBean;
}
/**
* 把专题前五条数据给topicInfoBean
* @param topicInfoBean
* @param shareDataJson
*/
public static void setTopFiveData(TopicInfoBean topicInfoBean, String shareDataJson){
if (topicInfoBean != null){
try {
if (26 == topicInfoBean.getTopicType()){
//时间轴专题
setTopFiveDataForTimeLine(topicInfoBean,shareDataJson);
}else {
List<ContentBean> contentBeans = GsonUtils.jsonToArrayList(shareDataJson, ContentBean.class);
topicInfoBean.setShareContentList(contentBeans);
}
}catch (Exception e){
e.printStackTrace();
}
}
}
/**
* 时间轴专题
*/
public static void setTopFiveDataForTimeLine(TopicInfoBean topicInfoBean, String shareDataJson){
List<TimeLineTopicPosterBean> timeLineTopicPosterBeans = GsonUtils.jsonToArrayList(shareDataJson, TimeLineTopicPosterBean.class);
List<ContentBean> contentBeans = new ArrayList<>();
if (timeLineTopicPosterBeans != null && timeLineTopicPosterBeans.size() > 0){
for (int i = 0; i < timeLineTopicPosterBeans.size(); i++){
TimeLineTopicPosterBean timeLineTopicPosterBean = timeLineTopicPosterBeans.get(i);
if (timeLineTopicPosterBean != null){
ContentBean contentBean = new ContentBean();
contentBean.setNewsTitle(timeLineTopicPosterBean.getName());
if (ArrayUtils.isNotEmpty(timeLineTopicPosterBean.getFullColumnImgUrls())){
ManuscriptImageBean manuscriptImageBean = timeLineTopicPosterBean.getFullColumnImgUrls().get(0);
if (manuscriptImageBean != null){
contentBean.setCoverUrl(manuscriptImageBean.url);
}
}
contentBean.timeBlurred = timeLineTopicPosterBean.getViewTimeBlurred();
contentBean.setPublishTime(timeLineTopicPosterBean.getViewTime());
contentBeans.add(contentBean);
}
}
}
topicInfoBean.setShareContentList(contentBeans);
}
/**
* 推送曝光埋点
* @param contentBeanList
*/
public static void recommendShowTrack(List<ContentBean> contentBeanList){
if(ArrayUtils.isEmpty(contentBeanList)){
return;
}
for (ContentBean contentBean : contentBeanList) {
TrackContentBean trackContentBean = new TrackContentBean();
trackContentBean.contentBeantoBean(contentBean,null);
trackContentBean.exporeOrClick(false);
// CommonTrack.getInstance().contentShowTrack(trackContentBean);
}
}
}