use of com.tmall.wireless.tangram.structure.BaseCell 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.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class PojoDataParser method parseComponent.
@Nullable
public List<BaseCell> parseComponent(JSONArray data, ServiceManager serviceManager, Card card) {
if (data == null) {
return new ArrayList<>();
}
final CardResolver cardResolver = serviceManager.getService(CardResolver.class);
Preconditions.checkState(cardResolver != null, "Must register CardResolver into ServiceManager first");
final MVHelper cellResolver = serviceManager.getService(MVHelper.class);
Preconditions.checkState(cellResolver != null, "Must register CellResolver into ServiceManager first");
final int size = data.length();
final List<BaseCell> result = new ArrayList<>(size);
// 解析 body 组件
JSONArray componentArray = data;
if (componentArray != null) {
final int cellLength = componentArray.length();
for (int i = 0; i < cellLength; i++) {
final JSONObject cellData = componentArray.optJSONObject(i);
BaseCell cell = createCell(cellResolver, cellData, serviceManager);
if (cell != null && cellResolver.isValid(cell, serviceManager)) {
result.add(cell);
}
}
}
return result;
}
use of com.tmall.wireless.tangram.structure.BaseCell 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) {
this.getContentView().scrollToPosition(pos);
}
}
}
use of com.tmall.wireless.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class Card method diffCells.
private void diffCells(@NonNull SparseArray<BaseCell> added, @NonNull SparseArray<BaseCell> removed) {
if (!mIsActivated)
return;
for (int i = 0, size = added.size(); i < size; i++) {
int key = added.keyAt(i);
BaseCell cell = added.get(key);
if (cell != null) {
cell.added();
}
}
for (int i = 0, size = removed.size(); i < size; i++) {
int key = removed.keyAt(i);
BaseCell cell = removed.get(key);
if (cell != null) {
cell.removed();
}
}
}
use of com.tmall.wireless.tangram.structure.BaseCell in project Tangram-Android by alibaba.
the class Card method adjustPendingCells.
private void adjustPendingCells(boolean silent) {
if (mPendingCells.size() > 0) {
Collections.sort(mPendingCells, CellPositionComparator.COMPARATOR);
for (Iterator<BaseCell> iter = mPendingCells.iterator(); iter.hasNext(); ) {
BaseCell next = iter.next();
if (next.position < 0)
continue;
if (next.position < mCells.size()) {
mCells.add(next.position, next);
mInQueueCells.add(next);
iter.remove();
if (!silent)
next.added();
} else {
break;
}
}
}
if (mInQueueCells.size() > 0) {
// when do clean, the cell is already removed
Collections.sort(mInQueueCells, CellPositionComparator.REVERSE_COMPARATOR);
for (Iterator<BaseCell> iter = mInQueueCells.iterator(); iter.hasNext(); ) {
BaseCell next = iter.next();
if (next.position < 0)
continue;
if (next.position > mCells.size()) {
mPendingCells.add(next);
iter.remove();
} else {
break;
}
}
}
if (TangramBuilder.isPrintLog()) {
if (mPendingCells.size() > 0 && mInQueueCells.size() > 0) {
Preconditions.checkState(mPendingCells.get(0).position >= mInQueueCells.get(mInQueueCells.size() - 1).position, "Items in pendingQueue must have large position than Items in queue");
}
}
}
Aggregations