@Test public void testAppendPrependRemoveReversed() { mProvider = new Provider(new int[]{80, 80, 30, 100, 40, 10}); mSingleRow = new SingleRow(); mSingleRow.setSpacing(20); mSingleRow.setProvider(mProvider); mSingleRow.setReversedFlow(true); mSingleRow.appendVisibleItems(-200); assertEquals(dump(mSingleRow) + " Should filled 2 items", 1, mSingleRow.mLastVisibleIndex); mSingleRow.appendVisibleItems(-201); assertEquals(dump(mSingleRow) + " Should filled 3 items", 2, mSingleRow.mLastVisibleIndex); mSingleRow.appendVisibleItems(-251); assertEquals(dump(mSingleRow) + " Should filled 4 items", 3, mSingleRow.mLastVisibleIndex); mSingleRow.appendVisibleItems(Integer.MIN_VALUE); assertEquals(dump(mSingleRow) + " Should filled 6 items", 5, mSingleRow.mLastVisibleIndex); assertEquals(mProvider.getEdge(0), 0); assertEquals(mProvider.getEdge(1), -100); assertEquals(mProvider.getEdge(2), -200); assertEquals(mProvider.getEdge(3), -250); assertEquals(mProvider.getEdge(4), -370); assertEquals(mProvider.getEdge(5), -430); mSingleRow.removeInvisibleItemsAtEnd(0, -200); assertEquals(dump(mSingleRow) + " Should filled 2 items", 1, mSingleRow.mLastVisibleIndex); mSingleRow.appendVisibleItems(Integer.MIN_VALUE); assertEquals(dump(mSingleRow) + " Should filled 6 items", 5, mSingleRow.mLastVisibleIndex); mSingleRow.removeInvisibleItemsAtFront(1000, -80); assertEquals(dump(mSingleRow) + " Should filled 6 items", 1, mSingleRow.mFirstVisibleIndex); }
@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);  }