File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed
recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/calculation/progress Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change 11package xyz .danoz .recyclerviewfastscroller .calculation .progress ;
22
3- import xyz .danoz .recyclerviewfastscroller .calculation .VerticalScrollBoundsProvider ;
4-
53import android .support .v7 .widget .GridLayoutManager ;
64import android .support .v7 .widget .LinearLayoutManager ;
75import android .support .v7 .widget .RecyclerView ;
119
1210import 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 }
Original file line number Diff line number Diff line change 11package xyz .danoz .recyclerviewfastscroller .calculation .progress ;
22
3- import xyz .danoz .recyclerviewfastscroller .calculation .VerticalScrollBoundsProvider ;
4-
53import android .support .v7 .widget .LinearLayoutManager ;
64import android .support .v7 .widget .RecyclerView ;
75import android .support .v7 .widget .RecyclerView .ViewHolder ;
86import 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 }
You can’t perform that action at this time.
0 commit comments