Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
[layouts] Don't apply adapter constraints when restoring items
Browse files Browse the repository at this point in the history
Fixes #146
  • Loading branch information
lucasr committed Oct 29, 2014
1 parent c1488bc commit 6030143
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ private LanedSavedState(Parcel in) {
itemEntries = new ItemEntries();
for (int i = 0; i < itemEntriesCount; i++) {
final ItemEntry entry = in.readParcelable(getClass().getClassLoader());
itemEntries.putItemEntry(i, entry);
itemEntries.restoreItemEntry(i, entry);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ class ItemEntries {

private ItemEntry[] mItemEntries;
private int mAdapterSize;
private boolean mRestoringItem;

private int sizeForPosition(int position) {
int len = mItemEntries.length;
while (len <= position) {
len *= 2;
}

if (len > mAdapterSize) {
// We don't apply any constraints while restoring
// item entries.
if (!mRestoringItem && len > mAdapterSize) {
len = mAdapterSize;
}

Expand Down Expand Up @@ -71,6 +74,12 @@ public void putItemEntry(int position, ItemEntry entry) {
mItemEntries[position] = entry;
}

public void restoreItemEntry(int position, ItemEntry entry) {
mRestoringItem = true;
putItemEntry(position, entry);
mRestoringItem = false;
}

public int size() {
return (mItemEntries != null ? mItemEntries.length : 0);
}
Expand Down

0 comments on commit 6030143

Please sign in to comment.