Search in sources :

Example 16 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper in project vlayout by alibaba.

the class BaseLayoutHelper method computeStartSpace.

protected int computeStartSpace(LayoutManagerHelper helper, boolean layoutInVertical, boolean isLayoutEnd, boolean isOverLapMargin) {
    int startSpace = 0;
    LayoutHelper lastLayoutHelper = null;
    if (helper instanceof VirtualLayoutManager) {
        lastLayoutHelper = ((VirtualLayoutManager) helper).findNeighbourNonfixLayoutHelper(this, isLayoutEnd);
    }
    MarginLayoutHelper lastMarginLayoutHelper = null;
    if (lastLayoutHelper != null && lastLayoutHelper instanceof MarginLayoutHelper) {
        lastMarginLayoutHelper = (MarginLayoutHelper) lastLayoutHelper;
    }
    if (lastLayoutHelper == this)
        return 0;
    if (!isOverLapMargin) {
        startSpace = layoutInVertical ? mMarginTop + mPaddingTop : mMarginLeft + mPaddingLeft;
    } else {
        int offset = 0;
        if (lastMarginLayoutHelper == null) {
            offset = layoutInVertical ? mMarginTop + mPaddingTop : mMarginLeft + mPaddingLeft;
        } else {
            offset = layoutInVertical ? (isLayoutEnd ? calGap(lastMarginLayoutHelper.mMarginBottom, mMarginTop) : calGap(lastMarginLayoutHelper.mMarginTop, mMarginBottom)) : (isLayoutEnd ? calGap(lastMarginLayoutHelper.mMarginRight, mMarginLeft) : calGap(lastMarginLayoutHelper.mMarginLeft, mMarginRight));
        }
        // Log.e("huang", "computeStartSpace offset: " + offset + ", isLayoutEnd: " + isLayoutEnd + ", " + this);
        startSpace += layoutInVertical ? (isLayoutEnd ? mPaddingTop : mPaddingBottom) : (isLayoutEnd ? mPaddingLeft : mPaddingRight);
        startSpace += offset;
    }
    return startSpace;
}
Also used : LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager)

Example 17 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.

the class TangramEngine method removeBy.

/**
 * Remove target cell. TODO handle nested card, cell in staggered, cell in onePlusN
 * @param data
 * @since 2.1.0
 */
protected void removeBy(BaseCell data) {
    VirtualLayoutManager layoutManager = getLayoutManager();
    if (data != null && mGroupBasicAdapter != null && layoutManager != null) {
        int removePosition = mGroupBasicAdapter.getPositionByItem(data);
        if (removePosition >= 0) {
            int cardIdx = mGroupBasicAdapter.findCardIdxFor(removePosition);
            Card card = mGroupBasicAdapter.getCardRange(cardIdx).second;
            card.removeCellSilently(data);
            List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
            LayoutHelper emptyLayoutHelper = null;
            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 (end < removePosition) {
                    // do nothing
                    } else if (start <= removePosition && removePosition <= end) {
                        int itemCount = layoutHelper.getItemCount() - 1;
                        if (itemCount > 0) {
                            layoutHelper.setItemCount(itemCount);
                            layoutHelper.setRange(start, end - 1);
                        } else {
                            emptyLayoutHelper = layoutHelper;
                        }
                    } else if (removePosition < start) {
                        layoutHelper.setRange(start - 1, end - 1);
                    }
                }
                if (emptyLayoutHelper != null) {
                    final List<LayoutHelper> newLayoutHelpers = new LinkedList<>(layoutHelpers);
                    newLayoutHelpers.remove(emptyLayoutHelper);
                    layoutManager.setLayoutHelpers(newLayoutHelpers);
                }
                mGroupBasicAdapter.removeComponent(data);
            }
        }
    }
}
Also used : LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) LinkedList(java.util.LinkedList) Card(com.tmall.wireless.tangram.dataparser.concrete.Card)

Example 18 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.

the class TangramEngine method removeBatchBy.

/**
 * Remove all cells in a card.
 * @param group
 * @since 2.1.0
 */
protected void removeBatchBy(Card group) {
    VirtualLayoutManager layoutManager = getLayoutManager();
    if (group != null && mGroupBasicAdapter != null && layoutManager != null) {
        int cardIdx = mGroupBasicAdapter.findCardIdxForCard(group);
        List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
        LayoutHelper emptyLayoutHelper = null;
        int removeItemCount = 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) {
                    removeItemCount = layoutHelper.getItemCount();
                    emptyLayoutHelper = layoutHelper;
                } else {
                    layoutHelper.setRange(start - removeItemCount, end - removeItemCount);
                }
            }
            if (emptyLayoutHelper != null) {
                final List<LayoutHelper> newLayoutHelpers = new LinkedList<>(layoutHelpers);
                newLayoutHelpers.remove(emptyLayoutHelper);
                layoutManager.setLayoutHelpers(newLayoutHelpers);
            }
            mGroupBasicAdapter.removeComponents(group);
        }
    }
}
Also used : LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) LinkedList(java.util.LinkedList)

Example 19 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.

the class TangramEngine method replace.

/**
 * Replace card one by one. New one's children size should be equal with old one's children size.
 * @param oldOne
 * @param newOne
 * @since 2.1.0
 */
public void replace(Card oldOne, Card newOne) {
    VirtualLayoutManager layoutManager = getLayoutManager();
    if (oldOne != null && newOne != null && mGroupBasicAdapter != null && layoutManager != null) {
        List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
        int cardIdx = mGroupBasicAdapter.findCardIdxForCard(oldOne);
        if (layoutHelpers != null && cardIdx >= 0 && cardIdx < layoutHelpers.size()) {
            final List<LayoutHelper> newLayoutHelpers = new LinkedList<>();
            for (int i = 0, size = layoutHelpers.size(); i < size; i++) {
                LayoutHelper layoutHelper = layoutHelpers.get(i);
                if (i == cardIdx) {
                    layoutHelper = newOne.getLayoutHelper();
                }
                newLayoutHelpers.add(layoutHelper);
            }
            layoutManager.setLayoutHelpers(newLayoutHelpers);
            mGroupBasicAdapter.replaceComponent(oldOne, newOne);
        }
    }
}
Also used : LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) LinkedList(java.util.LinkedList)

Example 20 with LayoutHelper

use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.

the class GroupBasicAdapter method transformCards.

/**
 * Transform cards to layoutHelpers with correct range and add cells in cards into data
 *
 * @param cards cards will be transformed
 * @param data  list of items that items will be added to
 * @return helpers transformed from cards
 */
@NonNull
protected List<LayoutHelper> transformCards(@Nullable List<L> cards, @NonNull final List<C> data, @NonNull List<Pair<Range<Integer>, L>> rangeCards) {
    if (cards == null || cards.size() == 0) {
        return new LinkedList<>();
    }
    int lastPos = data.size();
    List<LayoutHelper> helpers = new ArrayList<>(cards.size());
    for (int i = 0, size = cards.size(); i < size; i++) {
        L card = cards.get(i);
        if (card == null)
            continue;
        final String ctype = getCardStringType(card);
        List<C> items = getItems(card);
        if (items == null) {
            // skip card null
            continue;
        }
        data.addAll(items);
        // calculate offset to set ranges
        int offset = lastPos;
        lastPos += items.size();
        // include [x, x) for empty range, upper are not included in range
        rangeCards.add(Pair.create(Range.create(offset, lastPos), card));
        // get layoutHelper for this card
        LayoutBinder<L> binder = mCardBinderResolver.create(ctype);
        LayoutHelper helper = binder.getHelper(ctype, card);
        if (helper != null) {
            helper.setItemCount(items.size());
            helpers.add(helper);
        }
    }
    return helpers;
}
Also used : ArrayList(java.util.ArrayList) LayoutHelper(com.alibaba.android.vlayout.LayoutHelper) LinkedList(java.util.LinkedList) NonNull(android.support.annotation.NonNull)

Aggregations

LayoutHelper (com.alibaba.android.vlayout.LayoutHelper)26 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)13 LinkedList (java.util.LinkedList)9 View (android.view.View)7 Nullable (android.support.annotation.Nullable)6 ArrayList (java.util.ArrayList)6 RecyclerView (android.support.v7.widget.RecyclerView)5 FixLayoutHelper (com.alibaba.android.vlayout.layout.FixLayoutHelper)3 Card (com.tmall.wireless.tangram.dataparser.concrete.Card)3 Card (com.tmall.wireless.tangram3.dataparser.concrete.Card)3 NonNull (android.support.annotation.NonNull)2 ViewPropertyAnimator (android.view.ViewPropertyAnimator)2 ImageView (android.widget.ImageView)2 BaseLayoutHelper (com.alibaba.android.vlayout.layout.BaseLayoutHelper)2 FixAreaLayoutHelper (com.alibaba.android.vlayout.layout.FixAreaLayoutHelper)2 GridLayoutHelper (com.alibaba.android.vlayout.layout.GridLayoutHelper)2 MarginLayoutHelper (com.alibaba.android.vlayout.layout.MarginLayoutHelper)2 RangeGridLayoutHelper (com.alibaba.android.vlayout.layout.RangeGridLayoutHelper)2 BaseCell (com.tmall.wireless.tangram.structure.BaseCell)2 BaseCell (com.tmall.wireless.tangram3.structure.BaseCell)2