use of com.tmall.wireless.tangram.structure.card.WrapCellCard in project Tangram-Android by alibaba.
the class PojoDataParser method parseGroup.
@NonNull
@Override
public List<Card> parseGroup(@NonNull JSONArray data, @NonNull final ServiceManager serviceManager) {
final CardResolver cardResolver = serviceManager.getService(CardResolver.class);
Preconditions.checkState(cardResolver != null, "Must register CardResolver into ServiceManager first");
final MVHelper cellResolver = serviceManager.getService(MVHelper.class);
Preconditions.checkState(cellResolver != null, "Must register CellResolver into ServiceManager first");
final int size = data.length();
final List<Card> result = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
JSONObject cardData = data.optJSONObject(i);
if (cardData != null) {
final String cardType = cardData.optString(Card.KEY_TYPE);
if (!TextUtils.isEmpty(cardType)) {
final Card card = cardResolver.create(cardType);
if (card != null) {
card.rowId = i;
card.serviceManager = serviceManager;
card.parseWith(cardData, cellResolver);
card.type = cardData.optInt(Card.KEY_TYPE, -1);
card.stringType = cardType;
if (card.isValid()) {
if (card instanceof IDelegateCard) {
List<Card> cards = ((IDelegateCard) card).getCards(new CardResolver() {
@Override
public Card create(String type) {
Card c = cardResolver.create(type);
c.serviceManager = serviceManager;
c.id = card.id;
c.setStringType(cardType);
c.stringType = cardType;
c.rowId = card.rowId;
return c;
}
});
for (Card c : cards) {
if (c.isValid()) {
result.add(c);
}
}
} else {
if (card.style.slidable) {
result.add(new SlideCard(card));
} else {
result.add(card);
}
}
}
} else {
final Card cellCard = new WrapCellCard();
if (cellCard != null) {
cellCard.rowId = i;
cellCard.serviceManager = serviceManager;
cellCard.parseWith(cardData, cellResolver);
cellCard.setStringType(TangramBuilder.TYPE_CONTAINER_1C_FLOW);
if (cellCard.isValid()) {
result.add(cellCard);
}
}
}
} else {
LogUtils.w(TAG, "Invalid card type when parse JSON data");
}
}
}
cellResolver.resolver().setCards(result);
return result;
}
Aggregations