use of com.tmall.wireless.tangram3.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.tangram3.structure.BaseCell in project Tangram-Android by alibaba.
the class PojoGroupBasicAdapter method insertComponents.
@Override
public void insertComponents(int pos, List<BaseCell> components) {
if (mData != null && mData.size() > 0 && components != null && !components.isEmpty() && pos >= 0) {
int newItemSize = components.size();
if (mCards != null) {
List<Pair<Range<Integer>, Card>> newCards = new ArrayList<>();
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 < pos) {
// do nothing
newCards.add(pair);
} else if (start <= pos && pos < end) {
Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start, end + newItemSize), pair.second);
newCards.add(newPair);
} else if (pos <= start) {
Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start + newItemSize, end + newItemSize), pair.second);
newCards.add(newPair);
}
}
mCards.clear();
mCards.addAll(newCards);
}
for (int i = 0, size = components.size(); i < size; i++) {
BaseCell cell = components.get(i);
if (cell != null) {
cell.added();
}
}
for (int i = 0; i < newItemSize; i++) {
if ((pos + i) < mData.size()) {
mData.add(pos + i, components.get(i));
} else {
mData.add(components.get(i));
}
}
notifyItemRangeInserted(pos, newItemSize);
}
}
use of com.tmall.wireless.tangram3.structure.BaseCell in project Tangram-Android by alibaba.
the class GridCard method addChildCard.
@Override
public void addChildCard(Card card) {
if (card == null) {
return;
}
List<BaseCell> subCells = card.getCells();
if (subCells != null && !subCells.isEmpty()) {
addCells(card.getCells());
int startOffset = mCells.indexOf(subCells.get(0));
int endOffset = mCells.indexOf(subCells.get(subCells.size() - 1));
Range range = Range.create(startOffset, endOffset);
mChildren.put(range, card);
}
}
use of com.tmall.wireless.tangram3.structure.BaseCell in project Tangram-Android by alibaba.
the class LinearScrollView method recycleView.
private void recycleView(@NonNull BaseCell cell) {
if (!mViewHolders.isEmpty()) {
RecyclerView.RecycledViewPool pool = cell.serviceManager.getService(RecyclerView.RecycledViewPool.class);
for (int i = 0, size = mViewHolders.size(); i < size; i++) {
BinderViewHolder viewHolder = mViewHolders.get(i);
viewHolder.unbind();
removeView(viewHolder.itemView);
pool.putRecycledView(viewHolder);
}
mViewHolders.clear();
}
}
use of com.tmall.wireless.tangram3.structure.BaseCell in project Tangram-Android by alibaba.
the class Card method addCellInternal.
public boolean addCellInternal(Card parent, int index, @Nullable BaseCell cell, boolean silent) {
if (cell != null) {
cell.parentId = parent.id;
cell.parent = parent;
cell.serviceManager = serviceManager;
MVHelper mvHelper = getMVHelper();
if (mvHelper != null) {
if (mvHelper.isValid(cell, serviceManager)) {
if (cell.position >= 0 && !TextUtils.isEmpty(load)) {
cell.pos = cell.position;
mPendingCells.add(cell);
return true;
} else {
// FixMe pos not correct when insert cell
cell.pos = mHeader != null ? this.mCells.size() + 1 : this.mCells.size();
}
if (!silent && mIsActivated) {
// do cell added
cell.added();
}
this.mCells.add(index, cell);
if (mFooter != null) {
mFooter.pos = cell.pos + 1;
}
if (mHeader != null) {
mHeader.pos = 0;
}
return true;
}
}
}
return false;
}
Aggregations