AbsSection.java
6.55 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
278
279
280
281
/*
* Copyright (c) People Technologies Co., Ltd. 2019-2022. All rights reserved.
*/
package com.wd.display.comp.layoutdata;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import com.orhanobut.logger.Logger;
import com.people.entity.custom.comp.CompBean;
import com.people.entity.custom.item.ItemBean;
import com.people.entity.custom.section.SectionBean;
import com.wondertek.wheat.ability.tools.ArrayUtils;
import com.wondertek.wheat.ability.tools.CastUtils;
/**
* section基类<BR>
*
* @param <T> item数据泛型限定
* @param <F> 泛型,待扩展限定
* @author zhangbo
* @version [V1.0.0, 2021/12/8]
* @since V1.0.0
*/
public abstract class AbsSection<T extends ItemBean, F extends SectionBean> extends AbsLayout {
/**
* 对应comp数据
*/
protected CompBean mCompBean;
/**
* 上级父节点,即楼层对象
*/
protected AbsGroup parent;
private int position;
/**
* 单个comp里,列表数据,如卡片列表等
*/
private List<T> items = new ArrayList<>();
/**
* section数据,里面包含ListT数据,待扩展
*/
private F sectionData;
private String compType;
private String compStyle;
/**
* 构造器
*
* @param parent 承载section的group对象,即父节点
* @param compType comp组件类型
* @param compStyle comp组件样式
*/
public AbsSection(AbsGroup parent, String compType, String compStyle) {
super();
this.parent = parent;
this.compType = compType;
this.compStyle = compStyle;
}
/**
* 构造器
*
* @param parent 承载section的group对象,即父节点
* @param compBean comp组件对应的comp数据
*/
public AbsSection(AbsGroup parent, @NonNull CompBean compBean) {
this.parent = parent;
this.compType = compBean.getCompType();
this.compStyle = compBean.getCompStyle();
mCompBean = compBean;
}
public int getItemCount() {
return this.items == null ? 0 : this.items.size();
}
/**
* 转换数据
*
* @param jsonStr json数据
*/
@Deprecated
public void parsePartialData(String jsonStr) {
// 创建item数据
resetDisplayList(mCompBean);
}
/**
* 转换数据
*/
public void parsePartialData() {
parseData();
resetDisplayList(mCompBean);
}
/**
* 展示列表数据
*
* @param compBean comp数据
*/
public void resetDisplayList(@NonNull CompBean compBean) {
int itemSize = ArrayUtils.getListSize(compBean.getOriginalItemBeans());
if (itemSize <= 0) {
return;
}
// 源数据转换成最终展示数据
List<ItemBean> tmpList = compBean.getOriginalItemBeans();
compBean.setDisplayItemBeans(tmpList);
}
/**
* 转换数据
*
* @param dataList item数据列表
*/
public final void parseData(List<T> dataList) {
if (ArrayUtils.isEmpty(dataList)) {
return;
}
items.clear();
items.addAll(dataList);
}
/**
* 获取item数据
*
* @param index 下标
* @return item数据
*/
public T getItemData(int index) {
return ArrayUtils.getListElement(getItems(), index);
}
/**
* 获取item数据
*
* @param index 下标
* @return item数据
*/
protected T getOriginalItemData(int index) {
if (mCompBean == null || ArrayUtils.isEmpty(mCompBean.getOriginalItemBeans())) {
return null;
}
ItemBean itemBean = mCompBean.getOriginalItemBeans().get(index);
ParameterizedType pType = (ParameterizedType) this.getClass().getGenericSuperclass();
Class<T> clazz = (Class<T>) pType.getActualTypeArguments()[0];
return CastUtils.cast(itemBean, clazz);
}
/**
* 添加占位数据,如label是可以展示的,但是没有list,这里组装下占位数据
*/
public void setupOrNotSection() {
Logger.t(getLogTag()).d("setupOrNotSection");
}
/**
* 因section为特殊样式,需要组装list
*
* 如:label、button样式、横向滑动列表样式
*
* @return 创建的对象
*/
protected T newItemBean() {
ParameterizedType pType = (ParameterizedType) this.getClass().getGenericSuperclass();
if (pType == null) {
return null;
}
Class<T> clazz = (Class<T>) pType.getActualTypeArguments()[0];
T t = null;
try {
t = clazz.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
Logger.t(getLogTag()).e("newItemBean, Exception: " + e.getMessage());
}
return t;
}
/**
* 转换数据,二次请求的数据
*
* @param data json数据
*/
@Deprecated
protected abstract void parseData(String data);
/**
* 组装数据
*/
protected abstract void parseData();
/**
* 获取日志tag
*
* @return 日志tag
*/
public abstract String getLogTag();
/**
* 解析数据封装对象class,super.parseData(data)用到
* 若,自己覆写parseData,则可以忽略
*
* @return 数据class
*/
public abstract Class<T> getDataClazz();
public AbsGroup getParent() {
return parent;
}
public void setParent(AbsGroup parent) {
this.parent = parent;
}
public String getCompType() {
return compType;
}
public void setCompType(String compType) {
this.compType = compType;
}
public String getCompStyle() {
return compStyle;
}
public void setCompStyle(String compStyle) {
this.compStyle = compStyle;
}
public F getSectionData() {
return sectionData;
}
public void setSectionData(F sectionData) {
this.sectionData = sectionData;
}
public CompBean getCompBean() {
return mCompBean;
}
public void setCompBean(CompBean compBean) {
this.mCompBean = compBean;
}
@Override
public ILayoutPresenter getLayoutPresenter() {
return getParent().getLayoutPresenter();
}
public List<T> getItems() {
return items;
}
public void setItems(List<T> items) {
this.items = items;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
}