Search in sources :

Example 1 with LinearScrollCard

use of com.tmall.wireless.tangram.structure.card.LinearScrollCard in project Tangram-Android by alibaba.

the class Card method createCell.

public static BaseCell createCell(@Nullable Card parent, @NonNull MVHelper resolver, @NonNull JSONObject cellData, @NonNull ServiceManager serviceManager, boolean appended) {
    if (cellData != null) {
        BaseCell cell = null;
        String cellType = cellData.optString(Card.KEY_TYPE);
        if ((resolver.resolver().getViewClass(cellType) != null) || Utils.isCard(cellData)) {
            if (resolver.resolver().isCompatibleType(cellType)) {
                cell = Utils.newInstance(resolver.resolver().getCellClass(cellType));
                // do not display when newInstance failed
                if (cell == null) {
                    return BaseCell.NaN;
                }
                // ensure service manager
                cell.serviceManager = serviceManager;
            } else {
                if (Utils.isCard(cellData)) {
                    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:
                            CardResolver cardResolver = serviceManager.getService(CardResolver.class);
                            Card gridCard = cardResolver.create(cellType);
                            gridCard.serviceManager = serviceManager;
                            gridCard.parseWith(cellData, resolver);
                            parent.addChildCard(gridCard);
                            break;
                        case TangramBuilder.TYPE_CONTAINER_BANNER:
                            BannerCard bannerCard = new BannerCard();
                            bannerCard.serviceManager = serviceManager;
                            bannerCard.parseWith(cellData, resolver);
                            List<BaseCell> bannerChildren = bannerCard.getCells();
                            if (bannerChildren.size() > 0) {
                                cell = bannerCard.getCells().get(0);
                            }
                            break;
                        case TangramBuilder.TYPE_CONTAINER_SCROLL:
                            LinearScrollCard linearScrollCard = new LinearScrollCard();
                            linearScrollCard.serviceManager = serviceManager;
                            linearScrollCard.parseWith(cellData, resolver);
                            List<BaseCell> scrollChildren = linearScrollCard.getCells();
                            if (scrollChildren.size() > 0) {
                                cell = linearScrollCard.getCells().get(0);
                            }
                            break;
                    }
                    if (cell != null) {
                        cell.serviceManager = serviceManager;
                        if (parent != null) {
                            cell.parent = parent;
                            cell.parentId = parent.id;
                        }
                    } else {
                        return BaseCell.NaN;
                    }
                } else {
                    cell = new BaseCell(cellType);
                    cell.serviceManager = serviceManager;
                    if (parent != null) {
                        cell.parent = parent;
                        cell.parentId = parent.id;
                    }
                }
            }
            if (parent != null) {
                parent.parseCell(resolver, cellData, cell, appended);
            } else {
                resolver.parseCell(cell, cellData);
            }
            cell.setStringType(cellType);
            return cell;
        } else {
            // support virtual view at layout
            BaseCellBinderResolver componentBinderResolver = serviceManager.getService(BaseCellBinderResolver.class);
            if (componentBinderResolver.has(cellType)) {
                cell = new BaseCell(cellType);
                cell.serviceManager = serviceManager;
                if (parent != null) {
                    cell.parent = parent;
                    cell.parentId = parent.id;
                    parent.parseCell(resolver, cellData, cell, appended);
                } else {
                    resolver.parseCell(cell, cellData);
                }
                cell.setStringType(cellType);
                return cell;
            } else {
                return BaseCell.NaN;
            }
        }
    }
    return BaseCell.NaN;
}
Also used : BaseCell(com.tmall.wireless.tangram.structure.BaseCell) BannerCard(com.tmall.wireless.tangram.structure.card.BannerCard) LinearScrollCard(com.tmall.wireless.tangram.structure.card.LinearScrollCard) BannerCard(com.tmall.wireless.tangram.structure.card.BannerCard) LinearScrollCard(com.tmall.wireless.tangram.structure.card.LinearScrollCard)

Aggregations

BaseCell (com.tmall.wireless.tangram.structure.BaseCell)1 BannerCard (com.tmall.wireless.tangram.structure.card.BannerCard)1 LinearScrollCard (com.tmall.wireless.tangram.structure.card.LinearScrollCard)1