Skip to content

Commit

Permalink
Fixed an error where calculateAdapterHeight() was called from a non…
Browse files Browse the repository at this point in the history
…-MeasurableAdapter.

This probably needs some attention to prevent this from occurring in the future..
  • Loading branch information
timusus committed Nov 11, 2018
1 parent c26edb1 commit 835fff5
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public String scrollToPositionAtProgress(float touchFraction) {
scrollOffset = calculateScrollDistanceToPosition(scrollPosition) - passedHeight;
} else {
itemPos = findItemPosition(touchFraction);
availableScrollHeight = getAvailableScrollHeight(calculateAdapterHeight(), 0);
availableScrollHeight = getAvailableScrollHeight(rowCount * mScrollPosState.rowHeight, 0);

//The exact position of our desired item
int exactItemPos = (int) (availableScrollHeight * touchFraction);
Expand Down Expand Up @@ -305,10 +305,10 @@ public String scrollToPositionAtProgress(float touchFraction) {
@SuppressWarnings("unchecked")
private int findMeasureAdapterFirstVisiblePosition(int passedHeight) {
if (getAdapter() instanceof MeasurableAdapter) {
MeasurableAdapter measurmeasurableAdapterr = (MeasurableAdapter) getAdapter();
MeasurableAdapter measurableAdapter = (MeasurableAdapter) getAdapter();
for (int i = 0; i < getAdapter().getItemCount(); i++) {
int top = calculateScrollDistanceToPosition(i);
int bottom = top + measurmeasurableAdapterr.getViewTypeHeight(this, findViewHolderForAdapterPosition(i), getAdapter().getItemViewType(i));
int bottom = top + measurableAdapter.getViewTypeHeight(this, findViewHolderForAdapterPosition(i), getAdapter().getItemViewType(i));
if (i == getAdapter().getItemCount() - 1) {
if (passedHeight >= top && passedHeight <= bottom) {
return i;
Expand All @@ -321,7 +321,7 @@ private int findMeasureAdapterFirstVisiblePosition(int passedHeight) {
}
int low = calculateScrollDistanceToPosition(0);
int height = calculateScrollDistanceToPosition(getAdapter().getItemCount() - 1)
+ measurmeasurableAdapterr.getViewTypeHeight(this, findViewHolderForAdapterPosition(getAdapter().getItemCount() - 1), getAdapter().getItemViewType(getAdapter().getItemCount() - 1));
+ measurableAdapter.getViewTypeHeight(this, findViewHolderForAdapterPosition(getAdapter().getItemCount() - 1), getAdapter().getItemViewType(getAdapter().getItemCount() - 1));
throw new IllegalStateException(String.format("Invalid passed height: %d, [low: %d, height: %d]", passedHeight, low, height));
} else {
throw new IllegalStateException("findMeasureAdapterFirstVisiblePosition() should only be called where the RecyclerView.Adapter is an instance of MeasurableAdapter");
Expand Down

0 comments on commit 835fff5

Please sign in to comment.