use of com.tmall.wireless.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class SlideCard method storeCache.
private void storeCache() {
List<BaseCell> initCells = getCells();
BaseCell placeHolder = getPlaceholderCell();
if (initCells != null && !initCells.isEmpty()) {
TabContentCache tabContentCache = new TabContentCache(mIndex, initCells, placeHolder);
tabContentCache.id = id;
tabContentCache.loaded = loaded;
tabContentCache.loading = loading;
tabContentCache.page = page;
tabContentCache.hasMore = hasMore;
mCacheMap.put(mIndex, tabContentCache);
}
}
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 LinearScrollView method postBindView.
@Override
public void postBindView(BaseCell cell) {
if (lSCell == null) {
return;
}
recyclerView.setRecycledViewPool(lSCell.getRecycledViewPool());
float[] starts = null;
if (lSCell.cells != null && lSCell.cells.size() > 0) {
starts = new float[lSCell.cells.size()];
for (int i = 0; i < lSCell.cells.size(); i++) {
starts[i] = totalDistance;
BaseCell bc = lSCell.cells.get(i);
if (bc.style != null && bc.style.margin.length > 0) {
totalDistance = totalDistance + bc.style.margin[1] + bc.style.margin[3];
}
if (!Double.isNaN(lSCell.pageWidth)) {
if (bc.extras.has("pageWidth")) {
totalDistance += Style.parseSize(bc.extras.optString("pageWidth"), 0);
} else {
totalDistance += lSCell.pageWidth;
}
}
}
}
totalDistance -= getScreenWidth();
// calculate height of recycler view.
ViewGroup.LayoutParams lp = recyclerView.getLayoutParams();
if (!Double.isNaN(lSCell.pageHeight)) {
lp.height = (int) (lSCell.pageHeight + 0.5);
}
recyclerView.setLayoutParams(lp);
recyclerView.setAdapter(lSCell.adapter);
if (lSCell.hasIndicator && totalDistance > 0) {
setViewColor(indicator, lSCell.indicatorColor);
setViewColor(indicatorContainer, lSCell.defaultIndicatorColor);
indicatorContainer.setVisibility(VISIBLE);
} else {
indicatorContainer.setVisibility(GONE);
}
overScrollDecorator.setOnOverScrollListener(this);
overScrollDecorator.setOnMotionEventListener(this);
recyclerView.addOnScrollListener(onScrollListener);
setBackgroundColor(lSCell.bgColor);
if (lSCell.retainScrollState) {
int position = computeFirstCompletelyVisibleItemPositionForScrolledX(starts);
LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();
lm.scrollToPositionWithOffset(position, starts == null || starts.length <= position ? 0 : (int) (starts[position] - lSCell.currentDistance));
}
if (lSCell.scrollMarginLeft > 0 || lSCell.scrollMarginRight > 0) {
setPadding(lSCell.scrollMarginLeft, 0, lSCell.scrollMarginRight, 0);
setClipToPadding(false);
setClipChildren(false);
} else {
setPadding(0, 0, 0, 0);
setClipToPadding(true);
setClipChildren(true);
}
recycleView(lSCell);
bindHeaderView(lSCell.mHeader);
bindFooterView(lSCell.mFooter);
}
use of com.tmall.wireless.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class TangramEngine method replace.
/**
* NOTE new API
* Replace parent card's children. Cells' size should be equal with parent's children size.
* @param parent
* @param cells
*/
public void replace(Card parent, List<BaseCell> cells) {
VirtualLayoutManager layoutManager = getLayoutManager();
if (parent != null && cells != null && cells.size() > 0 && mGroupBasicAdapter != null && layoutManager != null) {
Card card = parent;
List<BaseCell> oldChildren = new ArrayList<>(parent.getCells());
if (oldChildren.size() == cells.size()) {
card.setCells(cells);
mGroupBasicAdapter.replaceComponent(oldChildren, cells);
} else {
List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
int cardIdx = mGroupBasicAdapter.findCardIdxForCard(parent);
int diff = 0;
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 (i < cardIdx) {
// do nothing
} else if (i == cardIdx) {
diff = cells.size() - layoutHelper.getItemCount();
layoutHelper.setItemCount(cells.size());
layoutHelper.setRange(start, end + diff);
} else {
layoutHelper.setRange(start + diff, end + diff);
}
}
card.setCells(cells);
mGroupBasicAdapter.replaceComponent(oldChildren, cells);
}
}
}
}
Aggregations