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;
}
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);
}
}
}
Aggregations