Skip to content

Commit

Permalink
Revert "Restore list animations on My I/O."
Browse files Browse the repository at this point in the history
This reverts commit d88e58c.

Change-Id: I1ad9243c37e658c7dfbf267019257b9acf6e1d44
  • Loading branch information
shailen committed May 15, 2017
1 parent 95a908e commit 41a39f5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ interface Callbacks extends SessionItemViewHolder.Callbacks {
mContext = context;
mCallbacks = callbacks;
stuckHeaderElevation = context.getResources().getDimension(R.dimen.card_elevation);
setHasStableIds(true);
setItems(null); // build the initial list of items
}

Expand Down Expand Up @@ -161,6 +160,9 @@ public void onClick(final View view) {
mItems.clear();
mItems.addAll(newData);
diff.dispatchUpdatesTo(this);
// we shouldn't need the following call, but without it the StickyHeader LayoutManger's
// bookkeeping gets messed up; this forces it to re-create it's internal state.
notifyDataSetChanged();
}

/**
Expand Down Expand Up @@ -439,7 +441,7 @@ private static class MyIoDiff extends DiffUtil.Callback {
private final List<Object> oldItems;
private final List<Object> newItems;

MyIoDiff(List<Object> oldItems, List<Object> newItems) {
public MyIoDiff(List<Object> oldItems, List<Object> newItems) {
this.oldItems = oldItems;
this.newItems = newItems;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,36 +595,112 @@ private void setPendingScroll(int position, int offset) {
private class HeaderPositionsAdapterDataObserver extends RecyclerView.AdapterDataObserver {
@Override
public void onChanged() {
reset();
// There's no hint at what changed, so go through the adapter.
mHeaderPositions.clear();
int itemCount = mAdapter.getItemCount();
for (int i = 0; i < itemCount; i++) {
if (mAdapter.isStickyHeader(i)) {
mHeaderPositions.add(i);
}
}

// Remove sticky header immediately if the entry it represents has been removed. A layout will follow.
if (mStickyHeader != null && !mHeaderPositions.contains(mStickyHeaderPosition)) {
scrapStickyHeader(null);
}
}

@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
reset();
// Shift headers below down.
int headerCount = mHeaderPositions.size();
if (headerCount > 0) {
for (int i = findHeaderIndexOrNext(positionStart); i != -1 && i < headerCount; i++) {
mHeaderPositions.set(i, mHeaderPositions.get(i) + itemCount);
}
}

// Add new headers.
for (int i = positionStart; i < positionStart + itemCount; i++) {
if (mAdapter.isStickyHeader(i)) {
int headerIndex = findHeaderIndexOrNext(i);
if (headerIndex != -1) {
mHeaderPositions.add(headerIndex, i);
} else {
mHeaderPositions.add(i);
}
}
}
}

@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
reset();
int headerCount = mHeaderPositions.size();
if (headerCount > 0) {
// Remove headers.
for (int i = positionStart + itemCount - 1; i >= positionStart; i--) {
int index = findHeaderIndex(i);
if (index != -1) {
mHeaderPositions.remove(index);
headerCount--;
}
}

// Remove sticky header immediately if the entry it represents has been removed. A layout will follow.
if (mStickyHeader != null && !mHeaderPositions.contains(mStickyHeaderPosition)) {
scrapStickyHeader(null);
}

// Shift headers below up.
for (int i = findHeaderIndexOrNext(positionStart + itemCount); i != -1 && i < headerCount; i++) {
mHeaderPositions.set(i, mHeaderPositions.get(i) - itemCount);
}
}
}

@Override
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
reset();
}

private void reset() {
mHeaderPositions.clear();
int itemCount = mAdapter.getItemCount();
for (int i = 0; i < itemCount; i++) {
if (mAdapter.isStickyHeader(i)) {
mHeaderPositions.add(i);
// Shift moved headers by toPosition - fromPosition.
// Shift headers in-between by -itemCount (reverse if upwards).
int headerCount = mHeaderPositions.size();
if (headerCount > 0) {
if (fromPosition < toPosition) {
for (int i = findHeaderIndexOrNext(fromPosition); i != -1 && i < headerCount; i++) {
int headerPos = mHeaderPositions.get(i);
if (headerPos >= fromPosition && headerPos < fromPosition + itemCount) {
mHeaderPositions.set(i, headerPos - (toPosition - fromPosition));
sortHeaderAtIndex(i);
} else if (headerPos >= fromPosition + itemCount && headerPos <= toPosition) {
mHeaderPositions.set(i, headerPos - itemCount);
sortHeaderAtIndex(i);
} else {
break;
}
}
} else {
for (int i = findHeaderIndexOrNext(toPosition); i != -1 && i < headerCount; i++) {
int headerPos = mHeaderPositions.get(i);
if (headerPos >= fromPosition && headerPos < fromPosition + itemCount) {
mHeaderPositions.set(i, headerPos + (toPosition - fromPosition));
sortHeaderAtIndex(i);
} else if (headerPos >= toPosition && headerPos <= fromPosition) {
mHeaderPositions.set(i, headerPos + itemCount);
sortHeaderAtIndex(i);
} else {
break;
}
}
}
}
}

// Remove sticky header immediately if the entry it represents has been removed. A layout will follow.
if (mStickyHeader != null && !mHeaderPositions.contains(mStickyHeaderPosition)) {
scrapStickyHeader(null);
private void sortHeaderAtIndex(int index) {
int headerPos = mHeaderPositions.remove(index);
int headerIndex = findHeaderIndexOrNext(headerPos);
if (headerIndex != -1) {
mHeaderPositions.add(headerIndex, headerPos);
} else {
mHeaderPositions.add(headerPos);
}
}
}
Expand Down
Binary file modified third_party/sticky-headers/libs/StickyHeaders-release.aar
Binary file not shown.

0 comments on commit 41a39f5

Please sign in to comment.