use of com.alibaba.android.vlayout.LayoutHelper in project vlayout by alibaba.
the class BaseLayoutHelper method computeStartSpace.
protected int computeStartSpace(LayoutManagerHelper helper, boolean layoutInVertical, boolean isLayoutEnd, boolean isOverLapMargin) {
int startSpace = 0;
LayoutHelper lastLayoutHelper = null;
if (helper instanceof VirtualLayoutManager) {
lastLayoutHelper = ((VirtualLayoutManager) helper).findNeighbourNonfixLayoutHelper(this, isLayoutEnd);
}
MarginLayoutHelper lastMarginLayoutHelper = null;
if (lastLayoutHelper != null && lastLayoutHelper instanceof MarginLayoutHelper) {
lastMarginLayoutHelper = (MarginLayoutHelper) lastLayoutHelper;
}
if (lastLayoutHelper == this)
return 0;
if (!isOverLapMargin) {
startSpace = layoutInVertical ? mMarginTop + mPaddingTop : mMarginLeft + mPaddingLeft;
} else {
int offset = 0;
if (lastMarginLayoutHelper == null) {
offset = layoutInVertical ? mMarginTop + mPaddingTop : mMarginLeft + mPaddingLeft;
} else {
offset = layoutInVertical ? (isLayoutEnd ? calGap(lastMarginLayoutHelper.mMarginBottom, mMarginTop) : calGap(lastMarginLayoutHelper.mMarginTop, mMarginBottom)) : (isLayoutEnd ? calGap(lastMarginLayoutHelper.mMarginRight, mMarginLeft) : calGap(lastMarginLayoutHelper.mMarginLeft, mMarginRight));
}
// Log.e("huang", "computeStartSpace offset: " + offset + ", isLayoutEnd: " + isLayoutEnd + ", " + this);
startSpace += layoutInVertical ? (isLayoutEnd ? mPaddingTop : mPaddingBottom) : (isLayoutEnd ? mPaddingLeft : mPaddingRight);
startSpace += offset;
}
return startSpace;
}
use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.
the class TangramEngine method removeBy.
/**
* Remove target cell. TODO handle nested card, cell in staggered, cell in onePlusN
* @param data
* @since 2.1.0
*/
protected void removeBy(BaseCell data) {
VirtualLayoutManager layoutManager = getLayoutManager();
if (data != null && mGroupBasicAdapter != null && layoutManager != null) {
int removePosition = mGroupBasicAdapter.getPositionByItem(data);
if (removePosition >= 0) {
int cardIdx = mGroupBasicAdapter.findCardIdxFor(removePosition);
Card card = mGroupBasicAdapter.getCardRange(cardIdx).second;
card.removeCellSilently(data);
List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
LayoutHelper emptyLayoutHelper = null;
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 < removePosition) {
// do nothing
} else if (start <= removePosition && removePosition <= end) {
int itemCount = layoutHelper.getItemCount() - 1;
if (itemCount > 0) {
layoutHelper.setItemCount(itemCount);
layoutHelper.setRange(start, end - 1);
} else {
emptyLayoutHelper = layoutHelper;
}
} else if (removePosition < start) {
layoutHelper.setRange(start - 1, end - 1);
}
}
if (emptyLayoutHelper != null) {
final List<LayoutHelper> newLayoutHelpers = new LinkedList<>(layoutHelpers);
newLayoutHelpers.remove(emptyLayoutHelper);
layoutManager.setLayoutHelpers(newLayoutHelpers);
}
mGroupBasicAdapter.removeComponent(data);
}
}
}
}
use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.
the class TangramEngine method removeBatchBy.
/**
* Remove all cells in a card.
* @param group
* @since 2.1.0
*/
protected void removeBatchBy(Card group) {
VirtualLayoutManager layoutManager = getLayoutManager();
if (group != null && mGroupBasicAdapter != null && layoutManager != null) {
int cardIdx = mGroupBasicAdapter.findCardIdxForCard(group);
List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
LayoutHelper emptyLayoutHelper = null;
int removeItemCount = 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) {
removeItemCount = layoutHelper.getItemCount();
emptyLayoutHelper = layoutHelper;
} else {
layoutHelper.setRange(start - removeItemCount, end - removeItemCount);
}
}
if (emptyLayoutHelper != null) {
final List<LayoutHelper> newLayoutHelpers = new LinkedList<>(layoutHelpers);
newLayoutHelpers.remove(emptyLayoutHelper);
layoutManager.setLayoutHelpers(newLayoutHelpers);
}
mGroupBasicAdapter.removeComponents(group);
}
}
}
use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.
the class TangramEngine method replace.
/**
* Replace card one by one. New one's children size should be equal with old one's children size.
* @param oldOne
* @param newOne
* @since 2.1.0
*/
public void replace(Card oldOne, Card newOne) {
VirtualLayoutManager layoutManager = getLayoutManager();
if (oldOne != null && newOne != null && mGroupBasicAdapter != null && layoutManager != null) {
List<LayoutHelper> layoutHelpers = layoutManager.getLayoutHelpers();
int cardIdx = mGroupBasicAdapter.findCardIdxForCard(oldOne);
if (layoutHelpers != null && cardIdx >= 0 && cardIdx < layoutHelpers.size()) {
final List<LayoutHelper> newLayoutHelpers = new LinkedList<>();
for (int i = 0, size = layoutHelpers.size(); i < size; i++) {
LayoutHelper layoutHelper = layoutHelpers.get(i);
if (i == cardIdx) {
layoutHelper = newOne.getLayoutHelper();
}
newLayoutHelpers.add(layoutHelper);
}
layoutManager.setLayoutHelpers(newLayoutHelpers);
mGroupBasicAdapter.replaceComponent(oldOne, newOne);
}
}
}
use of com.alibaba.android.vlayout.LayoutHelper in project Tangram-Android by alibaba.
the class GroupBasicAdapter method transformCards.
/**
* Transform cards to layoutHelpers with correct range and add cells in cards into data
*
* @param cards cards will be transformed
* @param data list of items that items will be added to
* @return helpers transformed from cards
*/
@NonNull
protected List<LayoutHelper> transformCards(@Nullable List<L> cards, @NonNull final List<C> data, @NonNull List<Pair<Range<Integer>, L>> rangeCards) {
if (cards == null || cards.size() == 0) {
return new LinkedList<>();
}
int lastPos = data.size();
List<LayoutHelper> helpers = new ArrayList<>(cards.size());
for (int i = 0, size = cards.size(); i < size; i++) {
L card = cards.get(i);
if (card == null)
continue;
final String ctype = getCardStringType(card);
List<C> items = getItems(card);
if (items == null) {
// skip card null
continue;
}
data.addAll(items);
// calculate offset to set ranges
int offset = lastPos;
lastPos += items.size();
// include [x, x) for empty range, upper are not included in range
rangeCards.add(Pair.create(Range.create(offset, lastPos), card));
// get layoutHelper for this card
LayoutBinder<L> binder = mCardBinderResolver.create(ctype);
LayoutHelper helper = binder.getHelper(ctype, card);
if (helper != null) {
helper.setItemCount(items.size());
helpers.add(helper);
}
}
return helpers;
}
Aggregations