Search in sources :

Example 1 with BaseCell

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

the class BannerEntityCard method createCell.

private BaseCell createCell(@NonNull MVHelper resolver, @NonNull JSONObject cellData, boolean appended) {
    if (cellData != null) {
        BaseCell cell = null;
        String cellType = cellData.optString(Card.KEY_TYPE);
        if ((resolver != null && 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 null;
                }
                cell.serviceManager = serviceManager;
            } else {
                // do not support
                if (Utils.isCard(cellData)) {
                    switch(cellType) {
                        case TangramBuilder.TYPE_CONTAINER_BANNER:
                            cell = new BannerEntityCard();
                            break;
                    }
                    if (cell != null) {
                        cell.serviceManager = serviceManager;
                        cell.nestedParent = this;
                        cell.parentId = id;
                    }
                } else {
                    cell = new BaseCell(cellType);
                    cell.serviceManager = serviceManager;
                    cell.nestedParent = this;
                    cell.parentId = id;
                }
            }
            if (cell != null) {
                parseCell(resolver, cellData, cell, appended);
                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;
                cell.nestedParent = this;
                cell.parentId = id;
                parseCell(resolver, cellData, cell, appended);
                cell.setStringType(cellType);
                return cell;
            } else {
                return null;
            }
        }
    }
    return null;
}
Also used : BaseCellBinderResolver(com.tmall.wireless.tangram.dataparser.concrete.BaseCellBinderResolver) BaseCell(com.tmall.wireless.tangram.structure.BaseCell)

Example 2 with BaseCell

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

the class LinearScrollEntityCard method createCell.

private BaseCell createCell(@NonNull MVHelper resolver, @NonNull JSONObject cellData, boolean appended) {
    if (cellData != null) {
        BaseCell cell = null;
        String cellType = cellData.optString(Card.KEY_TYPE);
        if ((resolver != null && 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 null;
                }
                cell.serviceManager = serviceManager;
            } else {
                cell = new BaseCell(cellType);
                cell.serviceManager = serviceManager;
                cell.nestedParent = this;
                cell.parentId = id;
            }
            if (cell != null) {
                parseCell(resolver, cellData, cell, appended);
                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;
                cell.nestedParent = this;
                cell.parentId = id;
                parseCell(resolver, cellData, cell, appended);
                cell.setStringType(cellType);
                return cell;
            } else {
                return null;
            }
        }
    }
    return null;
}
Also used : BaseCellBinderResolver(com.tmall.wireless.tangram.dataparser.concrete.BaseCellBinderResolver) BaseCell(com.tmall.wireless.tangram.structure.BaseCell)

Example 3 with BaseCell

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

the class Card method createCell.

protected BaseCell createCell(@NonNull MVHelper resolver, @Nullable JSONObject cellData, boolean appended) {
    if (cellData != null) {
        BaseCell cell = null;
        String cellType = cellData.optString(Card.KEY_TYPE);
        if ((getMVHelper() != null && getMVHelper().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 null;
                // 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);
                            addChildCard(gridCard);
                            break;
                        case TangramBuilder.TYPE_CONTAINER_BANNER:
                            cell = new BannerEntityCard();
                            break;
                        case TangramBuilder.TYPE_CONTAINER_SCROLL:
                            cell = new LinearScrollEntityCard();
                            break;
                    }
                    if (cell != null) {
                        cell.serviceManager = serviceManager;
                        cell.parent = this;
                        cell.parentId = id;
                    } else {
                        return null;
                    }
                } else {
                    cell = new BaseCell(cellType);
                    cell.serviceManager = serviceManager;
                    cell.parent = this;
                    cell.parentId = id;
                }
            }
            parseCell(resolver, cellData, cell, appended);
            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;
                cell.parent = this;
                cell.parentId = id;
                parseCell(resolver, cellData, cell, appended);
                cell.setStringType(cellType);
                return cell;
            } else {
                return null;
            }
        }
    }
    return null;
}
Also used : BaseCell(com.tmall.wireless.tangram.structure.BaseCell) BannerEntityCard(com.tmall.wireless.tangram.structure.entitycard.BannerEntityCard) LinearScrollEntityCard(com.tmall.wireless.tangram.structure.entitycard.LinearScrollEntityCard) LinearScrollEntityCard(com.tmall.wireless.tangram.structure.entitycard.LinearScrollEntityCard) BannerEntityCard(com.tmall.wireless.tangram.structure.entitycard.BannerEntityCard)

Example 4 with BaseCell

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

the class TangramEngine method insertWith.

/**
 * A high performance method to insert cells. Do not allowed to insert to an empty Tangram. TODO handle nested card
 * @param insertPosition the position to be inserted
 * @param list new cell data list
 * @since 2.1.0
 */
public void insertWith(int insertPosition, List<BaseCell> list) {
    int newItemSize = list != null ? list.size() : 0;
    if (newItemSize > 0 && mGroupBasicAdapter != null) {
        if (insertPosition >= mGroupBasicAdapter.getItemCount()) {
            insertPosition = mGroupBasicAdapter.getItemCount() - 1;
        }
        BaseCell insertCell = mGroupBasicAdapter.getItemByPosition(insertPosition);
        int cardIdx = mGroupBasicAdapter.findCardIdxFor(insertPosition);
        Card card = mGroupBasicAdapter.getCardRange(cardIdx).second;
        card.addCells(card, card.getCells().indexOf(insertCell), list);
        List<LayoutHelper> layoutHelpers = getLayoutManager().getLayoutHelpers();
        if (layoutHelpers != null && cardIdx >= 0 && cardIdx < layoutHelpers.size()) {
            for (int i = 0, size = layoutHelpers.size(); i < size; i++) {
                LayoutHelper layoutHelper = layoutHelpers.get(i);
                int start = layoutHelper.getRange().getLower();
                int end = layoutHelper.getRange().getUpper();
                if (end < insertPosition) {
                // do nothing
                } else if (start <= insertPosition && insertPosition <= end) {
                    layoutHelper.setItemCount(layoutHelper.getItemCount() + newItemSize);
                    layoutHelper.setRange(start, end + newItemSize);
                } else if (insertPosition < start) {
                    layoutHelper.setRange(start + newItemSize, end + newItemSize);
                }
            }
            mGroupBasicAdapter.insertComponents(insertPosition, list);
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram.structure.BaseCell) LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) Card(com.tmall.wireless.tangram.dataparser.concrete.Card)

Example 5 with BaseCell

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

the class TangramEngine method topPosition.

/**
 * {@inheritDoc}
 */
@Override
public void topPosition(Card card) {
    List<BaseCell> cells = card.getCells();
    if (cells.size() > 0) {
        BaseCell cell = cells.get(0);
        int pos = mGroupBasicAdapter.getComponents().indexOf(cell);
        if (pos > 0) {
            VirtualLayoutManager lm = getLayoutManager();
            View view = lm.findViewByPosition(pos);
            if (view != null) {
                int top = lm.getDecoratedTop(view);
                RecyclerView recyclerView = getContentView();
                if (recyclerView != null) {
                    recyclerView.scrollBy(0, top);
                }
            } else {
                RecyclerView recyclerView = getContentView();
                if (recyclerView != null) {
                    recyclerView.scrollToPosition(pos);
                }
            }
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram.structure.BaseCell) RecyclerView(android.support.v7.widget.RecyclerView) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

BaseCell (com.tmall.wireless.tangram.structure.BaseCell)33 Card (com.tmall.wireless.tangram.dataparser.concrete.Card)6 JSONObject (org.json.JSONObject)6 RecyclerView (android.support.v7.widget.RecyclerView)4 ArrayList (java.util.ArrayList)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 View (android.view.View)3 Range (com.alibaba.android.vlayout.Range)3 NonNull (android.support.annotation.NonNull)2 Pair (android.util.Pair)2 LayoutHelper (com.alibaba.android.vlayout.LayoutHelper)2 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)2 MVHelper (com.tmall.wireless.tangram.MVHelper)2 BaseCellBinderResolver (com.tmall.wireless.tangram.dataparser.concrete.BaseCellBinderResolver)2 LoadGroupOp (com.tmall.wireless.tangram.op.LoadGroupOp)2 LoadMoreOp (com.tmall.wireless.tangram.op.LoadMoreOp)2 BannerEntityCard (com.tmall.wireless.tangram.structure.entitycard.BannerEntityCard)2 LinearScrollEntityCard (com.tmall.wireless.tangram.structure.entitycard.LinearScrollEntityCard)2 CardLoadSupport (com.tmall.wireless.tangram.support.async.CardLoadSupport)2