Search in sources :

Example 1 with SlideCard

use of com.tmall.wireless.tangram.structure.card.SlideCard 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;
}
Also used : SlideCard(com.tmall.wireless.tangram.structure.card.SlideCard) WrapCellCard(com.tmall.wireless.tangram.structure.card.WrapCellCard) JSONObject(org.json.JSONObject) MVHelper(com.tmall.wireless.tangram.MVHelper) ArrayList(java.util.ArrayList) WrapCellCard(com.tmall.wireless.tangram.structure.card.WrapCellCard) SlideCard(com.tmall.wireless.tangram.structure.card.SlideCard) BannerEntityCard(com.tmall.wireless.tangram.structure.entitycard.BannerEntityCard) LinearScrollEntityCard(com.tmall.wireless.tangram.structure.entitycard.LinearScrollEntityCard) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)1 MVHelper (com.tmall.wireless.tangram.MVHelper)1 SlideCard (com.tmall.wireless.tangram.structure.card.SlideCard)1 WrapCellCard (com.tmall.wireless.tangram.structure.card.WrapCellCard)1 BannerEntityCard (com.tmall.wireless.tangram.structure.entitycard.BannerEntityCard)1 LinearScrollEntityCard (com.tmall.wireless.tangram.structure.entitycard.LinearScrollEntityCard)1 ArrayList (java.util.ArrayList)1 JSONObject (org.json.JSONObject)1