AbsGroup.java
6.17 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
* Copyright (c) People Technologies Co., Ltd. 2019-2022. All rights reserved.
*/
package com.wd.display.comp.layoutdata;
import java.util.ArrayList;
import java.util.List;
import com.people.entity.custom.comp.CompBean;
import com.people.entity.custom.comp.GroupBean;
/**
* Group基类<BR>
*
* @author zhangbo
* @version [V1.0.0, 2021/12/8]
* @since V1.0.0
*/
public abstract class AbsGroup extends AbsLayout {
private AbsPage parent;
/**
* group在页面里的下标
*/
private int position;
/**
* group在recyclerView里的下标
*/
private int startPosition;
// 每个楼层页码
private int pageNum = 1;
// 是否推荐策略;2:否,1:是
private String groupStrategy;
private List<AbsSection> sections;
/**
* 楼层所在页面所有楼层中的位置
*/
private int layerIndex = 0;
/**
* 是否是页面的最后一个楼层
*/
private boolean isLastLayer = false;
// 记录AbsGroup所在GroupBean对象
private GroupBean groupBean;
//记录的组件支持加载更多数据 (改组件对象必然在页面的最后一个楼层的最后一个组件上)
private CompBean supportLoadMoreDataComp;
/**
* gzq
*
* @param dataBean
* @param parent
*/
public AbsGroup(GroupBean dataBean, AbsPage parent) {
this(parent);
this.setId(dataBean.getId());
parseData(dataBean);
}
public int getLayerIndex() {
return layerIndex;
}
public void setLayerIndex(int layerIndex) {
this.layerIndex = layerIndex;
}
/**
* 构造器
*
* @param groupId 楼层id
* @param parent page对象
*/
public AbsGroup(String groupId, AbsPage parent) {
this(parent);
this.setId(groupId);
}
/**
* gzq
*
* @param parent
*/
public AbsGroup(AbsPage parent) {
this.parent = parent;
}
/**
* getParent
*
* @param <T>
* @return
*/
public <T extends AbsPage> T getParent() {
return (T) this.parent;
}
public void setParent(AbsPage parent) {
this.parent = parent;
}
/**
* getSection
*
* @return AbsSection
*/
public List<AbsSection> getSections() {
if (sections == null) {
sections = new ArrayList<>();
}
return sections;
}
public void setSections(List<AbsSection> sections) {
this.sections = sections;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public int getStartPosition() {
return startPosition;
}
public void setStartPosition(int startPosition) {
this.startPosition = startPosition;
}
@Override
public ILayoutPresenter getLayoutPresenter() {
return getParent().getLayoutPresenter();
}
/**
* 解析楼层,组装section
*
* @param groupBean 楼层数据
*/
public void parseData(GroupBean groupBean) {
getSections().clear();
if (groupBean.getComps() == null) {
return;
}
addParseData(groupBean.getComps());
}
/**
* 楼层添加新的组件信息以供解析成section
*
* @param compList
*/
public void addParseData(List<CompBean> compList) {
if (compList == null) {
return;
}
for (CompBean compBean : compList) {
if (compBean == null) {
continue;
}
if (getParent() != null && getParent().getSectionParser() != null) {
AbsSection<?, ?> section = getParent().getSectionParser().parseSection(this, compBean);
if (section != null) {
section.setCompBean(compBean);
// 添加section
getSections().add(section);
}
}
}
}
/**
* 解析Group数据
*
* @param groupBean 楼层对象,携带组件和稿件数据
* @param loadMore true:楼层增加数据 ;false:楼层第一次数据
*/
public void parseGroupData(GroupBean groupBean, boolean loadMore) {
if (groupBean == null) {
return;
}
if (loadMore) {
// 记录已经存在的数据量
setDisplayItemCount(this.getSections().size());
// 解析group数据,生成section列表
addParseData(groupBean.getComps());
} else {
setDisplayItemCount(0);
// 解析group数据,生成section列表
parseData(groupBean);
}
for (AbsSection<?, ?> section : this.getSections()) {
if (section == null) {
continue;
}
// 解析结果
section.parsePartialData();
}
}
public void removeSection(int index) {
sections.remove(index);
getLayoutPresenter().onRefreshPageSuccess();
}
public void removeSectionsByType(String type) {
for (AbsSection section : sections) {
if (type.equals(section.getCompType())) {
sections.remove(section);
}
}
getLayoutPresenter().onRefreshPageSuccess();
}
public int getPageNum() {
return pageNum;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public boolean isLastLayer() {
return isLastLayer;
}
public void setLastLayer(boolean lastLayer) {
isLastLayer = lastLayer;
}
public String getGroupStrategy() {
return groupStrategy;
}
public void setGroupStrategy(String groupStrategy) {
this.groupStrategy = groupStrategy;
}
public GroupBean getGroupBean() {
return groupBean;
}
public void setGroupBean(GroupBean groupBean) {
this.groupBean = groupBean;
}
public CompBean getSupportLoadMoreDataComp() {
return supportLoadMoreDataComp;
}
public void setSupportLoadMoreDataComp(CompBean supportLoadMoreDataComp) {
this.supportLoadMoreDataComp = supportLoadMoreDataComp;
}
}