Skip to content

Commit fd0e28d

Browse files
author
Rafael Dominiquini
committed
Bug fix
1 parent 5e70725 commit fd0e28d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/calculation/progress/GridLayoutManagerScrollProgressCalculator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package xyz.danoz.recyclerviewfastscroller.calculation.progress;
22

3-
import xyz.danoz.recyclerviewfastscroller.calculation.VerticalScrollBoundsProvider;
4-
53
import android.support.v7.widget.GridLayoutManager;
64
import android.support.v7.widget.LinearLayoutManager;
75
import android.support.v7.widget.RecyclerView;
@@ -11,6 +9,8 @@
119

1210
import java.util.Arrays;
1311

12+
import xyz.danoz.recyclerviewfastscroller.calculation.VerticalScrollBoundsProvider;
13+
1414
/**
1515
* Calculates scroll progress for a {@link RecyclerView} with a {@link LinearLayoutManager}
1616
*/
@@ -45,6 +45,7 @@ public float calculateScrollProgress(RecyclerView recyclerView) {
4545
if (visibleChild == null) {
4646
return 0;
4747
}
48+
4849
ViewHolder holder = recyclerView.getChildViewHolder(visibleChild);
4950
int itemHeight = holder.itemView.getHeight();
5051
int recyclerHeight = recyclerView.getHeight();
@@ -54,7 +55,7 @@ public float calculateScrollProgress(RecyclerView recyclerView) {
5455
int numScrollableSectionsInList = numItemsInList - itemsInWindow;
5556
int indexOfLastFullyVisibleItemInFirstSection = numItemsInList - numScrollableSectionsInList - 1;
5657

57-
int currentSection = lastFullyVisiblePosition - indexOfLastFullyVisibleItemInFirstSection;
58+
int currentSection = Math.max(0, lastFullyVisiblePosition - indexOfLastFullyVisibleItemInFirstSection);
5859

5960
return (float) currentSection / numScrollableSectionsInList;
6061
}

recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/calculation/progress/VerticalLinearLayoutManagerScrollProgressCalculator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package xyz.danoz.recyclerviewfastscroller.calculation.progress;
22

3-
import xyz.danoz.recyclerviewfastscroller.calculation.VerticalScrollBoundsProvider;
4-
53
import android.support.v7.widget.LinearLayoutManager;
64
import android.support.v7.widget.RecyclerView;
75
import android.support.v7.widget.RecyclerView.ViewHolder;
86
import android.view.View;
97

8+
import xyz.danoz.recyclerviewfastscroller.calculation.VerticalScrollBoundsProvider;
9+
1010
/**
1111
* Calculates scroll progress for a {@link RecyclerView} with a {@link LinearLayoutManager}
1212
*/
@@ -27,8 +27,9 @@ public float calculateScrollProgress(RecyclerView recyclerView) {
2727

2828
View visibleChild = recyclerView.getChildAt(0);
2929
if (visibleChild == null) {
30-
return 0;
30+
return 0f;
3131
}
32+
3233
ViewHolder holder = recyclerView.getChildViewHolder(visibleChild);
3334
int itemHeight = holder.itemView.getHeight();
3435
int recyclerHeight = recyclerView.getHeight();
@@ -38,7 +39,7 @@ public float calculateScrollProgress(RecyclerView recyclerView) {
3839
int numScrollableSectionsInList = numItemsInList - itemsInWindow;
3940
int indexOfLastFullyVisibleItemInFirstSection = numItemsInList - numScrollableSectionsInList - 1;
4041

41-
int currentSection = lastFullyVisiblePosition - indexOfLastFullyVisibleItemInFirstSection;
42+
int currentSection = Math.max(0, lastFullyVisiblePosition - indexOfLastFullyVisibleItemInFirstSection);
4243

4344
return (float) currentSection / numScrollableSectionsInList;
4445
}

0 commit comments

Comments
 (0)