Search in sources :

Example 11 with BaseCell

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

the class Card method diffCells.

private void diffCells(@NonNull SparseArray<BaseCell> added, @NonNull SparseArray<BaseCell> removed) {
    if (!mIsActivated)
        return;
    for (int i = 0, size = added.size(); i < size; i++) {
        int key = added.keyAt(i);
        BaseCell cell = added.get(key);
        if (cell != null) {
            cell.added();
        }
    }
    for (int i = 0, size = removed.size(); i < size; i++) {
        int key = removed.keyAt(i);
        BaseCell cell = removed.get(key);
        if (cell != null) {
            cell.removed();
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell)

Example 12 with BaseCell

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

the class PojoGroupBasicAdapter method insertComponents.

@Override
public void insertComponents(int pos, List<BaseCell> components) {
    if (mData != null && mData.size() > 0 && components != null && !components.isEmpty() && pos >= 0) {
        int newItemSize = components.size();
        if (mCards != null) {
            List<Pair<Range<Integer>, Card>> newCards = new ArrayList<>();
            for (int i = 0, size = mCards.size(); i < size; i++) {
                Pair<Range<Integer>, Card> pair = mCards.get(i);
                int start = pair.first.getLower();
                int end = pair.first.getUpper();
                if (end < pos) {
                    // do nothing
                    newCards.add(pair);
                } else if (start <= pos && pos < end) {
                    Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start, end + newItemSize), pair.second);
                    newCards.add(newPair);
                } else if (pos <= start) {
                    Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start + newItemSize, end + newItemSize), pair.second);
                    newCards.add(newPair);
                }
            }
            mCards.clear();
            mCards.addAll(newCards);
        }
        for (int i = 0, size = components.size(); i < size; i++) {
            BaseCell cell = components.get(i);
            if (cell != null) {
                cell.added();
            }
        }
        for (int i = 0; i < newItemSize; i++) {
            if ((pos + i) < mData.size()) {
                mData.add(pos + i, components.get(i));
            } else {
                mData.add(components.get(i));
            }
        }
        notifyItemRangeInserted(pos, newItemSize);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) ArrayList(java.util.ArrayList) Range(com.alibaba.android.vlayout.Range) Pair(android.util.Pair)

Example 13 with BaseCell

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

the class GridCard method addChildCard.

@Override
public void addChildCard(Card card) {
    if (card == null) {
        return;
    }
    List<BaseCell> subCells = card.getCells();
    if (subCells != null && !subCells.isEmpty()) {
        addCells(card.getCells());
        int startOffset = mCells.indexOf(subCells.get(0));
        int endOffset = mCells.indexOf(subCells.get(subCells.size() - 1));
        Range range = Range.create(startOffset, endOffset);
        mChildren.put(range, card);
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) Range(com.alibaba.android.vlayout.Range)

Example 14 with BaseCell

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

the class LinearScrollView method recycleView.

private void recycleView(@NonNull BaseCell cell) {
    if (!mViewHolders.isEmpty()) {
        RecyclerView.RecycledViewPool pool = cell.serviceManager.getService(RecyclerView.RecycledViewPool.class);
        for (int i = 0, size = mViewHolders.size(); i < size; i++) {
            BinderViewHolder viewHolder = mViewHolders.get(i);
            viewHolder.unbind();
            removeView(viewHolder.itemView);
            pool.putRecycledView(viewHolder);
        }
        mViewHolders.clear();
    }
}
Also used : BinderViewHolder(com.tmall.wireless.tangram3.core.adapter.BinderViewHolder) RecyclerView(android.support.v7.widget.RecyclerView)

Example 15 with BaseCell

use of com.tmall.wireless.tangram3.structure.BaseCell 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

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