use of com.tmall.wireless.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class BannerEntityCard method createCell.
private BaseCell createCell(@NonNull MVHelper resolver, @NonNull JSONObject cellData, boolean appended) {
if (cellData != null) {
BaseCell cell = null;
String cellType = cellData.optString(Card.KEY_TYPE);
if ((resolver != null && resolver.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;
}
cell.serviceManager = serviceManager;
} else {
// do not support
if (Utils.isCard(cellData)) {
switch(cellType) {
case TangramBuilder.TYPE_CONTAINER_BANNER:
cell = new BannerEntityCard();
break;
}
if (cell != null) {
cell.serviceManager = serviceManager;
cell.nestedParent = this;
cell.parentId = id;
}
} else {
cell = new BaseCell(cellType);
cell.serviceManager = serviceManager;
cell.nestedParent = this;
cell.parentId = id;
}
}
if (cell != null) {
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.nestedParent = 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 LinearScrollEntityCard method createCell.
private BaseCell createCell(@NonNull MVHelper resolver, @NonNull JSONObject cellData, boolean appended) {
if (cellData != null) {
BaseCell cell = null;
String cellType = cellData.optString(Card.KEY_TYPE);
if ((resolver != null && resolver.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;
}
cell.serviceManager = serviceManager;
} else {
cell = new BaseCell(cellType);
cell.serviceManager = serviceManager;
cell.nestedParent = this;
cell.parentId = id;
}
if (cell != null) {
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.nestedParent = 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 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 TangramEngine method insertWith.
/**
* A high performance method to insert cells. Do not allowed to insert to an empty Tangram. TODO handle nested card
* @param insertPosition the position to be inserted
* @param list new cell data list
* @since 2.1.0
*/
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 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);
}
}
}
}
}
Aggregations