Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Dominiquini committed May 5, 2016
1 parent a06daef commit 99b0d0f
Showing 1 changed file with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.util.AttributeSet;
import android.view.View;

import com.tonicartos.superslim.GridSLM;
import com.tonicartos.superslim.LayoutManager;

import xyz.danoz.recyclerviewfastscroller.AbsRecyclerViewFastScroller;
Expand Down Expand Up @@ -71,26 +72,53 @@ public SLiMLayoutManagerScrollProgressCalculator(VerticalScrollBoundsProvider sc

@Override
public float calculateScrollProgress(RecyclerView recyclerView) {
LayoutManager layoutManager = (LayoutManager) recyclerView.getLayoutManager();
int lastFullyVisiblePosition = layoutManager.findLastCompletelyVisibleItemPosition();

View visibleChild = recyclerView.getChildAt(0);
if (visibleChild == null) {
return 0;
View visibleChild = getViewSample(recyclerView);

if (visibleChild != null) {
LayoutManager layoutManager = (LayoutManager) recyclerView.getLayoutManager();
int lastFullyVisiblePosition = layoutManager.findLastCompletelyVisibleItemPosition();

int spanCount = getSpanCount(recyclerView, visibleChild);

RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(visibleChild);

int itemHeight = holder.itemView.getHeight();
int recyclerHeight = recyclerView.getHeight();
int itemsInWindow = (recyclerHeight / itemHeight) * spanCount;

int numItemsInList = recyclerView.getAdapter().getItemCount();
int numScrollableSectionsInList = numItemsInList - itemsInWindow;
int indexOfLastFullyVisibleItemInFirstSection = numItemsInList - numScrollableSectionsInList - 1;

int currentSection = Math.max(0, lastFullyVisiblePosition - indexOfLastFullyVisibleItemInFirstSection);

float currentPosition = (float) currentSection / numScrollableSectionsInList;

return currentPosition;
}

RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(visibleChild);
int itemHeight = holder.itemView.getHeight();
int recyclerHeight = recyclerView.getHeight();
int itemsInWindow = recyclerHeight / itemHeight;
return 0f;
}

private View getViewSample(RecyclerView recyclerView) {

int numItemsInList = recyclerView.getAdapter().getItemCount();
int numScrollableSectionsInList = numItemsInList - itemsInWindow;
int indexOfLastFullyVisibleItemInFirstSection = numItemsInList - numScrollableSectionsInList - 1;
return recyclerView.getChildAt(0);
}

int currentSection = Math.max(0, lastFullyVisiblePosition - indexOfLastFullyVisibleItemInFirstSection);
private int getSpanCount(RecyclerView recyclerView, View viewSample) {

return (float) currentSection / numScrollableSectionsInList;
if (viewSample == null) {
viewSample = getViewSample(recyclerView);
}

GridSLM.LayoutParams layoutParams = GridSLM.LayoutParams.from(viewSample.getLayoutParams());

if (layoutParams.getNumColumns() != -1) {
return layoutParams.getNumColumns();
} else {
return layoutParams.getColumnWidth() == RecyclerView.LayoutParams.MATCH_PARENT ? 1 : recyclerView.getWidth() / layoutParams.getColumnWidth();
}
}
}
}

0 comments on commit 99b0d0f

Please sign in to comment.