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

Update BaseLayoutManager.java #264

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,10 @@ Lanes getLanes() {
}

void setItemEntryForPosition(int position, ItemEntry entry) {
if (mItemEntries != null) {
mItemEntries.putItemEntry(position, entry);
}
if(mItemEntries == null)
mItemEntries = new ItemEntries();
mItemEntries.putItemEntry(position, entry);

}

ItemEntry getItemEntryForPosition(int position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,19 @@ class ItemEntries {
private static final int MIN_SIZE = 10;

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

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

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

return len;
}

private void ensureSize(int position) {
if (mItemEntries == null) {
mItemEntries = new ItemEntry[Math.max(position, MIN_SIZE) + 1];
mItemEntries = new ItemEntry[Math.max(position, mAdapterSize) + 1];
Arrays.fill(mItemEntries, null);
} else if (position >= mItemEntries.length) {
ItemEntry[] oldItemEntries = mItemEntries;
mItemEntries = new ItemEntry[sizeForPosition(position)];
mItemEntries = new ItemEntry[position + 1];
System.arraycopy(oldItemEntries, 0, mItemEntries, 0, oldItemEntries.length);
Arrays.fill(mItemEntries, oldItemEntries.length, mItemEntries.length, null);
mAdapterSize = position;
}
}

Expand Down