Search in sources :

Example 1 with BaseCellBinderResolver

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);
    }
}
Also used : BaseCellBinderResolver(com.tmall.wireless.tangram3.dataparser.concrete.BaseCellBinderResolver)

Example 2 with BaseCellBinderResolver

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;
}
Also used : BaseCellBinderResolver(com.tmall.wireless.tangram3.dataparser.concrete.BaseCellBinderResolver) CellSupport(com.tmall.wireless.tangram3.support.CellSupport)

Example 3 with BaseCellBinderResolver

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;
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) ArrayList(java.util.ArrayList) List(java.util.List) StickyCard(com.tmall.wireless.tangram3.structure.card.StickyCard) LinearScrollCard(com.tmall.wireless.tangram3.structure.card.LinearScrollCard) SlideCard(com.tmall.wireless.tangram3.structure.card.SlideCard) StickyEndCard(com.tmall.wireless.tangram3.structure.card.StickyEndCard) WrapCellCard(com.tmall.wireless.tangram3.structure.card.WrapCellCard) GridCard(com.tmall.wireless.tangram3.structure.card.GridCard) FixLinearScrollCard(com.tmall.wireless.tangram3.structure.card.FixLinearScrollCard) BannerCard(com.tmall.wireless.tangram3.structure.card.BannerCard) FixCard(com.tmall.wireless.tangram3.structure.card.FixCard) StaggeredCard(com.tmall.wireless.tangram3.structure.card.StaggeredCard) OnePlusNCard(com.tmall.wireless.tangram3.structure.card.OnePlusNCard)

Example 4 with BaseCellBinderResolver

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);
}
Also used : MVHelper(com.tmall.wireless.tangram3.MVHelper)

Aggregations

BaseCellBinderResolver (com.tmall.wireless.tangram3.dataparser.concrete.BaseCellBinderResolver)2 MVHelper (com.tmall.wireless.tangram3.MVHelper)1 BaseCell (com.tmall.wireless.tangram3.structure.BaseCell)1 BannerCard (com.tmall.wireless.tangram3.structure.card.BannerCard)1 FixCard (com.tmall.wireless.tangram3.structure.card.FixCard)1 FixLinearScrollCard (com.tmall.wireless.tangram3.structure.card.FixLinearScrollCard)1 GridCard (com.tmall.wireless.tangram3.structure.card.GridCard)1 LinearScrollCard (com.tmall.wireless.tangram3.structure.card.LinearScrollCard)1 OnePlusNCard (com.tmall.wireless.tangram3.structure.card.OnePlusNCard)1 SlideCard (com.tmall.wireless.tangram3.structure.card.SlideCard)1 StaggeredCard (com.tmall.wireless.tangram3.structure.card.StaggeredCard)1 StickyCard (com.tmall.wireless.tangram3.structure.card.StickyCard)1 StickyEndCard (com.tmall.wireless.tangram3.structure.card.StickyEndCard)1 WrapCellCard (com.tmall.wireless.tangram3.structure.card.WrapCellCard)1 CellSupport (com.tmall.wireless.tangram3.support.CellSupport)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1