use of com.tmall.wireless.tangram.MVHelper in project Tangram-Android by alibaba.
the class Card method addCellInternal.
private boolean addCellInternal(Card parent, int index, @Nullable BaseCell cell, boolean silent) {
if (cell != null) {
cell.parentId = parent.id;
cell.parent = parent;
cell.serviceManager = serviceManager;
MVHelper mvHelper = getMVHelper();
if (mvHelper != null) {
if (mvHelper.isValid(cell, serviceManager)) {
if (cell.position >= 0 && !TextUtils.isEmpty(load)) {
cell.pos = cell.position;
mPendingCells.add(cell);
return true;
} else {
// FixMe pos not correct when insert cell
cell.pos = mHeader != null ? this.mCells.size() + 1 : this.mCells.size();
}
if (!silent && mIsActivated) {
// do cell added
cell.added();
}
this.mCells.add(index, cell);
if (mFooter != null) {
mFooter.pos = cell.pos + 1;
}
return true;
}
}
}
return false;
}
use of com.tmall.wireless.tangram.MVHelper in project Tangram-Android by alibaba.
the class PojoAdapterBuilder method newAdapter.
@Override
public PojoGroupBasicAdapter newAdapter(@NonNull final Context context, @NonNull final VirtualLayoutManager layoutManager, @NonNull final ServiceManager serviceManager) {
BaseCellBinderResolver componentBinderResolver = serviceManager.getService(BaseCellBinderResolver.class);
BaseCardBinderResolver cardBinderResolver = serviceManager.getService(BaseCardBinderResolver.class);
MVHelper mvHelper = serviceManager.getService(MVHelper.class);
ViewManager viewManager = serviceManager.getService(ViewManager.class);
final PojoGroupBasicAdapter adapter = new PojoGroupBasicAdapter(context, layoutManager, componentBinderResolver, cardBinderResolver, mvHelper, viewManager);
return adapter;
}
use of com.tmall.wireless.tangram.MVHelper in project Tangram-Android by alibaba.
the class PojoDataParser method parseSingleGroup.
/**
* {@inheritDoc}
*/
@NonNull
@Override
public Card parseSingleGroup(@Nullable JSONObject data, final ServiceManager serviceManager) {
if (data == null) {
return Card.NaN;
}
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 String cardType = data.optString(Card.KEY_TYPE);
if (!TextUtils.isEmpty(cardType)) {
final Card card = cardResolver.create(cardType);
if (card != null) {
card.serviceManager = serviceManager;
card.parseWith(data, cellResolver);
card.type = data.optInt(Card.KEY_TYPE, -1);
card.stringType = cardType;
if (card.isValid()) {
if (card.style.slidable) {
return new SlideCard(card);
} else {
return card;
}
}
} else {
final Card cellCard = new WrapCellCard();
if (cellCard != null) {
cellCard.serviceManager = serviceManager;
cellCard.parseWith(data, cellResolver);
cellCard.setStringType(TangramBuilder.TYPE_CONTAINER_1C_FLOW);
if (cellCard.isValid()) {
return cellCard;
}
}
}
} else {
LogUtils.w(TAG, "Invalid card type when parse JSON data");
}
return Card.NaN;
}
use of com.tmall.wireless.tangram.MVHelper in project Tangram-Android by alibaba.
the class PojoDataParser method parseSingleComponent.
/**
* {@inheritDoc}
*/
@NonNull
@Override
public BaseCell parseSingleComponent(@Nullable JSONObject data, Card parent, ServiceManager serviceManager) {
if (data == null) {
return BaseCell.NaN;
}
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");
BaseCell cell = Card.createCell(parent, cellResolver, data, serviceManager, true);
if (cellResolver.isValid(cell, serviceManager)) {
return cell;
} else {
return BaseCell.NaN;
}
}
use of com.tmall.wireless.tangram.MVHelper 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.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;
}
Aggregations