@Test public void testPrefetchItems() { mProvider = new Provider(new int[]{80, 80, 30, 100, 40, 10}); mSingleRow = new SingleRow(); mSingleRow.setSpacing(20); mSingleRow.setProvider(mProvider); mSingleRow.appendVisibleItems(200); validatePrefetch(200, 10, new Integer[] {2, 0}); validatePrefetch(0, -10); mProvider.scroll(90); mSingleRow.removeInvisibleItemsAtFront(Integer.MAX_VALUE, 0); mSingleRow.appendVisibleItems(200); validatePrefetch(200, 10, new Integer[] {4, 80}); validatePrefetch(0, -10, new Integer[] {0, 10}); }
@Override protected final boolean appendVisibleItems(int toLimit, boolean oneColumnMode) { if (mProvider.getCount() == 0) { return false; } if (!oneColumnMode && checkAppendOverLimit(toLimit)) { return false; } boolean filledOne = false; for (int index = getStartIndexForAppend(); index < mProvider.getCount(); index++) { int size = mProvider.createItem(index, true, mTmpItem, false); int edge; if (mFirstVisibleIndex < 0 || mLastVisibleIndex< 0) { edge = mReversedFlow ? Integer.MAX_VALUE : Integer.MIN_VALUE; mLastVisibleIndex = mFirstVisibleIndex = index; } else { if (mReversedFlow) { edge = mProvider.getEdge(index - 1) - mProvider.getSize(index - 1) - mSpacing; } else { edge = mProvider.getEdge(index - 1) + mProvider.getSize(index - 1) + mSpacing; } mLastVisibleIndex = index; } mProvider.addItem(mTmpItem[0], index, size, 0, edge); filledOne = true; if (oneColumnMode || checkAppendOverLimit(toLimit)) { break; } } return filledOne; }
SingleRow extends Grid { @Override protected final boolean appendVisibleItems(int toLimit, boolean oneColumnMode) { if (mProvider.getCount() == 0) { return false; } if (!oneColumnMode && checkAppendOverLimit(toLimit)) { return false; } boolean filledOne = false; for (int index = getStartIndexForAppend(); index < mProvider.getCount(); index++) { int size = mProvider.createItem(index, true, mTmpItem, false); int edge; if (mFirstVisibleIndex < 0 || mLastVisibleIndex< 0) { edge = mReversedFlow ? Integer.MAX_VALUE : Integer.MIN_VALUE; mLastVisibleIndex = mFirstVisibleIndex = index; } else { if (mReversedFlow) { edge = mProvider.getEdge(index - 1) - mProvider.getSize(index - 1) - mSpacing; } else { edge = mProvider.getEdge(index - 1) + mProvider.getSize(index - 1) + mSpacing; } mLastVisibleIndex = index; } mProvider.addItem(mTmpItem[0], index, size, 0, edge); filledOne = true; if (oneColumnMode || checkAppendOverLimit(toLimit)) { break; } } return filledOne; } }
SingleRow extends Grid { @Override protected final boolean appendVisibleItems(int toLimit, boolean oneColumnMode) { if (mProvider.getCount() == 0) { return false; } if (!oneColumnMode && checkAppendOverLimit(toLimit)) { return false; } boolean filledOne = false; for (int index = getStartIndexForAppend(); index < mProvider.getCount(); index++) { int size = mProvider.createItem(index, true, mTmpItem, false); int edge; if (mFirstVisibleIndex < 0 || mLastVisibleIndex< 0) { edge = mReversedFlow ? Integer.MAX_VALUE : Integer.MIN_VALUE; mLastVisibleIndex = mFirstVisibleIndex = index; } else { if (mReversedFlow) { edge = mProvider.getEdge(index - 1) - mProvider.getSize(index - 1) - mSpacing; } else { edge = mProvider.getEdge(index - 1) + mProvider.getSize(index - 1) + mSpacing; } mLastVisibleIndex = index; } mProvider.addItem(mTmpItem[0], index, size, 0, edge); filledOne = true; if (oneColumnMode || checkAppendOverLimit(toLimit)) { break; } } return filledOne; } SingleRow(); }
SingleRow extends Grid { @Override protected final boolean appendVisibleItems(int toLimit, boolean oneColumnMode) { if (mProvider.getCount() == 0) { return false; } if (!oneColumnMode && checkAppendOverLimit(toLimit)) { return false; } boolean filledOne = false; for (int index = getStartIndexForAppend(); index < mProvider.getCount(); index++) { int size = mProvider.createItem(index, true, mTmpItem, false); int edge; if (mFirstVisibleIndex < 0 || mLastVisibleIndex< 0) { edge = mReversedFlow ? Integer.MAX_VALUE : Integer.MIN_VALUE; mLastVisibleIndex = mFirstVisibleIndex = index; } else { if (mReversedFlow) { edge = mProvider.getEdge(index - 1) - mProvider.getSize(index - 1) - mSpacing; } else { edge = mProvider.getEdge(index - 1) + mProvider.getSize(index - 1) + mSpacing; } mLastVisibleIndex = index; } mProvider.addItem(mTmpItem[0], index, size, 0, edge); filledOne = true; if (oneColumnMode || checkAppendOverLimit(toLimit)) { break; } } return filledOne; } SingleRow(); @Override final Location getLocation(int index); @Override final void debugPrint(PrintWriter pw); @Override void collectAdjacentPrefetchPositions(int fromLimit, int da,
        @NonNull RecyclerView.LayoutManager.LayoutPrefetchRegistry layoutPrefetchRegistry); @Override final CircularIntArray[] getItemPositionsInRows(int startPos, int endPos); }
SingleRow extends Grid { @Override protected final boolean appendVisibleItems(int toLimit, boolean oneColumnMode) { if (mProvider.getCount() == 0) { return false; } if (!oneColumnMode && checkAppendOverLimit(toLimit)) { return false; } boolean filledOne = false; for (int index = getStartIndexForAppend(); index < mProvider.getCount(); index++) { int size = mProvider.createItem(index, true, mTmpItem, false); int edge; if (mFirstVisibleIndex < 0 || mLastVisibleIndex< 0) { edge = mReversedFlow ? Integer.MAX_VALUE : Integer.MIN_VALUE; mLastVisibleIndex = mFirstVisibleIndex = index; } else { if (mReversedFlow) { edge = mProvider.getEdge(index - 1) - mProvider.getSize(index - 1) - mSpacing; } else { edge = mProvider.getEdge(index - 1) + mProvider.getSize(index - 1) + mSpacing; } mLastVisibleIndex = index; } mProvider.addItem(mTmpItem[0], index, size, 0, edge); filledOne = true; if (oneColumnMode || checkAppendOverLimit(toLimit)) { break; } } return filledOne; } SingleRow(); @Override final Location getLocation(int index); @Override final void debugPrint(PrintWriter pw); @Override void collectAdjacentPrefetchPositions(int fromLimit, int da,
        @NonNull RecyclerView.LayoutManager.LayoutPrefetchRegistry layoutPrefetchRegistry); @Override final CircularIntArray[] getItemPositionsInRows(int startPos, int endPos);  }