use of com.tmall.wireless.tangram3.MVHelper in project Tangram-Android by alibaba.
the class PojoDataParser method createCell.
protected BaseCell createCell(@Nullable Card parent, @NonNull MVHelper resolver, @NonNull JSONObject cellData, @NonNull ServiceManager serviceManager, Map<String, ComponentInfo> componentInfoMap) {
BaseCell cell = null;
String cellType = parseCellType(cellData);
// cellType is null, maybe is card
if (TextUtils.isEmpty(cellType)) {
cellType = parseCardType(cellData);
}
if (TextUtils.isEmpty(cellType)) {
return BaseCell.NaN;
}
if (Utils.isCard(cellType)) {
switch(cellType) {
case TangramBuilder.TYPE_CONTAINER_FLOW:
case TangramBuilder.TYPE_CONTAINER_1C_FLOW:
case TangramBuilder.TYPE_CONTAINER_2C_FLOW:
case TangramBuilder.TYPE_CONTAINER_3C_FLOW:
case TangramBuilder.TYPE_CONTAINER_4C_FLOW:
case TangramBuilder.TYPE_CONTAINER_5C_FLOW:
{
Card card = parseSingleGroup(cellData, serviceManager);
parent.addChildCard(card);
break;
}
case TangramBuilder.TYPE_CONTAINER_BANNER:
case TangramBuilder.TYPE_CONTAINER_SCROLL:
{
Card card = parseSingleGroup(cellData, serviceManager);
List<BaseCell> children = card.getCells();
if (children.size() > 0) {
cell = card.getCells().get(0);
}
break;
}
}
if (cell != null) {
cell.serviceManager = serviceManager;
if (parent != null) {
cell.parent = parent;
cell.parentId = parent.id;
}
} else {
return BaseCell.NaN;
}
parseCell(cell, cellData);
if (parent != null) {
boolean ret = parent.addCellInternal(cell, false);
if (!ret && TangramBuilder.isPrintLog()) {
LogUtils.w(TAG, "Parse invalid cell with data: " + cellData.toString());
}
}
return cell;
} else if (resolver.resolver().getViewClass(cellType) != null) {
cell = new BaseCell(cellType);
cell.serviceManager = serviceManager;
if (parent != null) {
cell.parent = parent;
cell.parentId = parent.id;
}
parseCell(cell, cellData);
if (parent != null) {
boolean ret = parent.addCellInternal(cell, false);
if (!ret && TangramBuilder.isPrintLog()) {
LogUtils.w(TAG, "Parse invalid cell with data: " + cellData.toString());
}
}
return cell;
} else {
BaseCellBinderResolver componentBinderResolver = serviceManager.getService(BaseCellBinderResolver.class);
// if cell type not register and has component info, register it!
if (TangramBuilder.isPrintLog()) {
LogUtils.e("PojoDataParser", "createCell status: cellType=" + cellType + ", componentInfoMap=" + (componentInfoMap == null ? "null" : componentInfoMap.toString()));
}
if (!componentBinderResolver.has(cellType) && componentInfoMap != null && componentInfoMap.containsKey(cellType)) {
componentBinderResolver.register(cellType, new BaseCellBinder<>(cellType, resolver));
}
if (componentBinderResolver.has(cellType)) {
cell = new BaseCell(cellType);
if (componentInfoMap != null) {
cell.componentInfo = componentInfoMap.get(cellType);
}
cell.serviceManager = serviceManager;
if (parent != null) {
cell.parent = parent;
cell.parentId = parent.id;
parseCell(cell, cellData);
boolean ret = parent.addCellInternal(cell, false);
if (!ret && TangramBuilder.isPrintLog()) {
LogUtils.w(TAG, "Parse invalid cell with data: " + cellData.toString());
}
} else {
parseCell(cell, cellData);
}
cell.setStringType(cellType);
return cell;
} else {
return BaseCell.NaN;
}
}
}
use of com.tmall.wireless.tangram3.MVHelper in project Tangram-Android by alibaba.
the class PojoDataParser method parseSingleComponent.
@NonNull
@Override
public BaseCell parseSingleComponent(@Nullable JSONObject data, Card parent, ServiceManager serviceManager, Map<String, ComponentInfo> componentInfoMap) {
if (data == null) {
return BaseCell.NaN;
}
checkCardResolverAndMVHelper(serviceManager);
String cellType = parseCellType(data);
if (componentInfoMap == null) {
componentInfoMap = new HashMap<>();
}
ComponentInfo componentInfo = mvHelper.renderManager().supplementComponentInfo(cellType);
if (componentInfo != null) {
componentInfoMap.put(cellType, componentInfo);
}
BaseCell cell = createCell(parent, mvHelper, data, serviceManager, componentInfoMap);
if (mvHelper.isValid(cell, serviceManager)) {
return cell;
} else {
return BaseCell.NaN;
}
}
use of com.tmall.wireless.tangram3.MVHelper in project Tangram-Android by alibaba.
the class BaseTangramEngine method registerCell.
/**
* register cell after engine has been created
*
* @param type
* @param viewClz
* @param <V>
*/
public <V extends View> void registerCell(String type, @NonNull Class<V> viewClz) {
BaseCellBinderResolver baseCellBinderResolver = getService(BaseCellBinderResolver.class);
MVHelper mMVHelper = getService(MVHelper.class);
if (baseCellBinderResolver != null && mMVHelper != null && mMVHelper.resolver() != null) {
baseCellBinderResolver.register(type, new BaseCellBinder<>(viewClz, mMVHelper));
mMVHelper.resolver().register(type, viewClz);
}
}
use of com.tmall.wireless.tangram3.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);
return new PojoGroupBasicAdapter(context, layoutManager, componentBinderResolver, cardBinderResolver, mvHelper);
}
use of com.tmall.wireless.tangram3.MVHelper in project Tangram-Android by alibaba.
the class Card method addCellInternal.
public 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;
}
if (mHeader != null) {
mHeader.pos = 0;
}
return true;
}
}
}
return false;
}
Aggregations