Search in sources :

Example 16 with BaseCell

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

Example 17 with BaseCell

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

the class PojoDataParser method parseComponent.

@Nullable
public List<BaseCell> parseComponent(JSONArray data, ServiceManager serviceManager, Card card) {
    if (data == null) {
        return new ArrayList<>();
    }
    final CardResolver cardResolver = serviceManager.getService(CardResolver.class);
    Preconditions.checkState(cardResolver != null, "Must register CardResolver into ServiceManager first");
    final MVHelper cellResolver = serviceManager.getService(MVHelper.class);
    Preconditions.checkState(cellResolver != null, "Must register CellResolver into ServiceManager first");
    final int size = data.length();
    final List<BaseCell> result = new ArrayList<>(size);
    // 解析 body 组件
    JSONArray componentArray = data;
    if (componentArray != null) {
        final int cellLength = componentArray.length();
        for (int i = 0; i < cellLength; i++) {
            final JSONObject cellData = componentArray.optJSONObject(i);
            BaseCell cell = createCell(cellResolver, cellData, serviceManager);
            if (cell != null && cellResolver.isValid(cell, serviceManager)) {
                result.add(cell);
            }
        }
    }
    return result;
}
Also used : JSONObject(org.json.JSONObject) BaseCell(com.tmall.wireless.tangram.structure.BaseCell) MVHelper(com.tmall.wireless.tangram.MVHelper) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Nullable(android.support.annotation.Nullable)

Example 18 with BaseCell

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

the class TangramEngine method scrollToPosition.

/**
 * {@inheritDoc}
 */
@Override
public void scrollToPosition(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) {
            this.getContentView().scrollToPosition(pos);
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram.structure.BaseCell)

Example 19 with BaseCell

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

Example 20 with BaseCell

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

Aggregations

BaseCell (com.tmall.wireless.tangram.structure.BaseCell)26 JSONObject (org.json.JSONObject)5 Card (com.tmall.wireless.tangram.dataparser.concrete.Card)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 Nullable (android.support.annotation.Nullable)2 View (android.view.View)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 BannerEntityCard (com.tmall.wireless.tangram.structure.entitycard.BannerEntityCard)2 LinearScrollEntityCard (com.tmall.wireless.tangram.structure.entitycard.LinearScrollEntityCard)2 ArrayList (java.util.ArrayList)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ViewGroup (android.view.ViewGroup)1 Range (com.alibaba.android.vlayout.Range)1 OnePlusNLayoutHelper (com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper)1 Engine (com.tmall.wireless.tangram.Engine)1