use of com.tmall.wireless.tangram3.dataparser.concrete.BaseCellBinderResolver 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.dataparser.concrete.BaseCellBinderResolver in project Tangram-Android by alibaba.
the class MVHelper method isValid.
public boolean isValid(BaseCell cell, ServiceManager serviceManager) {
boolean ret = cell.isValid();
if (serviceManager != null) {
BaseCellBinderResolver componentBinderResolver = serviceManager.getService(BaseCellBinderResolver.class);
ret = ret && (componentBinderResolver.has(cell.stringType) || cell.componentInfo != null && renderManager.getRenderService(cell.componentInfo.getType()) != null);
CellSupport cellSupport = serviceManager.getService(CellSupport.class);
if (cellSupport != null) {
ret = cellSupport.isValid(cell) && ret;
}
}
return ret;
}
use of com.tmall.wireless.tangram3.dataparser.concrete.BaseCellBinderResolver 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.dataparser.concrete.BaseCellBinderResolver 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);
}
Aggregations