use of com.tmall.wireless.tangram.structure.BaseCell 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);
this.getContentView().scrollBy(0, top);
} else
this.getContentView().scrollToPosition(pos);
}
}
}
use of com.tmall.wireless.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class TangramEngine method insertWith.
/**
* NOTE new API
* A high performance method to insert cells. TODO handle nested card
* @param insertPosition the position to be inserted
* @param list new cell data list
*/
public void insertWith(int insertPosition, List<BaseCell> list) {
int newItemSize = list != null ? list.size() : 0;
if (newItemSize > 0 && mGroupBasicAdapter != null) {
if (insertPosition >= mGroupBasicAdapter.getItemCount()) {
insertPosition = mGroupBasicAdapter.getItemCount() - 1;
}
BaseCell insertCell = mGroupBasicAdapter.getItemByPosition(insertPosition);
int cardIdx = mGroupBasicAdapter.findCardIdxFor(insertPosition);
Card card = mGroupBasicAdapter.getCardRange(cardIdx).second;
card.addCells(card, card.getCells().indexOf(insertCell), list);
List<LayoutHelper> layoutHelpers = getLayoutManager().getLayoutHelpers();
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 < insertPosition) {
// do nothing
} else if (start <= insertPosition && insertPosition <= end) {
layoutHelper.setItemCount(layoutHelper.getItemCount() + newItemSize);
layoutHelper.setRange(start, end + newItemSize);
} else if (insertPosition < start) {
layoutHelper.setRange(start + newItemSize, end + newItemSize);
}
}
mGroupBasicAdapter.insertComponents(insertPosition, list);
}
}
}
use of com.tmall.wireless.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class TangramEngine method removeBy.
/**
* NOTE new API
* Remove cell at target position. TODO handle nested card
* @param position
*/
protected void removeBy(int position) {
if (mGroupBasicAdapter != null) {
if (position < mGroupBasicAdapter.getItemCount() && position >= 0) {
BaseCell removeCell = mGroupBasicAdapter.getItemByPosition(position);
removeBy(removeCell);
}
}
}
use of com.tmall.wireless.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class Card method createCell.
protected BaseCell createCell(@NonNull MVHelper resolver, @Nullable JSONObject cellData, boolean appended) {
if (cellData != null) {
BaseCell cell = null;
String cellType = cellData.optString(Card.KEY_TYPE);
if ((getMVHelper() != null && getMVHelper().resolver().getViewClass(cellType) != null) || Utils.isCard(cellData)) {
if (resolver.resolver().isCompatibleType(cellType)) {
cell = Utils.newInstance(resolver.resolver().getCellClass(cellType));
// do not display when newInstance failed
if (cell == null)
return null;
// ensure service manager
cell.serviceManager = serviceManager;
} else {
if (Utils.isCard(cellData)) {
switch(cellType) {
case TangramBuilder.TYPE_CONTAINER_FLOW:
case TangramBuilder.TYPE_CONTAINER_1C_FLOW:
case TangramBuilder.TYPE_CONTAINER_2C_FLOW:
case TangramBuilder.TYPE_CONTAINER_3C_FLOW:
case TangramBuilder.TYPE_CONTAINER_4C_FLOW:
case TangramBuilder.TYPE_CONTAINER_5C_FLOW:
CardResolver cardResolver = serviceManager.getService(CardResolver.class);
Card gridCard = cardResolver.create(cellType);
gridCard.serviceManager = serviceManager;
gridCard.parseWith(cellData, resolver);
addChildCard(gridCard);
break;
case TangramBuilder.TYPE_CONTAINER_BANNER:
cell = new BannerEntityCard();
break;
case TangramBuilder.TYPE_CONTAINER_SCROLL:
cell = new LinearScrollEntityCard();
break;
}
if (cell != null) {
cell.serviceManager = serviceManager;
cell.parent = this;
cell.parentId = id;
} else {
return null;
}
} else {
cell = new BaseCell(cellType);
cell.serviceManager = serviceManager;
cell.parent = this;
cell.parentId = id;
}
}
parseCell(resolver, cellData, cell, appended);
cell.setStringType(cellType);
return cell;
} else {
// support virtual view at layout
BaseCellBinderResolver componentBinderResolver = serviceManager.getService(BaseCellBinderResolver.class);
if (componentBinderResolver.has(cellType)) {
cell = new BaseCell(cellType);
cell.serviceManager = serviceManager;
cell.parent = this;
cell.parentId = id;
parseCell(resolver, cellData, cell, appended);
cell.setStringType(cellType);
return cell;
} else {
return null;
}
}
}
return null;
}
use of com.tmall.wireless.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class Card method setCells.
public void setCells(@Nullable List<BaseCell> cells) {
if (mPlaceholderCell != null)
this.mCells.remove(mPlaceholderCell);
oldMap.clear();
pendingDeleteMap.clear();
for (BaseCell cell : this.mCells) {
oldMap.put(System.identityHashCode(cell), cell);
}
this.mCells.clear();
if (cells != null) {
for (BaseCell c : cells) {
// noinspection unchecked
this.addCellInternal(c, true);
}
}
adjustPendingCells(true);
newMap.clear();
for (BaseCell cell : this.mCells) {
newMap.put(System.identityHashCode(cell), cell);
}
for (int i = 0, size = oldMap.size(); i < size; i++) {
int key = oldMap.keyAt(i);
if (newMap.get(key) != null) {
newMap.remove(key);
pendingDeleteMap.put(key, true);
}
}
for (int i = 0, size = pendingDeleteMap.size(); i < size; i++) {
oldMap.remove(pendingDeleteMap.keyAt(i));
}
diffCells(newMap, oldMap);
newMap.clear();
oldMap.clear();
pendingDeleteMap.clear();
if (requirePlaceholderCell()) {
this.mCells.add(mPlaceholderCell);
}
}
Aggregations