Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
longerian committed Jan 10, 2018
2 parents 6c505ca + ce59222 commit 5c9a304
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,19 @@ protected LayoutParams generateLayoutParams(LayoutParams p) {
public boolean isRecyclable(int childPos, int startIndex, int endIndex, LayoutManagerHelper helper, boolean fromStart) {
Range<Integer> range = getRange();
if (range.contains(childPos)) {
return Range.create(startIndex, endIndex).contains(range);
if (hasHeader && childPos == getRange().getLower()) {
return true;
}
if (hasFooter && childPos == getRange().getUpper()) {
return true;
}
Range<Integer> childRange = Range.create(range.getLower() + (hasHeader ? 1 : 0),
range.getUpper() - (hasFooter ? 1 : 0));
return Range.create(startIndex, endIndex).contains(childRange);
} else {
Log.w(TAG, "Child item not match");
return true;
}
//NOTE may opt to recycle header or footer separately
}

public void setHasHeader(boolean hasHeader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,58 +184,62 @@ public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state
View header = nextView(recycler, layoutState, helper, result);
int headerConsumed = handleHeader(header, layoutState, result, helper, layoutInVertical, parentWidth, parentHeight,
parentHPadding, parentVPadding);
int left = 0, right = 0, top = 0, bottom = 0;
if (layoutInVertical) {
if (layoutStart) {
bottom = layoutState.getOffset();
top = bottom - headerConsumed;
} else {
top = layoutState.getOffset() + (mLayoutWithAnchor ? 0 : mMarginTop + mPaddingTop);
bottom = top + headerConsumed;
}
left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft;
right = left + orientationHelper.getDecoratedMeasurementInOther(header);
} else {
if (layoutStart) {
right = layoutState.getOffset();
left = right - headerConsumed;
if (header != null) {
int left = 0, right = 0, top = 0, bottom = 0;
if (layoutInVertical) {
if (layoutStart) {
bottom = layoutState.getOffset();
top = bottom - headerConsumed;
} else {
top = layoutState.getOffset() + (mLayoutWithAnchor ? 0 : mMarginTop + mPaddingTop);
bottom = top + headerConsumed;
}
left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft;
right = left + orientationHelper.getDecoratedMeasurementInOther(header);
} else {
left = layoutState.getOffset() + (mLayoutWithAnchor ? 0 : mMarginLeft + mPaddingLeft);
right = left + headerConsumed;
if (layoutStart) {
right = layoutState.getOffset();
left = right - headerConsumed;
} else {
left = layoutState.getOffset() + (mLayoutWithAnchor ? 0 : mMarginLeft + mPaddingLeft);
right = left + headerConsumed;
}
top = helper.getPaddingTop() + mMarginTop + mPaddingTop;
bottom = top + orientationHelper.getDecoratedMeasurementInOther(header);
}
top = helper.getPaddingTop() + mMarginTop + mPaddingTop;
bottom = top + orientationHelper.getDecoratedMeasurementInOther(header);
layoutChildWithMargin(header, left, top, right, bottom, helper);
}
layoutChildWithMargin(header, left, top, right, bottom, helper);
result.mConsumed = headerConsumed;
handleStateOnResult(result, header);
} else if (hasFooter && currentPosition == getRange().getUpper()) {
View footer = nextView(recycler, layoutState, helper, result);
int footerConsumed = handleFooter(footer, layoutState, result, helper, layoutInVertical, parentWidth, parentHeight,
parentHPadding, parentVPadding);
int left = 0, right = 0, top = 0, bottom = 0;
if (layoutInVertical) {
if (layoutStart) {
bottom = layoutState.getOffset() - (mLayoutWithAnchor ? 0 : mMarginBottom + mPaddingBottom);
top = bottom - footerConsumed;
} else {
top = layoutState.getOffset();
bottom = top + footerConsumed;
}
left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft;
right = left + orientationHelper.getDecoratedMeasurementInOther(footer);
} else {
if (layoutStart) {
right = layoutState.getOffset() - (mLayoutWithAnchor ? 0 : mMarginRight + mPaddingRight);
left = right - footerConsumed;
if (footer != null) {
int left = 0, right = 0, top = 0, bottom = 0;
if (layoutInVertical) {
if (layoutStart) {
bottom = layoutState.getOffset() - (mLayoutWithAnchor ? 0 : mMarginBottom + mPaddingBottom); //TODO margin overlap
top = bottom - footerConsumed;
} else {
top = layoutState.getOffset();
bottom = top + footerConsumed;
}
left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft;
right = left + orientationHelper.getDecoratedMeasurementInOther(footer);
} else {
left = layoutState.getOffset();
right = left + footerConsumed;
if (layoutStart) {
right = layoutState.getOffset() - (mLayoutWithAnchor ? 0 : mMarginRight + mPaddingRight); //TODO margin overlap
left = right - footerConsumed;
} else {
left = layoutState.getOffset();
right = left + footerConsumed;
}
top = helper.getPaddingTop() + mMarginTop + mPaddingTop;
bottom = top + orientationHelper.getDecoratedMeasurementInOther(footer);
}
top = helper.getPaddingTop() + mMarginTop + mPaddingTop;
bottom = top + orientationHelper.getDecoratedMeasurementInOther(footer);
layoutChildWithMargin(footer, left, top, right, bottom, helper);
}
layoutChildWithMargin(footer, left, top, right, bottom, helper);
result.mConsumed = footerConsumed;
handleStateOnResult(result, footer);
} else {
Expand All @@ -244,7 +248,7 @@ public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state
mChildrenViews = new View[contentCount];
}
int count = getAllChildren(mChildrenViews, recycler, layoutState, result, helper);
if (count == 0) {
if (count == 0 || count < contentCount) {
return;
}
int mainConsumed = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public class StaggeredGridLayoutHelper extends BaseLayoutHelper {

private List<View> prelayoutViewList = new ArrayList<>();

private boolean mLayoutWithAnchor;

private int anchorPosition;

private WeakReference<VirtualLayoutManager> mLayoutManager = null;

private final Runnable checkForGapsRunnable = new Runnable() {
Expand Down Expand Up @@ -190,6 +194,7 @@ public void beforeLayout(RecyclerView.Recycler recycler, RecyclerView.State stat
@Override
public void afterLayout(RecyclerView.Recycler recycler, RecyclerView.State state, int startPosition, int endPosition, int scrolled, LayoutManagerHelper helper) {
super.afterLayout(recycler, state, startPosition, endPosition, scrolled, helper);
mLayoutWithAnchor = false;
if (startPosition > getRange().getUpper() || endPosition < getRange().getLower()) {
//do not in visible screen, skip
return;
Expand Down Expand Up @@ -239,6 +244,7 @@ public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state
prelayoutViewList.clear();
while (layoutState.hasMore(state) && !mRemainingSpans.isEmpty() && !isOutOfRange(layoutState.getCurrentPosition())) {
boolean isStartLine = false, isEndLine = false;
int currentPosition = layoutState.getCurrentPosition();
View view = layoutState.next(recycler);

if (view == null) {
Expand All @@ -260,7 +266,7 @@ public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state
}
// handle margin for start/end line
isStartLine = position - getRange().getLower() < mNumLanes;
isEndLine = getRange().getUpper() - position < mNumLanes; //fix the end line condiition
isEndLine = getRange().getUpper() - position < mNumLanes; //fix the end line condition, edit by longerian

if (layoutState.isPreLayout()) {
prelayoutViewList.add(view);
Expand Down Expand Up @@ -291,15 +297,22 @@ public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state

if (isStartLine) {
start += computeStartSpace(helper, layoutInVertical, true, isOverLapMargin);
//Log.d(TAG", "startLine " + position + " " + start);
} else {
start += (layoutInVertical ? mVGap : mHGap);
//Log.d(TAG", "normalStartLine " + position + " " + start);
if (mLayoutWithAnchor) {
if (Math.abs(currentPosition - anchorPosition) < mNumLanes) {
//do not add extra gaps here
} else {
start += (layoutInVertical ? mVGap : mHGap);
}
} else {
start += (layoutInVertical ? mVGap : mHGap);
}
}
end = start + orientationHelper.getDecoratedMeasurement(view);
} else {
if (isEndLine) {
end = currentSpan.getStartLine(defaultNewViewLine, orientationHelper) - (layoutInVertical ? mMarginBottom + mPaddingRight : mMarginRight + mPaddingRight);
end = currentSpan.getStartLine(defaultNewViewLine, orientationHelper) - (layoutInVertical ?
mMarginBottom + mPaddingRight : mMarginRight + mPaddingRight);
//Log.d(TAG, "endLine " + position + " " + end);
} else {
end = currentSpan.getStartLine(defaultNewViewLine, orientationHelper) - (layoutInVertical ? mVGap : mHGap);
Expand Down Expand Up @@ -997,6 +1010,9 @@ public void checkAnchorInfo(RecyclerView.State state, VirtualLayoutManager.Ancho
}
}
}
} else {
anchorPosition = anchorInfo.position;
mLayoutWithAnchor = true;
}

if (BuildConfig.DEBUG) {
Expand Down Expand Up @@ -1173,6 +1189,7 @@ void cacheReferenceLineAndClear(boolean reverseLayout, int offset, OrientationHe
}

void clear() {
Log.d("Longer", "clear span");
mViews.clear();
invalidateCache();
mDeletedSize = 0;
Expand Down

0 comments on commit 5c9a304

Please sign in to comment.