Search in sources :

Example 26 with Card

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

the class PojoDataParser method parseFooterCell.

protected void parseFooterCell(BaseCell footerCell, Card card) {
    card.mFooter = footerCell;
    if (card instanceof GridCard) {
        GridCard gridCard = (GridCard) card;
        gridCard.ensureBlock(card.mFooter);
    } else if (card instanceof OnePlusNCard) {
        OnePlusNCard onePlusNCard = (OnePlusNCard) card;
        onePlusNCard.ensureBlock(card.mFooter);
    }
}
Also used : GridCard(com.tmall.wireless.tangram3.structure.card.GridCard) OnePlusNCard(com.tmall.wireless.tangram3.structure.card.OnePlusNCard)

Example 27 with Card

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

the class TangramEngine method onScrolled.

/**
 * Call this method in RecyclerView's scroll listener. Would trigger the preload of card's data.
 */
public void onScrolled() {
    // due to a bug in 21: https://code.google.com/p/android/issues/detail?id=162753, which cause getDecoratedStart() throws NullPointException
    // officially reported it has been fixed in v22
    final int lastPosition = getLayoutManager().findLastVisibleItemPosition();
    final int firstPosition = getLayoutManager().findFirstVisibleItemPosition();
    int lastCardIndex = -1;
    int firstCardIndex = -1;
    int position = lastPosition;
    // find the last visible item in card
    for (int i = lastPosition; i >= firstPosition; i--) {
        lastCardIndex = mGroupBasicAdapter.findCardIdxFor(i);
        if (lastCardIndex >= 0) {
            position = i;
            break;
        }
    }
    for (int i = firstCardIndex; i <= lastPosition; i++) {
        firstCardIndex = mGroupBasicAdapter.findCardIdxFor(i);
        if (firstCardIndex >= 0) {
            break;
        }
    }
    if (lastCardIndex < 0 || firstCardIndex < 0)
        return;
    final CardLoadSupport loadSupport = getService(CardLoadSupport.class);
    if (loadSupport == null)
        return;
    List<Card> cards = mGroupBasicAdapter.getGroups();
    // check the loadmore state of current card first  range is inclusive-exclusive
    Card current = cards.get(lastCardIndex);
    Pair<Range<Integer>, Card> pair = mGroupBasicAdapter.getCardRange(lastCardIndex);
    if (pair != null && position >= pair.first.getUpper() - mPreLoadNumber) {
        // async load
        if (!TextUtils.isEmpty(current.load) && current.loaded) {
            // page load
            if (current.loadMore) {
                loadSupport.loadMore(current);
                loadSupport.reactiveDoLoadMore(current);
            }
            return;
        }
    }
    boolean loadedMore = false;
    for (int i = firstCardIndex; i < Math.min(lastCardIndex + mPreLoadNumber, cards.size()); i++) {
        Card c = cards.get(i);
        // async load
        if (!TextUtils.isEmpty(c.load) && !c.loaded) {
            // page load
            if (c.loadMore && !loadedMore) {
                // only load one load more card
                loadSupport.loadMore(c);
                loadSupport.reactiveDoLoadMore(c);
                loadedMore = true;
            } else {
                loadSupport.doLoad(c);
                loadSupport.reactiveDoLoad(c);
            }
            c.loaded = true;
        }
    }
    if (mEnableAutoLoadMore && mGroupBasicAdapter.getItemCount() - position < mPreLoadNumber) {
        loadMoreCard();
    }
}
Also used : CardLoadSupport(com.tmall.wireless.tangram3.support.async.CardLoadSupport) Range(com.alibaba.android.vlayout.Range) Card(com.tmall.wireless.tangram3.dataparser.concrete.Card)

Example 28 with Card

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

the class TangramEngine method topPosition.

/**
 * {@inheritDoc}
 */
@Override
public void topPosition(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) {
            VirtualLayoutManager lm = getLayoutManager();
            View view = lm.findViewByPosition(pos);
            if (view != null) {
                int top = lm.getDecoratedTop(view);
                RecyclerView recyclerView = getContentView();
                if (recyclerView != null) {
                    recyclerView.scrollBy(0, top);
                }
            } else {
                RecyclerView recyclerView = getContentView();
                if (recyclerView != null) {
                    recyclerView.scrollToPosition(pos);
                }
            }
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) RecyclerView(android.support.v7.widget.RecyclerView) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 29 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card 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) {
            RecyclerView recyclerView = getContentView();
            if (recyclerView != null) {
                recyclerView.scrollToPosition(pos);
            }
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) RecyclerView(android.support.v7.widget.RecyclerView)

Example 30 with Card

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

the class TangramEngine method removeBy.

/**
 * Remove cell at target position. TODO handle nested card
 *
 * @param position
 * @since 2.1.0
 */
public void removeBy(int position) {
    if (mGroupBasicAdapter != null) {
        if (position < mGroupBasicAdapter.getItemCount() && position >= 0) {
            BaseCell removeCell = mGroupBasicAdapter.getItemByPosition(position);
            removeBy(removeCell);
        }
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell)

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