Search in sources :

Example 1 with CardResolver

use of com.tmall.wireless.tangram.dataparser.concrete.CardResolver in project Tangram-Android by alibaba.

the class SampleDataParser method parseGroup.

@Nullable
@Override
public List<Card> parseGroup(@Nullable JSONArray data, 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) {
            // maybe custom card
            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;
                    // add card style
                    addCardStyle(cardData, card);
                    // custom items element key if need.
                    transformCardCellData(cardData);
                    // parser card
                    card.parseWith(cardData, cellResolver);
                    card.type = cardData.optInt(Card.KEY_TYPE, -1);
                    card.stringType = cardType;
                    result.add(card);
                }
            }
        }
    }
    cellResolver.resolver().setCards(result);
    return result;
}
Also used : CardResolver(com.tmall.wireless.tangram.dataparser.concrete.CardResolver) JSONObject(org.json.JSONObject) MVHelper(com.tmall.wireless.tangram.MVHelper) ArrayList(java.util.ArrayList) BannerCard(com.tmall.wireless.tangram.structure.card.BannerCard) GridCard(com.tmall.wireless.tangram.structure.card.GridCard) Card(com.tmall.wireless.tangram.dataparser.concrete.Card) Nullable(android.support.annotation.Nullable)

Example 2 with CardResolver

use of com.tmall.wireless.tangram.dataparser.concrete.CardResolver in project Tangram-Android by alibaba.

the class BaseTangramEngine method registerVirtualViewTemplate.

/**
 * set compiled binary data after engine has been setup, used when load template data dynamically
 * @param type
 * @param data
 */
public void registerVirtualViewTemplate(String type, byte[] data) {
    BaseCellBinderResolver baseCellBinderResolver = getService(BaseCellBinderResolver.class);
    BaseCardBinderResolver baseCardBinderResolver = getService(BaseCardBinderResolver.class);
    if (baseCellBinderResolver != null && baseCardBinderResolver != null) {
        CardResolver cardResolver = baseCardBinderResolver.getDelegate();
        MVHelper mMVHelper = getService(MVHelper.class);
        if (cardResolver != null && mMVHelper != null) {
            baseCellBinderResolver.register(type, new BaseCellBinder(type, mMVHelper));
            cardResolver.register(type, VVCard.class);
            setVirtualViewTemplate(data);
        }
    }
}
Also used : BaseCellBinderResolver(com.tmall.wireless.tangram.dataparser.concrete.BaseCellBinderResolver) CardResolver(com.tmall.wireless.tangram.dataparser.concrete.CardResolver) BaseCellBinder(com.tmall.wireless.tangram.dataparser.concrete.BaseCellBinder) BaseCardBinderResolver(com.tmall.wireless.tangram.dataparser.concrete.BaseCardBinderResolver)

Aggregations

CardResolver (com.tmall.wireless.tangram.dataparser.concrete.CardResolver)2 Nullable (android.support.annotation.Nullable)1 MVHelper (com.tmall.wireless.tangram.MVHelper)1 BaseCardBinderResolver (com.tmall.wireless.tangram.dataparser.concrete.BaseCardBinderResolver)1 BaseCellBinder (com.tmall.wireless.tangram.dataparser.concrete.BaseCellBinder)1 BaseCellBinderResolver (com.tmall.wireless.tangram.dataparser.concrete.BaseCellBinderResolver)1 Card (com.tmall.wireless.tangram.dataparser.concrete.Card)1 BannerCard (com.tmall.wireless.tangram.structure.card.BannerCard)1 GridCard (com.tmall.wireless.tangram.structure.card.GridCard)1 ArrayList (java.util.ArrayList)1 JSONObject (org.json.JSONObject)1