use of android.support.v7.widget.RecyclerView in project epoxy by airbnb.
the class VerticalGridCardSpacingDecoration method getItemOffsets.
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {
if (outerPadding == -1 || innerPadding == -1) {
DisplayMetrics m = view.getResources().getDisplayMetrics();
outerPadding = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, OUTER_PADDING_DP, m);
innerPadding = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, INNER_PADDING_DP, m);
}
int position = parent.getChildAdapterPosition(view);
final GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
final SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup();
// Zero everything out for the common case
outRect.setEmpty();
int spanSize = spanSizeLookup.getSpanSize(position);
int spanCount = layoutManager.getSpanCount();
int spanIndex = spanSizeLookup.getSpanIndex(position, spanCount);
if (spanSize == spanCount) {
// Only item in row
outRect.left = outerPadding;
outRect.right = outerPadding;
} else if (spanIndex == 0) {
// First item in row
outRect.left = outerPadding;
outRect.right = innerPadding;
} else if (spanIndex == spanCount - 1) {
// Last item in row
outRect.left = innerPadding;
outRect.right = outerPadding;
} else {
// Inner item (not relevant for less than three columns)
outRect.left = innerPadding;
outRect.right = innerPadding;
}
}
use of android.support.v7.widget.RecyclerView in project GestureViews by alexvasilkov.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = Views.find(this, R.id.main_list);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new SampleAdapter(this, getActivitiesList()));
}
use of android.support.v7.widget.RecyclerView in project GestureViews by alexvasilkov.
the class DefaultEndlessRecyclerAdapter method onAttachedToRecyclerView.
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
GridLayoutManager gridManager = (GridLayoutManager) recyclerView.getLayoutManager();
spanCount = gridManager.getSpanCount();
originalSpanLookup = gridManager.getSpanSizeLookup();
gridManager.setSpanSizeLookup(spanSizes);
}
}
use of android.support.v7.widget.RecyclerView in project GestureViews by alexvasilkov.
the class DefaultEndlessRecyclerAdapter method onDetachedFromRecyclerView.
@Override
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
super.onDetachedFromRecyclerView(recyclerView);
if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
GridLayoutManager gridManager = (GridLayoutManager) recyclerView.getLayoutManager();
gridManager.setSpanSizeLookup(originalSpanLookup);
originalSpanLookup = null;
spanCount = 1;
}
}
use of android.support.v7.widget.RecyclerView in project GestureViews by alexvasilkov.
the class EndlessRecyclerAdapter method loadNextItemsIfNeeded.
private void loadNextItemsIfNeeded(RecyclerView recyclerView) {
if (!isLoading && !isError) {
View lastVisibleChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
int lastVisiblePos = recyclerView.getChildAdapterPosition(lastVisibleChild);
int total = getItemCount();
if (lastVisiblePos >= total - loadingOffset) {
// We need to use runnable, since recycler view does not like when we are notifying
// about changes during scroll callback.
recyclerView.post(new Runnable() {
@Override
public void run() {
loadNextItems();
}
});
}
}
}
Aggregations