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