Search in sources :

Example 6 with BaseCell

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

Example 7 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 8 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 9 with BaseCell

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

the class LinearScrollView method postBindView.

@Override
public void postBindView(BaseCell cell) {
    if (lSCell == null) {
        return;
    }
    recyclerView.setRecycledViewPool(lSCell.getRecycledViewPool());
    float[] starts = null;
    if (lSCell.cells != null && lSCell.cells.size() > 0) {
        starts = new float[lSCell.cells.size()];
        for (int i = 0; i < lSCell.cells.size(); i++) {
            starts[i] = totalDistance;
            BaseCell bc = lSCell.cells.get(i);
            if (bc.style != null && bc.style.margin.length > 0) {
                totalDistance = totalDistance + bc.style.margin[1] + bc.style.margin[3];
            }
            if (!Double.isNaN(lSCell.pageWidth)) {
                if (bc.extras.has("pageWidth")) {
                    totalDistance += Style.parseSize(bc.extras.optString("pageWidth"), 0);
                } else {
                    totalDistance += lSCell.pageWidth;
                }
            }
        }
    }
    totalDistance -= getScreenWidth();
    // calculate height of recycler view.
    ViewGroup.LayoutParams lp = recyclerView.getLayoutParams();
    if (!Double.isNaN(lSCell.pageHeight)) {
        lp.height = (int) (lSCell.pageHeight + 0.5);
    }
    recyclerView.setLayoutParams(lp);
    recyclerView.setAdapter(lSCell.adapter);
    if (lSCell.hasIndicator && totalDistance > 0) {
        setViewColor(indicator, lSCell.indicatorColor);
        setViewColor(indicatorContainer, lSCell.defaultIndicatorColor);
        indicatorContainer.setVisibility(VISIBLE);
    } else {
        indicatorContainer.setVisibility(GONE);
    }
    overScrollDecorator.setOnOverScrollListener(this);
    overScrollDecorator.setOnMotionEventListener(this);
    recyclerView.addOnScrollListener(onScrollListener);
    setBackgroundColor(lSCell.bgColor);
    if (lSCell.retainScrollState) {
        int position = computeFirstCompletelyVisibleItemPositionForScrolledX(starts);
        LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();
        lm.scrollToPositionWithOffset(position, starts == null || starts.length <= position ? 0 : (int) (starts[position] - lSCell.currentDistance));
    }
    if (lSCell.scrollMarginLeft > 0 || lSCell.scrollMarginRight > 0) {
        setPadding(lSCell.scrollMarginLeft, 0, lSCell.scrollMarginRight, 0);
        setClipToPadding(false);
        setClipChildren(false);
    } else {
        setPadding(0, 0, 0, 0);
        setClipToPadding(true);
        setClipChildren(true);
    }
    recycleView(lSCell);
    bindHeaderView(lSCell.mHeader);
    bindFooterView(lSCell.mFooter);
}
Also used : BaseCell(com.tmall.wireless.tangram.structure.BaseCell) ViewGroup(android.view.ViewGroup) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 10 with BaseCell

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

the class TangramEngine method replace.

/**
 * NOTE new API
 * Replace parent card's children. Cells' size should be equal with parent's children size.
 * @param parent
 * @param cells
 */
public void replace(Card parent, List<BaseCell> cells) {
    VirtualLayoutManager layoutManager = getLayoutManager();
    if (parent != null && cells != null && cells.size() > 0 && mGroupBasicAdapter != null && layoutManager != null) {
        Card card = parent;
        List<BaseCell> oldChildren = new ArrayList<>(parent.getCells());
        if (oldChildren.size() == cells.size()) {
            card.setCells(cells);
            mGroupBasicAdapter.replaceComponent(oldChildren, cells);
        } else {
            List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
            int cardIdx = mGroupBasicAdapter.findCardIdxForCard(parent);
            int diff = 0;
            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 (i < cardIdx) {
                    // do nothing
                    } else if (i == cardIdx) {
                        diff = cells.size() - layoutHelper.getItemCount();
                        layoutHelper.setItemCount(cells.size());
                        layoutHelper.setRange(start, end + diff);
                    } else {
                        layoutHelper.setRange(start + diff, end + diff);
                    }
                }
                card.setCells(cells);
                mGroupBasicAdapter.replaceComponent(oldChildren, cells);
            }
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram.structure.BaseCell) ArrayList(java.util.ArrayList) LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) Card(com.tmall.wireless.tangram.dataparser.concrete.Card)

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