Search in sources :

Example 16 with BaseCell

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

the class Card method addCells.

public void addCells(Card parent, int index, @Nullable List<BaseCell> cells) {
    if (cells != null) {
        int i = 0;
        for (BaseCell cell : cells) {
            addCellInternal(parent, index + i, cell, false);
            i++;
        }
    }
    adjustPendingCells(false);
    if (mPlaceholderCell != null && this.mCells.contains(mPlaceholderCell))
        this.mCells.remove(mPlaceholderCell);
    if (requirePlaceholderCell()) {
        this.mCells.add(mPlaceholderCell);
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell)

Example 17 with BaseCell

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

the class Card method adjustPendingCells.

private void adjustPendingCells(boolean silent) {
    if (mPendingCells.size() > 0) {
        Collections.sort(mPendingCells, CellPositionComparator.COMPARATOR);
        for (Iterator<BaseCell> iter = mPendingCells.iterator(); iter.hasNext(); ) {
            BaseCell next = iter.next();
            if (next.position < 0)
                continue;
            if (next.position < mCells.size()) {
                mCells.add(next.position, next);
                mInQueueCells.add(next);
                iter.remove();
                if (!silent)
                    next.added();
            } else {
                break;
            }
        }
    }
    if (mInQueueCells.size() > 0) {
        // when do clean, the cell is already removed
        Collections.sort(mInQueueCells, CellPositionComparator.REVERSE_COMPARATOR);
        for (Iterator<BaseCell> iter = mInQueueCells.iterator(); iter.hasNext(); ) {
            BaseCell next = iter.next();
            if (next.position < 0)
                continue;
            if (next.position > mCells.size()) {
                mPendingCells.add(next);
                iter.remove();
            } else {
                break;
            }
        }
    }
    if (TangramBuilder.isPrintLog()) {
        if (mPendingCells.size() > 0 && mInQueueCells.size() > 0) {
            Preconditions.checkState(mPendingCells.get(0).position >= mInQueueCells.get(mInQueueCells.size() - 1).position, "Items in pendingQueue must have large position than Items in queue");
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell)

Example 18 with BaseCell

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

the class Card method addCellInternal.

public boolean addCellInternal(@Nullable BaseCell cell, boolean silent) {
    if (cell != null) {
        cell.parentId = id;
        cell.parent = this;
        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 {
                    cell.pos = mHeader != null ? this.mCells.size() + 1 : this.mCells.size();
                }
                if (!silent && mIsActivated) {
                    // do cell added
                    cell.added();
                }
                this.mCells.add(cell);
                if (mFooter != null) {
                    mFooter.pos = cell.pos + 1;
                }
                return true;
            }
        }
    }
    return false;
}
Also used : MVHelper(com.tmall.wireless.tangram3.MVHelper)

Example 19 with BaseCell

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

the class SlideCard method storeCache.

private void storeCache() {
    List<BaseCell> initCells = getCells();
    BaseCell placeHolder = getPlaceholderCell();
    if (initCells != null && !initCells.isEmpty()) {
        TabContentCache tabContentCache = new TabContentCache(mIndex, initCells, placeHolder);
        tabContentCache.id = id;
        tabContentCache.loaded = loaded;
        tabContentCache.loading = loading;
        tabContentCache.page = page;
        tabContentCache.hasMore = hasMore;
        mCacheMap.put(mIndex, tabContentCache);
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell)

Example 20 with BaseCell

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

the class OnePlusNCard method convertLayoutHelper.

@Nullable
@Override
public LayoutHelper convertLayoutHelper(@Nullable LayoutHelper oldHelper) {
    OnePlusNLayoutHelper layoutHelper;
    if (oldHelper instanceof OnePlusNLayoutHelper) {
        layoutHelper = (OnePlusNLayoutHelper) oldHelper;
    } else {
        layoutHelper = new OnePlusNLayoutHelper();
    }
    layoutHelper.setItemCount(mCells.size());
    if (mCells.size() == 1) {
        BaseCell isHeader = mCells.get(0);
        layoutHelper.setHasHeader(isHeader.gridDisplayType == BaseCell.GridDisplayType.block);
        layoutHelper.setHasFooter(false);
    } else if (mCells.size() >= 2) {
        BaseCell isHeader = mCells.get(0);
        layoutHelper.setHasHeader(isHeader.gridDisplayType == BaseCell.GridDisplayType.block);
        BaseCell isFooter = mCells.get(mCells.size() - 1);
        layoutHelper.setHasFooter(isFooter.gridDisplayType == BaseCell.GridDisplayType.block);
    }
    if (style instanceof ColumnStyle) {
        ColumnStyle columnStyle = (ColumnStyle) style;
        if (columnStyle.cols != null && columnStyle.cols.length > 0)
            layoutHelper.setColWeights(columnStyle.cols);
        else
            layoutHelper.setColWeights(EMPTY_WEIGHTS);
        if (!Float.isNaN(style.aspectRatio)) {
            layoutHelper.setAspectRatio(style.aspectRatio);
        }
        if (columnStyle.rows != null && columnStyle.rows.length > 0) {
            layoutHelper.setRowWeight(columnStyle.rows[0]);
        }
        layoutHelper.setBgColor(columnStyle.bgColor);
        layoutHelper.setMargin(style.margin[Style.MARGIN_LEFT_INDEX], style.margin[Style.MARGIN_TOP_INDEX], style.margin[Style.MARGIN_RIGHT_INDEX], style.margin[Style.MARGIN_BOTTOM_INDEX]);
        layoutHelper.setPadding(style.padding[Style.MARGIN_LEFT_INDEX], style.padding[Style.MARGIN_TOP_INDEX], style.padding[Style.MARGIN_RIGHT_INDEX], style.padding[Style.MARGIN_BOTTOM_INDEX]);
    }
    return layoutHelper;
}
Also used : ColumnStyle(com.tmall.wireless.tangram3.structure.style.ColumnStyle) BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) OnePlusNLayoutHelper(com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper) Nullable(android.support.annotation.Nullable)

Aggregations

BaseCell (com.tmall.wireless.tangram3.structure.BaseCell)21 RecyclerView (android.support.v7.widget.RecyclerView)7 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)5 ArrayList (java.util.ArrayList)5 Range (com.alibaba.android.vlayout.Range)4 JSONObject (com.alibaba.fastjson.JSONObject)4 BinderViewHolder (com.tmall.wireless.tangram3.core.adapter.BinderViewHolder)4 GroupBasicAdapter (com.tmall.wireless.tangram3.core.adapter.GroupBasicAdapter)4 Card (com.tmall.wireless.tangram3.dataparser.concrete.Card)4 GridCard (com.tmall.wireless.tangram3.structure.card.GridCard)4 OnePlusNCard (com.tmall.wireless.tangram3.structure.card.OnePlusNCard)4 NonNull (android.support.annotation.NonNull)3 LayoutHelper (com.alibaba.android.vlayout.LayoutHelper)3 ColumnStyle (com.tmall.wireless.tangram3.structure.style.ColumnStyle)3 CellSupport (com.tmall.wireless.tangram3.support.CellSupport)3 Pair (android.util.Pair)2 View (android.view.View)2 JSONArray (com.alibaba.fastjson.JSONArray)2 MVHelper (com.tmall.wireless.tangram3.MVHelper)2 BannerCard (com.tmall.wireless.tangram3.structure.card.BannerCard)2