Search in sources :

Example 1 with MVHelper

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;
        }
    }
}
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 2 with MVHelper

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;
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) NonNull(android.support.annotation.NonNull)

Example 3 with MVHelper

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

Example 4 with MVHelper

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

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

Aggregations

MVHelper (com.tmall.wireless.tangram3.MVHelper)3 BaseCell (com.tmall.wireless.tangram3.structure.BaseCell)2 NonNull (android.support.annotation.NonNull)1 BaseCellBinderResolver (com.tmall.wireless.tangram3.dataparser.concrete.BaseCellBinderResolver)1 BusSupport (com.tmall.wireless.tangram3.eventbus.BusSupport)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 BannerSupport (com.tmall.wireless.tangram3.support.BannerSupport)1 ExposureSupport (com.tmall.wireless.tangram3.support.ExposureSupport)1 SimpleClickSupport (com.tmall.wireless.tangram3.support.SimpleClickSupport)1 TimerSupport (com.tmall.wireless.tangram3.support.TimerSupport)1