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);
}
}
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();
}
}
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);
}
}
}
}
}
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);
}
}
}
}
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);
}
}
}
Aggregations