Search in sources :

Example 16 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card 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 Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.

the class GridCard method convertChildLayoutHelper.

private void convertChildLayoutHelper(@Nullable RangeGridLayoutHelper gridHelper, GridCard parentCard) {
    for (int i = 0, size = parentCard.getChildren().size(); i < size; i++) {
        Range<Integer> range = parentCard.getChildren().keyAt(i);
        Card child = parentCard.getChildren().valueAt(i);
        Style style = child.style;
        if (style instanceof GridStyle && child instanceof GridCard) {
            final GridStyle gridStyle = (GridStyle) style;
            final GridCard gridCard = (GridCard) child;
            if (!gridCard.getChildren().isEmpty()) {
                convertChildLayoutHelper(gridHelper, gridCard);
            }
            GridRangeStyle rangeStyle = new GridRangeStyle();
            int totalColumn = gridCard.mColumn;
            if (gridStyle.column > 0) {
                totalColumn = gridStyle.column;
                rangeStyle.setSpanCount(gridStyle.column);
            } else {
                rangeStyle.setSpanCount(totalColumn);
            }
            rangeStyle.setSpanSizeLookup(new CellSpanSizeLookup(gridCard.getCells(), totalColumn));
            rangeStyle.setVGap(gridStyle.vGap);
            rangeStyle.setHGap(gridStyle.hGap);
            rangeStyle.setAutoExpand(gridStyle.autoExpand);
            if (gridStyle.cols != null && gridStyle.cols.length > 0) {
                rangeStyle.setWeights(gridStyle.cols);
            }
            if (!Float.isNaN(gridStyle.aspectRatio)) {
                rangeStyle.setAspectRatio(gridStyle.aspectRatio);
            }
            rangeStyle.setBgColor(style.bgColor);
            rangeStyle.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]);
            rangeStyle.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]);
            if (!TextUtils.isEmpty(style.bgImgUrl)) {
                if (serviceManager != null && serviceManager.getService(CardSupport.class) != null) {
                    final CardSupport support = serviceManager.getService(CardSupport.class);
                    rangeStyle.setLayoutViewBindListener(new BindListener(style) {

                        @Override
                        public void onBind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onBindBackgroundView(layoutView, gridCard);
                        }
                    });
                    rangeStyle.setLayoutViewUnBindListener(new UnbindListener(style) {

                        @Override
                        public void onUnbind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onUnbindBackgroundView(layoutView, gridCard);
                        }
                    });
                } else {
                    rangeStyle.setLayoutViewBindListener(new BindListener(style));
                    rangeStyle.setLayoutViewUnBindListener(new UnbindListener(style));
                }
            } else {
                rangeStyle.setLayoutViewBindListener(null);
                rangeStyle.setLayoutViewUnBindListener(null);
            }
            gridHelper.addRangeStyle(range.getLower().intValue(), range.getUpper().intValue(), rangeStyle);
        }
    }
}
Also used : View(android.view.View) Card(com.tmall.wireless.tangram3.dataparser.concrete.Card) CardSupport(com.tmall.wireless.tangram3.support.CardSupport) Style(com.tmall.wireless.tangram3.dataparser.concrete.Style) GridRangeStyle(com.alibaba.android.vlayout.layout.RangeGridLayoutHelper.GridRangeStyle) GridRangeStyle(com.alibaba.android.vlayout.layout.RangeGridLayoutHelper.GridRangeStyle) BaseLayoutHelper(com.alibaba.android.vlayout.layout.BaseLayoutHelper)

Example 18 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.

the class PojoGroupBasicAdapter method replaceComponent.

@Override
public void replaceComponent(List<BaseCell> oldComponent, List<BaseCell> newComponent) {
    if (mData != null && oldComponent != null && newComponent != null && oldComponent.size() > 0 && newComponent.size() > 0) {
        int index = mData.indexOf(oldComponent.get(0));
        if (index >= 0) {
            if (mCards != null) {
                List<Pair<Range<Integer>, Card>> newCards = new ArrayList<>();
                int diff = 0;
                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 <= index) {
                        // do nothing
                        newCards.add(pair);
                    } else if (start <= index && index < end) {
                        diff = newComponent.size() - oldComponent.size();
                        Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start, end + diff), pair.second);
                        newCards.add(newPair);
                    } else if (index <= start) {
                        Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start + diff, end + diff), pair.second);
                        newCards.add(newPair);
                    }
                }
                mCards.clear();
                mCards.addAll(newCards);
            }
            for (int i = 0, size = oldComponent.size(); i < size; i++) {
                BaseCell cell = oldComponent.get(i);
                if (cell != null) {
                    cell.removed();
                }
            }
            for (int i = 0, size = newComponent.size(); i < size; i++) {
                BaseCell cell = newComponent.get(i);
                if (cell != null) {
                    cell.added();
                }
            }
            mData.removeAll(oldComponent);
            mData.addAll(index, newComponent);
            int oldSize = oldComponent.size();
            int newSize = newComponent.size();
            notifyItemRangeChanged(index, Math.max(oldSize, newSize));
        }
    }
}
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 19 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.

the class PojoGroupBasicAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(BinderViewHolder<BaseCell, ? extends View> holder, int position) {
    super.onBindViewHolder(holder, position);
    int idx = findCardIdxFor(position);
    if (idx >= 0) {
        Pair<Range<Integer>, Card> pair = mCards.get(idx);
        pair.second.onBindCell(position - pair.first.getLower(), position, mLastBindPosition < 0 || mLastBindPosition < position);
        PageDetectorSupport pageDetectorSupport = pair.second.serviceManager.getService(PageDetectorSupport.class);
        if (pageDetectorSupport != null) {
            pageDetectorSupport.onBindItem(position, mLastBindPosition < 0 || mLastBindPosition < position, getItemByPosition(position));
        }
    }
    mLastBindPosition = position;
}
Also used : PageDetectorSupport(com.tmall.wireless.tangram3.support.PageDetectorSupport) Range(com.alibaba.android.vlayout.Range)

Example 20 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.

the class SwipeItemTouchListener method updateCurrCard.

public void updateCurrCard() {
    if (recyclerView == null || lastMotionEvent == null) {
        return;
    }
    View childView = recyclerView.findChildViewUnder(lastMotionEvent.getX(), lastMotionEvent.getY());
    if (childView != null) {
        int position = layoutManager.getPosition(childView);
        currCardIdx = mGroupBasicAdapter.findCardIdxFor(position);
        List<Card> groups = mGroupBasicAdapter.getGroups();
        if (currCardIdx >= groups.size() || currCardIdx < 0) {
            Log.e(TAG, "onScroll: group size >= cardIdx");
            return;
        }
        currCard = groups.get(currCardIdx);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Card(com.tmall.wireless.tangram3.dataparser.concrete.Card) SwipeCard(com.tmall.wireless.tangram3.structure.card.SwipeCard)

Aggregations

BaseCell (com.tmall.wireless.tangram3.structure.BaseCell)15 Card (com.tmall.wireless.tangram3.dataparser.concrete.Card)11 Range (com.alibaba.android.vlayout.Range)6 ArrayList (java.util.ArrayList)6 NonNull (android.support.annotation.NonNull)5 GridCard (com.tmall.wireless.tangram3.structure.card.GridCard)5 OnePlusNCard (com.tmall.wireless.tangram3.structure.card.OnePlusNCard)5 RecyclerView (android.support.v7.widget.RecyclerView)4 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)4 JSONObject (com.alibaba.fastjson.JSONObject)4 View (android.view.View)3 LayoutHelper (com.alibaba.android.vlayout.LayoutHelper)3 JSONArray (com.alibaba.fastjson.JSONArray)3 BannerCard (com.tmall.wireless.tangram3.structure.card.BannerCard)3 FixCard (com.tmall.wireless.tangram3.structure.card.FixCard)3 FixLinearScrollCard (com.tmall.wireless.tangram3.structure.card.FixLinearScrollCard)3 LinearScrollCard (com.tmall.wireless.tangram3.structure.card.LinearScrollCard)3 SlideCard (com.tmall.wireless.tangram3.structure.card.SlideCard)3 StaggeredCard (com.tmall.wireless.tangram3.structure.card.StaggeredCard)3 StickyCard (com.tmall.wireless.tangram3.structure.card.StickyCard)3